]> git.taranathan.com Git - FRC2026.git/commitdiff
SOTM
authorWesley28w <wesleycwong@gmail.com>
Sat, 24 Jan 2026 23:40:57 +0000 (15:40 -0800)
committerWesley28w <wesleycwong@gmail.com>
Sat, 24 Jan 2026 23:40:57 +0000 (15:40 -0800)
src/main/java/frc/robot/commands/gpm/TurretAutoShoot.java
src/main/java/frc/robot/controls/PS5ControllerDriverConfig.java
src/main/java/frc/robot/subsystems/turret/Turret.java

index 24feadaa48aefafa8ff86530981762cd8444270e..057e8dae58d2d1cea3a4be659dea23e41928eaa4 100644 (file)
@@ -2,6 +2,7 @@ package frc.robot.commands.gpm;
 
 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;
@@ -16,6 +17,8 @@ public class TurretAutoShoot extends Command {
     private Drivetrain drivetrain;
     private TurretVision turretVision;
 
+    public boolean SOTM;
+
     double fieldAngleRad;
     double turretSetpoint;
     double adjustedSetpoint;
@@ -24,23 +27,37 @@ public class TurretAutoShoot extends Command {
 
     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);
index 7a064917a8d6b734f7410cb4be1e3d66119a1ba1..f35e45fd0ad23dea7f7ddf3e951581ee9aec3e54 100644 (file)
@@ -39,10 +39,13 @@ public class PS5ControllerDriverConfig extends BaseDriverConfig {
     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() { 
@@ -51,6 +54,8 @@ public class PS5ControllerDriverConfig extends BaseDriverConfig {
             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);
@@ -83,7 +88,7 @@ public class PS5ControllerDriverConfig extends BaseDriverConfig {
                         if (turretAutoShoot != null && turretAutoShoot.isScheduled()){
                             turretAutoShoot.cancel();
                         } else{
-                            turretAutoShoot = new TurretAutoShoot(turret, getDrivetrain());
+                            turretAutoShoot = new TurretAutoShoot(turret, getDrivetrain(), SOTM);
                             CommandScheduler.getInstance().schedule(turretAutoShoot);
                         }
                     })
@@ -160,4 +165,12 @@ public class PS5ControllerDriverConfig extends BaseDriverConfig {
     public void endRumble(){
         driver.rumbleOff();
     }
+
+    public void toggleSOTM() {
+        if (SOTM) {
+            SOTM = false;
+        } else {
+            SOTM = true;
+        }
+    }
 }
index 3d6e67a116341f99b88a2019e39dfe7a69a2ce4f..95b386f7d6ff9cb4e31c7ae1e12265dad5934947 100644 (file)
@@ -119,7 +119,6 @@ public class Turret extends SubsystemBase implements TurretIO{
     }
 
     public void setSetpoint(double setpointDegrees, double robotRotVel) {
-
         setpoint = MathUtil.clamp(setpointDegrees, TurretConstants.MIN_ANGLE, TurretConstants.MAX_ANGLE);
 
         if (infiniteRotation) {