import edu.wpi.first.math.MathUtil;
import edu.wpi.first.math.geometry.Translation2d;
+import edu.wpi.first.math.kinematics.ChassisSpeeds;
import edu.wpi.first.math.util.Units;
import edu.wpi.first.wpilibj.DriverStation.Alliance;
import edu.wpi.first.wpilibj2.command.Command;
private Drivetrain drivetrain;
private TurretVision turretVision;
+ public boolean SOTM;
+
double fieldAngleRad;
double turretSetpoint;
double adjustedSetpoint;
private boolean turretVisionEnabled = false;
- public TurretAutoShoot(Turret turret, Drivetrain drivetrain, TurretVision turretVision){
+ public TurretAutoShoot(Turret turret, Drivetrain drivetrain, TurretVision turretVision, boolean SOTM){
this.turret = turret;
this.drivetrain = drivetrain;
this.turretVision = turretVision;
+
+ this.SOTM = SOTM;
addRequirements(turret);
}
- public TurretAutoShoot(Turret turret, Drivetrain drivetrain){
+ public TurretAutoShoot(Turret turret, Drivetrain drivetrain, boolean SOTM){
this(turret, drivetrain, null);
+ this.SOTM = SOTM;
}
public void updateTurretSetpoint() {
Translation2d drivepose = drivetrain.getPose().getTranslation();
Translation2d target = FieldConstants.getHubTranslation().toTranslation2d();
- double D_y = target.getY() - drivepose.getY();
- double D_x = target.getX() - drivepose.getX();
+ double D_y;
+ double D_x;
+ if (SOTM) {
+ ChassisSpeeds chassisSpeed = drivetrain.getChassisSpeeds();
+ double xVel = chassisSpeed.vxMetersPerSecond;
+ double yVel = chassisSpeed.vyMetersPerSecond;
+
+ D_y = target.getY() - drivepose.getY() + (Units.secondsToMilliseconds(yVel) * 20); // every periodic predict where the robot will be in one periodic into the future
+ D_x = target.getX() - drivepose.getX() + (Units.secondsToMilliseconds(xVel) * 20);
+ } else {
+ D_y = target.getY() - drivepose.getY();
+ D_x = target.getX() - drivepose.getX();
+ }
fieldAngleRad = Math.atan2(D_y, D_x);
double robotHeading = MathUtil.angleModulus((drivetrain.getYaw().getRadians() + Math.PI)); // Add 180 because drivetrain is backwards
turretSetpoint = MathUtil.inputModulus(Units.radiansToDegrees(fieldAngleRad - robotHeading), -180.0,180.0);
private Command turretAutoShoot;
private TurretJoyStickAim turretJoyStickAim;
+ private boolean SOTM;
+
public PS5ControllerDriverConfig(Drivetrain drive, Shooter shooter, Turret turret) {
super(drive);
this.shooter = shooter;
this.turret = turret;
+ SOTM = false;
}
public void configureControls() {
new Rotation2d(Robot.getAlliance() == Alliance.Blue ? 0 : Math.PI)
)));
+ driver.get(PS5Button.MUTE).onTrue(new InstantCommand(() -> toggleSOTM()));
+
// Cancel commands
driver.get(PS5Button.RIGHT_TRIGGER).onTrue(new InstantCommand(()->{
getDrivetrain().setIsAlign(false);
if (turretAutoShoot != null && turretAutoShoot.isScheduled()){
turretAutoShoot.cancel();
} else{
- turretAutoShoot = new TurretAutoShoot(turret, getDrivetrain());
+ turretAutoShoot = new TurretAutoShoot(turret, getDrivetrain(), SOTM);
CommandScheduler.getInstance().schedule(turretAutoShoot);
}
})
public void endRumble(){
driver.rumbleOff();
}
+
+ public void toggleSOTM() {
+ if (SOTM) {
+ SOTM = false;
+ } else {
+ SOTM = true;
+ }
+ }
}