Skip to content

Instantly share code, notes, and snippets.

@zainthemaynnn
Created March 9, 2023 21:47
Show Gist options
  • Save zainthemaynnn/9f157d29386d72f4a256fba9f12d0e89 to your computer and use it in GitHub Desktop.
Save zainthemaynnn/9f157d29386d72f4a256fba9f12d0e89 to your computer and use it in GitHub Desktop.
package frc.robot.commands;
import java.util.Set;
import com.revrobotics.CANSparkMax.IdleMode;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.Subsystem;
import frc.robot.subsystems.Drive;
public class Balance implements Command {
private static final double POW_STATIC = .0;
private static final double POW_SIN_SCALE = .50;
private static final double NAT_DEG = -1.4; // natural pitch angle of the gyro (the bottom of the robot isn't level)
private static final double A_THRESH = 1.0;
private Drive drive;
public Balance(Drive drive) {
this.drive = drive;
}
@Override
public void initialize() {
drive.setIdleMode(IdleMode.kBrake);
}
@Override
public void execute() {
double a = drive.pitch() - NAT_DEG;
drive.arcadeDrive(
Math.abs(a) > A_THRESH ? POW_STATIC + POW_SIN_SCALE * Math.sin(a) : 0.,
0.
);
}
@Override
public Set<Subsystem> getRequirements() {
return Set.of(drive);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment