Why is checkpoint 3 optional?
It depends on whether or not your robot rotates your inputs already. If it does not, we need step 3!
// REQUIREMENTS: Have a drivetrain with at least a function or equivalent of
// m_drivetrain.driveAtSpeeds(ChassisSpeeds)
- Checkpoint 1
Have a swerve drivetrain configured and driveable, and have the request prepared for the next steps. (Reference other members/teams for this info!)
import edu.wpi.first.math.kinematics.ChassisSpeeds;
/* Robot.java */
// The direction of travel (DoT) will be different depending on if you are on red/blue alliance!
// NOTE: Test the DoT before use, as it may be reversed. Reverse it by negating driveSpeed below.
double autoDriveSpeed = 0.1;
ChassisSpeeds autoDriveSpeeds;
@Override
public void autonomousInit() {
autoDriveSpeeds = new ChassisSpeeds(autoDriveSpeed, 0, 0);
}
@Override
public void autonomousPeriodic() {
m_drivetrain.driveAtSpeeds(autoDriveSpeeds); // Drive at speed
}
@Override
public void teleopInit() {
m_drivetrain.driveAtSpeeds(new ChassisSpeeds(0, 0, 0)); // Stop
}
- Checkpoint 2
Have a functioning auto that moves when entering auto, and ends when entering teleop. Be sure to test both alliances to see if you need the next step at all! If you go the correct direction both times, success!
import edu.wpi.first.wpilibj.DriverStation.Alliance;
/* Robot.java */
// When auto starts, check the team we are on a and switch direction of travel as needed
// If your drivetrain already rotates movement by 180 deg depending on team, ignore this step
Optional<Alliance> team;
@Override
public void autonomousInit() {
team = DriverStation.getAlliance();
if (team.isPresent())
{
// Flip DoT based on alliance
if (team.get() == Alliance.Red) autoDriveSpeeds = new ChassisSpeeds(-autoDriveSpeed, 0, 0);
else autoDriveSpeeds = new ChassisSpeeds(autoDriveSpeed, 0, 0);
}
else
{
autoDriveSpeeds = new ChassisSpeeds(autoDriveSpeed, 0, 0);
System.out.println("No team assigned!");
}
//
// Continue with previously mentioned code...
//
}
- Checkpoint 3
Ensure that the auto goes the correct direction based on the alliance its on. Going the right way now? Success!