Skip to content
This repository was archived by the owner on Jan 17, 2026. It is now read-only.

Commit fa1902a

Browse files
committed
[drive] Speedup auto align
Signed-off-by: Jade Turner <spacey-sooty@proton.me>
1 parent 7d3b557 commit fa1902a

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed

src/main/java/org/curtinfrc/frc2025/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* (log replay from a file).
1616
*/
1717
public final class Constants {
18-
public static final RobotType robotType = RobotType.COMPBOT;
18+
public static final RobotType robotType = RobotType.SIMBOT;
1919
public static final double ROBOT_X = 0.705;
2020
public static final double ROBOT_Y = 0.730;
2121
public static final double FIELD_LENGTH = aprilTagLayout.getFieldLength();

src/main/java/org/curtinfrc/frc2025/Robot.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ public Robot() {
299299

300300
autoChooser.addCmd("Test Auto", this::testAuto);
301301

302+
autoChooser.addCmd("Align to A", () -> drive.autoAlign(A::getPose));
303+
302304
// Set up SysId routines
303305
autoChooser.addCmd(
304306
"Drive Wheel Radius Characterization", () -> drive.wheelRadiusCharacterization());

src/main/java/org/curtinfrc/frc2025/subsystems/drive/Drive.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,23 @@ public class Drive extends SubsystemBase {
7777
private SwerveDrivePoseEstimator poseEstimator =
7878
new SwerveDrivePoseEstimator(kinematics, rawGyroRotation, lastModulePositions, Pose2d.kZero);
7979

80-
private final PIDController xController = new PIDController(3.5, 0, 0);
81-
private final PIDController yController = new PIDController(3.5, 0, 0);
82-
private final PIDController headingController = new PIDController(3.5, 0, 0);
80+
private final ProfiledPIDController xController =
81+
new ProfiledPIDController(
82+
10,
83+
0,
84+
0,
85+
new TrapezoidProfile.Constraints(
86+
getMaxLinearSpeedMetersPerSec(), MAX_LINEAR_ACCELERATION));
87+
private final ProfiledPIDController yController =
88+
new ProfiledPIDController(
89+
10,
90+
0,
91+
0,
92+
new TrapezoidProfile.Constraints(
93+
getMaxLinearSpeedMetersPerSec(), MAX_LINEAR_ACCELERATION));
94+
private final ProfiledPIDController headingController =
95+
new ProfiledPIDController(
96+
10, 0, 0, new TrapezoidProfile.Constraints(ANGLE_MAX_VELOCITY, ANGLE_MAX_ACCELERATION));
8397

8498
private final PIDController xFollower = new PIDController(1, 0, 0);
8599
private final PIDController yFollower = new PIDController(1, 0, 0);
@@ -145,9 +159,9 @@ public Drive(
145159
new SysIdRoutine.Mechanism(
146160
(voltage) -> runSteerCharacterization(voltage.in(Volts)), null, this));
147161

148-
xController.setTolerance(0.02);
149-
yController.setTolerance(0.02);
150-
headingController.setTolerance(0.02);
162+
xController.setTolerance(0.01);
163+
yController.setTolerance(0.01);
164+
headingController.setTolerance(0.01);
151165
headingController.enableContinuousInput(-Math.PI, Math.PI);
152166

153167
headingFollower.enableContinuousInput(-Math.PI, Math.PI);

src/main/java/org/curtinfrc/frc2025/subsystems/drive/DriveConstants.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import edu.wpi.first.math.geometry.Pose3d;
99
import edu.wpi.first.math.geometry.Rotation2d;
1010
import edu.wpi.first.math.geometry.Rotation3d;
11+
import edu.wpi.first.math.system.plant.DCMotor;
1112
import edu.wpi.first.util.struct.Struct;
1213
import edu.wpi.first.util.struct.StructGenerator;
1314
import edu.wpi.first.util.struct.StructSerializable;
@@ -30,6 +31,10 @@ public final class DriveConstants {
3031
public static final double FF_RAMP_RATE = 0.1; // Volts/Sec
3132
public static final double WHEEL_RADIUS_MAX_VELOCITY = 0.25; // Rad/Sec
3233
public static final double WHEEL_RADIUS_RAMP_RATE = 0.05; // Rad/Sec^2
34+
public static final double KT = DCMotor.getKrakenX60Foc(1).KtNMPerAmp * 5.99;
35+
// max acceleration = 4 * torque / r / robotWeight
36+
// torque = kT * statorCurrentLimit * gearRatio
37+
public static final double MAX_LINEAR_ACCELERATION = 4 * KT * 60 / 0.0508 / 38.5554;
3338
public static final double ODOMETRY_FREQUENCY =
3439
new CANBus(CompTunerConstants.DrivetrainConstants.CANBusName).isNetworkFD() ? 250.0 : 100.0;
3540
public static final double DRIVE_BASE_RADIUS =

0 commit comments

Comments
 (0)