]> git.taranathan.com Git - FRC2026.git/commitdiff
negative progress
authormoo <moogoesmeow123@gmail.com>
Sun, 22 Feb 2026 00:37:55 +0000 (16:37 -0800)
committermoo <moogoesmeow123@gmail.com>
Sun, 22 Feb 2026 00:37:55 +0000 (16:37 -0800)
src/main/java/frc/robot/RobotContainer.java
src/main/java/frc/robot/commands/drive_comm/DefaultDriveCommand.java
src/main/java/frc/robot/commands/gpm/SimpleAutoShoot.java
src/main/java/frc/robot/commands/vision/AimAtGamePiece.java
src/main/java/frc/robot/controls/PS5ControllerDriverConfig.java
src/main/java/frc/robot/util/TrenchAssist/TrenchAssist2.java
src/main/java/frc/robot/util/TrenchAssist/TrenchAssistConstants.java
src/main/java/frc/robot/util/Vision/TurretVision.java [deleted file]

index 377285c816d512c2b3e9088bcdc48549402901df..aab87c83fb81d880dcee2b3b3ce3a4055e8e1166 100644 (file)
@@ -59,7 +59,7 @@ public class RobotContainer {
   private Command auto = new DoNothing();
 
   // Controllers are defined here
-  private BaseDriverConfig driver = null;
+  private PS5ControllerDriverConfig driver = null;
   private Operator operator = null;
 
   /**
index 8156f5c7c1107ec40b85f4c7b5ff459b6a0fe895..5c176306d0ff21f10c8f9af6ae306f72820edf8b 100644 (file)
@@ -3,6 +3,7 @@ package frc.robot.commands.drive_comm;
 import org.littletonrobotics.junction.Logger;
 
 import edu.wpi.first.math.geometry.Rectangle2d;
+import edu.wpi.first.math.geometry.Rotation2d;
 import edu.wpi.first.math.kinematics.ChassisSpeeds;
 import edu.wpi.first.math.util.Units;
 import edu.wpi.first.wpilibj.DriverStation.Alliance;
@@ -11,21 +12,24 @@ import edu.wpi.first.wpilibj2.command.Command;
 import frc.robot.Robot;
 import frc.robot.constants.swerve.DriveConstants;
 import frc.robot.controls.BaseDriverConfig;
+import frc.robot.controls.PS5ControllerDriverConfig;
 import frc.robot.subsystems.drivetrain.Drivetrain;
 import frc.robot.util.TrenchAssist.TrenchAssist;
+import frc.robot.util.TrenchAssist.TrenchAssist2;
 import frc.robot.util.TrenchAssist.TrenchAssistConstants;
 import frc.robot.util.Vision.DriverAssist;
+import lib.controllers.PS5Controller.PS5Axis;
 
 /**
  * Default drive command. Drives robot using driver controls.
  */
 public class DefaultDriveCommand extends Command {
     protected final Drivetrain swerve;
-    protected final BaseDriverConfig driver;
+    protected final PS5ControllerDriverConfig driver;
 
     public DefaultDriveCommand(
             Drivetrain swerve,
-            BaseDriverConfig driver) {
+            PS5ControllerDriverConfig driver) {
         this.swerve = swerve;
         this.driver = driver;
 
@@ -45,6 +49,20 @@ public class DefaultDriveCommand extends Command {
         double forwardTranslation = driver.getForwardTranslation();
         double sideTranslation = driver.getSideTranslation();
         double rotation = -driver.getRotation();
+        // if (swerve.getTrenchAssist()) {
+        //     sideTranslation = Math
+        //             .sqrt(driver.controller.get(PS5Axis.LEFT_X) * driver.controller.get(PS5Axis.LEFT_Y)
+        //                     * driver.controller.get(PS5Axis.LEFT_X) * driver.controller.get(PS5Axis.LEFT_Y))
+        //             *
+        //             new Rotation2d(driver.controller.get(PS5Axis.LEFT_X), driver.controller.get(PS5Axis.LEFT_Y))
+        //                     .rotateBy(swerve.getYaw()).getCos();
+        //     forwardTranslation = Math
+        //             .sqrt(driver.controller.get(PS5Axis.LEFT_X) * driver.controller.get(PS5Axis.LEFT_Y)
+        //                     * driver.controller.get(PS5Axis.LEFT_X) * driver.controller.get(PS5Axis.LEFT_Y))
+        //             *
+        //             new Rotation2d(driver.controller.get(PS5Axis.LEFT_X), driver.controller.get(PS5Axis.LEFT_Y))
+        //                     .rotateBy(swerve.getYaw()).getSin();
+        // }
 
         double slowFactor = driver.getIsSlowMode() ? DriveConstants.SLOW_DRIVE_FACTOR : 1;
 
@@ -86,7 +104,7 @@ public class DefaultDriveCommand extends Command {
 
         Logger.recordOutput("TrenchAssist", swerve.getTrenchAssist());
         if (swerve.getTrenchAssist()) {
-            drive(TrenchAssist.calculate(swerve, corrected));
+            drive(TrenchAssist2.calculate(swerve, corrected));
         } else {
             drive(corrected);
         }
index 899a51e4b536beb8321af83bdc492b291e8ee053..0f0b8dd1aaae27ecc980a1a1521eaded13bfcf43 100644 (file)
@@ -23,12 +23,10 @@ import frc.robot.subsystems.turret.ShotInterpolation;
 import frc.robot.subsystems.turret.Turret;
 import frc.robot.util.FieldZone;
 import frc.robot.util.ShootingTarget;
-import frc.robot.util.Vision.TurretVision;
 
 public class SimpleAutoShoot extends Command {
     private Turret turret;
     private Drivetrain drivetrain;
-    private TurretVision turretVision;
     private Shooter shooter;
 
     private double fieldAngleRad;
@@ -93,19 +91,6 @@ public class SimpleAutoShoot extends Command {
         // System.out.println("Aligning the turn to degree angle: " + turretSetpoint);
     }
 
-    public void adjustWithTurretCam() {
-        if(turretVision.canSeeTag(26) || turretVision.canSeeTag(10)){
-            // Adjust turret setpoint based on vision input
-            if(Robot.getAlliance() == Alliance.Blue){
-                yawToTagCamera = -1 * Units.radiansToDegrees(turretVision.getYawToTagRad(26).get());
-            }
-            else{
-                yawToTagCamera = -1 * Units.radiansToDegrees(turretVision.getYawToTagRad(10).get());
-            }
-            double error = yawToTagCamera - yawToTag;
-            adjustedSetpoint = turretSetpoint + error;
-        }
-    }
 
     public void updateYawToTag(){
         // Calculate the yaw offset to the tag
index f3c371ce72a856cb5fcc5928a75242623771e2c7..ad8eef67c8567ce0e308b0a1b29dd9cf71db731e 100644 (file)
@@ -7,6 +7,7 @@ import edu.wpi.first.math.kinematics.ChassisSpeeds;
 import frc.robot.commands.drive_comm.DefaultDriveCommand;
 import frc.robot.constants.VisionConstants;
 import frc.robot.controls.BaseDriverConfig;
+import frc.robot.controls.PS5ControllerDriverConfig;
 import frc.robot.subsystems.drivetrain.Drivetrain;
 import frc.robot.util.Vision.DetectedObject;
 
@@ -16,7 +17,7 @@ public class AimAtGamePiece extends DefaultDriveCommand {
     private static DetectedObject cachedObject;
   
 
-    public AimAtGamePiece(Drivetrain drive, BaseDriverConfig driver, Supplier<DetectedObject> objectSupplier){
+    public AimAtGamePiece(Drivetrain drive, PS5ControllerDriverConfig driver, Supplier<DetectedObject> objectSupplier){
         super(drive, driver);
         this.objectSupplier = objectSupplier;
     }
index 6df9538bb5e9ac66976dd57c52a9ef03837d3504..0e035cc3b8e222bd06dbffed6c99d11914bbb571 100644 (file)
@@ -21,7 +21,7 @@ import lib.controllers.PS5Controller.PS5Button;
  * Driver controls for the PS5 controller
  */
 public class PS5ControllerDriverConfig extends BaseDriverConfig {
-    private final PS5Controller driver = new PS5Controller(Constants.DRIVER_JOY);
+    public final PS5Controller controller = new PS5Controller(Constants.DRIVER_JOY);
     private final BooleanSupplier slowModeSupplier = () -> false;
     private boolean intakeBoolean = true;
     private Command autoShoot = null;
@@ -40,27 +40,27 @@ public class PS5ControllerDriverConfig extends BaseDriverConfig {
 
     public void configureControls() {
         // Reset the yaw. Mainly useful for testing/driver practice
-        driver.get(PS5Button.CREATE).onTrue(new InstantCommand(() -> getDrivetrain().setYaw(
+        controller.get(PS5Button.CREATE).onTrue(new InstantCommand(() -> getDrivetrain().setYaw(
                 new Rotation2d(Robot.getAlliance() == Alliance.Blue ? 0 : Math.PI))));
 
         // Cancel commands
-        driver.get(PS5Button.RIGHT_TRIGGER).onTrue(new InstantCommand(() -> {
+        controller.get(PS5Button.RIGHT_TRIGGER).onTrue(new InstantCommand(() -> {
             getDrivetrain().setIsAlign(false);
             getDrivetrain().setDesiredPose(() -> null);
             CommandScheduler.getInstance().cancelAll();
         }));
 
         // Align wheels
-        driver.get(PS5Button.MUTE).onTrue(new FunctionalCommand(
+        controller.get(PS5Button.MUTE).onTrue(new FunctionalCommand(
                 () -> getDrivetrain().setStateDeadband(false),
                 getDrivetrain()::alignWheels,
                 interrupted -> getDrivetrain().setStateDeadband(true),
                 () -> false, getDrivetrain()).withTimeout(2));
 
-        driver.get(PS5Button.CROSS).onTrue(new InstantCommand(() -> getDrivetrain().setTrenchAlign(true)))
+        controller.get(PS5Button.CROSS).onTrue(new InstantCommand(() -> getDrivetrain().setTrenchAlign(true)))
             .onFalse(new InstantCommand(() -> getDrivetrain().setTrenchAlign(false)));
 
-        driver.get(PS5Button.CIRCLE).onTrue(new InstantCommand(() -> getDrivetrain().setTrenchAssist(true)))
+        controller.get(PS5Button.CIRCLE).onTrue(new InstantCommand(() -> getDrivetrain().setTrenchAssist(true)))
             .onFalse(new InstantCommand(() -> getDrivetrain().setTrenchAssist(false)));
 
 
@@ -125,27 +125,27 @@ public class PS5ControllerDriverConfig extends BaseDriverConfig {
 
     @Override
     public double getRawSideTranslation() {
-        return driver.get(PS5Axis.LEFT_X);
+        return controller.get(PS5Axis.LEFT_X);
     }
 
     @Override
     public double getRawForwardTranslation() {
-        return driver.get(PS5Axis.LEFT_Y);
+        return controller.get(PS5Axis.LEFT_Y);
     }
 
     @Override
     public double getRawRotation() {
-        return driver.get(PS5Axis.RIGHT_X);
+        return controller.get(PS5Axis.RIGHT_X);
     }
 
     @Override
     public double getRawHeadingAngle() {
-        return Math.atan2(driver.get(PS5Axis.RIGHT_X), -driver.get(PS5Axis.RIGHT_Y)) - Math.PI / 2;
+        return Math.atan2(controller.get(PS5Axis.RIGHT_X), -controller.get(PS5Axis.RIGHT_Y)) - Math.PI / 2;
     }
 
     @Override
     public double getRawHeadingMagnitude() {
-        return Math.hypot(driver.get(PS5Axis.RIGHT_X), driver.get(PS5Axis.RIGHT_Y));
+        return Math.hypot(controller.get(PS5Axis.RIGHT_X), controller.get(PS5Axis.RIGHT_Y));
     }
 
     @Override
@@ -159,10 +159,10 @@ public class PS5ControllerDriverConfig extends BaseDriverConfig {
     }
 
     public void startRumble() {
-        driver.rumbleOn();
+        controller.rumbleOn();
     }
 
     public void endRumble() {
-        driver.rumbleOff();
+        controller.rumbleOff();
     }
 }
index 183791db5f09dc7b2b217df0047df7b9797dcd2c..af107681d2e209680b9c9670dea8224450d00ec2 100644 (file)
@@ -110,68 +110,33 @@ public class TrenchAssist2 {
         return Optional.empty();
     }
 
-    static Translation2d calculateCorrection(Rectangle2d[] rectangles, Drivetrain drive, ChassisSpeeds predictedSpeeds) {
-        Pose2d pose = drive.getPose();
-
-        Translation2d velocityRobotRelative = new Translation2d(predictedSpeeds.vxMetersPerSecond,
-                predictedSpeeds.vyMetersPerSecond);
-
-        Translation2d velocityFieldRelative = velocityRobotRelative.rotateBy(drive.getYaw());
-
-        double halfRobotWidth = 0.5 * DriveConstants.ROBOT_WIDTH_WITH_BUMPERS;
-
-        Translation2d[] robotCorners = new Translation2d[] {
-                pose.transformBy(new Transform2d(new Translation2d(halfRobotWidth, 0), new Rotation2d(0.0)))
-                        .getTranslation(),
-                pose.transformBy(new Transform2d(new Translation2d(0, halfRobotWidth), new Rotation2d(0.0)))
-                        .getTranslation(),
-                pose.transformBy(new Transform2d(new Translation2d(-halfRobotWidth, 0), new Rotation2d(0.0)))
-                        .getTranslation(),
-                pose.transformBy(new Transform2d(new Translation2d(0, -halfRobotWidth), new Rotation2d(0.0)))
-                        .getTranslation(),
-        };
-
-        for (Translation2d corner : robotCorners) {
-            for (Rectangle2d rectangle : rectangles) {
-                Optional<Double> distanceOptional = rayCast(rectangle, corner, velocityFieldRelative, 1.0);
-                if (distanceOptional.isPresent()) {
-                    double timeToCollision = distanceOptional.get(); // seconds
-                    double timeWindow = 1.0; //secs
-                    double scale = Math.max(0.0, 1.0 - (timeToCollision / timeWindow));
-
-
-                    if (drive.getPose().getY() > rectangle.getCenter().getY() + (rectangle.getYWidth() / 2)) {
-                        // above rectangle: push +90 deg
-                        return velocityFieldRelative.rotateBy(new Rotation2d(Units.degreesToRadians(90))).times(scale);
-                    } else if (drive.getPose().getY() <= rectangle.getCenter().getY() - (rectangle.getYWidth() / 2)) {
-                        // below rectangle push -90 deg
-                        return velocityFieldRelative.rotateBy(new Rotation2d(Units.degreesToRadians(-90))).times(scale);
-                    }
-
-                    // emergency fallback
-                    if (rayCast(rectangle, corner, velocityFieldRelative, 0.2).isPresent()) {
-                        return velocityFieldRelative.unaryMinus();
-                    }
-                }
-            }
-        }
 
-        return new Translation2d(0, 0);
 
-    }
+    public static ChassisSpeeds funky(Drivetrain drive, ChassisSpeeds chassisSpeeds) {
+        ChassisSpeeds speedsFieldRelative = ChassisSpeeds.fromRobotRelativeSpeeds(chassisSpeeds, drive.getYaw());
+        ChassisSpeeds horizontalSpeeds = new ChassisSpeeds(speedsFieldRelative.vxMetersPerSecond, 0.0, speedsFieldRelative.omegaRadiansPerSecond);
 
+        Logger.recordOutput("slideTranslation", new Translation2d(horizontalSpeeds.vxMetersPerSecond, horizontalSpeeds.vyMetersPerSecond));
 
-    public static ChassisSpeeds calculate(Drivetrain drive, ChassisSpeeds chassisSpeeds) {
-        Translation2d correctionFieldRelative = calculateCorrection(TrenchAssistConstants.OBSTACLES, drive, chassisSpeeds);
-
-        Logger.recordOutput("TrenchCorrectionFieldRelative", correctionFieldRelative);
-
-        ChassisSpeeds correctionRobot = convertToChassisSpeedsRobotRelative(correctionFieldRelative, drive);
-
-        double vx = chassisSpeeds.vxMetersPerSecond + correctionRobot.vxMetersPerSecond;
-        double vy = chassisSpeeds.vyMetersPerSecond + correctionRobot.vyMetersPerSecond;
+        var x = new ChassisSpeeds(horizontalSpeeds.vxMetersPerSecond, horizontalSpeeds.vyMetersPerSecond, chassisSpeeds.omegaRadiansPerSecond);
+        var y = new Translation2d(x.vxMetersPerSecond, x.vyMetersPerSecond).rotateBy(drive.getYaw().unaryMinus());
+        return new ChassisSpeeds(y.getX(), y.getY(), x.omegaRadiansPerSecond);
+    }
 
-        return new ChassisSpeeds(vx, vy, chassisSpeeds.omegaRadiansPerSecond);
+    public static ChassisSpeeds calculate(Drivetrain drive, ChassisSpeeds chassisSpeeds) {
+        double yawRadians = drive.getYaw().unaryMinus().getRadians();
+        
+        double fieldRelativeX = chassisSpeeds.vxMetersPerSecond * Math.cos(yawRadians) - chassisSpeeds.vyMetersPerSecond * Math.sin(yawRadians);
+        double fieldRelativeY = chassisSpeeds.vxMetersPerSecond * Math.sin(yawRadians) + chassisSpeeds.vyMetersPerSecond * Math.cos(yawRadians);
+        
+        fieldRelativeY = 0;
+        
+        double neutralizedRobotX = fieldRelativeX * Math.cos(yawRadians) + fieldRelativeY * Math.sin(yawRadians);
+        double neutralizedRobotY = -fieldRelativeX * Math.sin(yawRadians) + fieldRelativeY * Math.cos(yawRadians);
+
+        var x = new Translation2d(neutralizedRobotX, neutralizedRobotY).rotateBy(drive.getYaw().unaryMinus());
+
+        return new ChassisSpeeds(x.getX(), x.getY(), chassisSpeeds.omegaRadiansPerSecond);
     }
 
     public static ChassisSpeeds convertToChassisSpeedsRobotRelative(Translation2d translation, Drivetrain drive){
@@ -184,7 +149,7 @@ public class TrenchAssist2 {
     public static Translation2d convertToTranslation2dFieldRelative(ChassisSpeeds speeds, Drivetrain drive){
         Rotation2d yaw = drive.getYaw();
         Translation2d robotTranslation = new Translation2d(speeds.vxMetersPerSecond, speeds.vyMetersPerSecond);
-        return robotTranslation.rotateBy(yaw.times(-1));
+        return robotTranslation.rotateBy(yaw.times(-1));        
 
     }
 }
\ No newline at end of file
index 75e905fb6323e4e77abe6e2aad5a1c91c8c28a80..29654bbc88eb7c71d1181c7ed16786c87fef72cd 100644 (file)
@@ -2,6 +2,7 @@ package frc.robot.util.TrenchAssist;
 
 import edu.wpi.first.math.geometry.Rectangle2d;
 import edu.wpi.first.math.geometry.Translation2d;
+import edu.wpi.first.math.util.Units;
 
 public class TrenchAssistConstants {
     public static final Rectangle2d[] OBSTACLES = new Rectangle2d[]{
@@ -19,5 +20,9 @@ public class TrenchAssistConstants {
         // new Rectangle2d(new Translation2d(99.99, 99.9), new Translation2d(0.0, 0.0)),
     };
 
+    public static final double[] SLIDE_ZONES = new double[]{
+        8.07 - Units.inchesToMeters(25.0),
+        Units.inchesToMeters(25.0),
+    };
 
 }
\ No newline at end of file
diff --git a/src/main/java/frc/robot/util/Vision/TurretVision.java b/src/main/java/frc/robot/util/Vision/TurretVision.java
deleted file mode 100644 (file)
index 09f69ee..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-package frc.robot.util.Vision;
-
-import java.util.Optional;
-
-import org.photonvision.PhotonCamera;
-import org.photonvision.targeting.PhotonPipelineResult;
-import org.photonvision.targeting.PhotonTrackedTarget;
-
-import edu.wpi.first.math.util.Units;
-
-public class TurretVision {
-
-    private final PhotonCamera camera;
-
-    public TurretVision(String cameraName) {
-        camera = new PhotonCamera(cameraName);
-    }
-
-  /**
-   * @param tagId AprilTag ID to aim at
-   * @return Optional yaw error in radians (positive = target to the right, negative = target to the left)
-   */
-    public Optional<Double> getYawToTagRad(int tagId) {
-        PhotonPipelineResult result = camera.getLatestResult();
-
-        if (!result.hasTargets()) {
-            return Optional.empty();
-        }
-
-        for (PhotonTrackedTarget target : result.getTargets()) {
-            if (target.getFiducialId() == tagId) {
-                // PhotonVision yaw is in DEGREES
-                double yawRad = Units.degreesToRadians(target.getYaw());
-                return Optional.of(yawRad);
-            }
-        }
-
-        return Optional.empty();
-    }
-
-    public boolean canSeeTag(int tagId) {
-        PhotonPipelineResult result = camera.getLatestResult();
-        if (!result.hasTargets()) return false;
-
-        for (PhotonTrackedTarget target : result.getTargets()) {
-        if (target.getFiducialId() == tagId) {
-            return true;
-        }
-        }
-        return false;
-    }
-}