We have a swerve bot using mk4 modules and running the WPILib SwerveControllerCommand. During autonomous which uses a SequentialCommandGroup, we run a Trajectory then a WaitCommand. However, when the Trajectory is over and the WaitCommand starts, the robot drifts in the last direction it was going when the Trajectory finished. Is this a problem with the WaitCommand or something else?
public class ultrasonicAuto extends SequentialCommandGroup {
public ultrasonicAuto(Swerve s_Swerve, Ultrasonic ultrasonic, Timer timer){
System.out.println("Ultrasonic Auto !!");
TrajectoryConfig config =
new TrajectoryConfig(
Constants.AutoConstants.kMaxSpeedMetersPerSecond,
Constants.AutoConstants.kMaxAccelerationMetersPerSecondSquared)
.setKinematics(Constants.Swerve.swerveKinematics);
Trajectory firstHalfTrajectory =
TrajectoryGenerator.generateTrajectory(
List.of(new Pose2d(0, 0, new Rotation2d(0)), new Pose2d(1, 0, new Rotation2d(0)), new Pose2d(1, 1, new Rotation2d(90))),
config);
var thetaController = new ProfiledPIDController(Constants.AutoConstants.kPThetaController, 0, 0, Constants.AutoConstants.kThetaControllerConstraints);
thetaController.enableContinuousInput(-Math.PI, Math.PI);
SwerveControllerCommand firstHalfTraject = new SwerveControllerCommand(firstHalfTrajectory, s_Swerve::getPose, Constants.Swerve.swerveKinematics, new PIDController(Constants.AutoConstants.kPXController, 0, 0), new PIDController(Constants.AutoConstants.kPYController, 0, 0), thetaController, s_Swerve::setModuleStates, s_Swerve);
WaitCommand firstWait = new WaitCommand(3);
WaitCommand secondWait = new WaitCommand(3);
addCommands(
new InstantCommand(() -> s_Swerve.resetOdometry(firstHalfTrajectory.getInitialPose())),
firstWait,
firstHalfTraject ,
secondWait
);
}
}