Skip to content

Commit

Permalink
Add a command cancel in autoInit()
Browse files Browse the repository at this point in the history
Make sure all PathPlanner PIDs point to values in `Constants.java`.

	modified:   src/main/java/frc/robot/Constants.java
	modified:   src/main/java/frc/robot/Robot.java
	modified:   src/main/java/frc/robot/subsystems/drive/Drive.java
  • Loading branch information
tbowers7 committed Jan 15, 2025
1 parent e52c1d9 commit eddf329
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public static final class DrivebaseConstants {
public static final double kMaxLinearAccel = 4.0; // m/s/s
public static final double kMaxAngularAccel = Units.degreesToRadians(720);

// Drive and Turn PID constants
// Drive and Turn PID constants used for PathPlanner
public static final PIDConstants drivePID = new PIDConstants(0.05, 0.0, 0.0);
public static final PIDConstants steerPID = new PIDConstants(2.0, 0.0, 0.4);

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ public void disabledPeriodic() {
@Override
public void autonomousInit() {

// Just in case, cancel all running commands
CommandScheduler.getInstance().cancelAll();

// TODO: Make sure Gyro inits here with whatever is in the path planning thingie
m_robotContainer.setMotorBrake(true);
switch (Constants.getAutoType()) {
Expand Down
14 changes: 6 additions & 8 deletions src/main/java/frc/robot/subsystems/drive/Drive.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.ctre.phoenix6.swerve.SwerveRequest;
import com.pathplanner.lib.auto.AutoBuilder;
import com.pathplanner.lib.config.ModuleConfig;
import com.pathplanner.lib.config.PIDConstants;
import com.pathplanner.lib.config.RobotConfig;
import com.pathplanner.lib.controllers.PPHolonomicDriveController;
import com.pathplanner.lib.pathfinding.Pathfinding;
Expand Down Expand Up @@ -97,9 +96,6 @@ public class Drive extends SubsystemBase {
private SwerveDrivePoseEstimator m_PoseEstimator =
new SwerveDrivePoseEstimator(kinematics, rawGyroRotation, lastModulePositions, new Pose2d());

// Choreo drive controller
private final PIDController xController = new PIDController(10.0, 0.0, 0.0);

// Constructor
public Drive() {
switch (Constants.getSwerveType()) {
Expand Down Expand Up @@ -169,7 +165,7 @@ public Drive() {
this::getChassisSpeeds,
this::runVelocity,
new PPHolonomicDriveController(
new PIDConstants(5.0, 0.0, 0.0), new PIDConstants(5.0, 0.0, 0.0)),
DrivebaseConstants.drivePID, DrivebaseConstants.steerPID),
PP_CONFIG,
() -> DriverStation.getAlliance().orElse(Alliance.Blue) == Alliance.Red,
this);
Expand Down Expand Up @@ -441,6 +437,7 @@ public Command resetOdometry(Pose2d orElseGet) {
private final SwerveRequest.ApplyFieldSpeeds m_pathApplyFieldSpeeds =
new SwerveRequest.ApplyFieldSpeeds();

// Choreo Controller Values
private final PIDController m_pathXController = new PIDController(10, 0, 0);
private final PIDController m_pathYController = new PIDController(10, 0, 0);
private final PIDController m_pathThetaController = new PIDController(7, 0, 0);
Expand Down Expand Up @@ -474,9 +471,10 @@ public void followTrajectory(SwerveSample sample) {
// Generate the next speeds for the robot
ChassisSpeeds speeds =
new ChassisSpeeds(
sample.vx + xController.calculate(pose.getX(), sample.x),
sample.vy + xController.calculate(pose.getX(), sample.y),
sample.omega + xController.calculate(pose.getRotation().getRadians(), sample.heading));
sample.vx + m_pathXController.calculate(pose.getX(), sample.x),
sample.vy + m_pathXController.calculate(pose.getX(), sample.y),
sample.omega
+ m_pathXController.calculate(pose.getRotation().getRadians(), sample.heading));

// Apply the generated speeds
runVelocity(speeds);
Expand Down

0 comments on commit eddf329

Please sign in to comment.