// Vendor Library: Phoenix 6
// https://maven.ctr-electronics.com/release/com/ctre/phoenix6/latest/Phoenix6-frc2025-latest.json
import com.ctre.phoenix6.swerve.SwerveDrivetrain;
import com.ctre.phoenix6.swerve.SwerveRequest;
/* Robot.java */
// If you already have your own drivetrain, reference that instead!
private final SwerveDrivetrain m_drivetrain = TunerConstants.DriveTrain;
private final SwerveRequest.FieldCentric m_driveRequest = new SwerveRequest.FieldCentric()
.withDriveRequestType(DriveRequestType.OpenLoopVoltage)
.withSteerRequestType(SteerRequestType.MotionMagicExpo);
// Additional modifiers include...
// .withDeadband(MaxSpeed * 0.1) // Add a 10% deadband to driving motions
// .withRotationalDeadband(MaxAngularRate * 0.1) // Add a 10% deadband to turning motions
- Checkpoint 1
Have a swerve drivetrain configured and drivable, 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 */
// NOTE: 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 driveSpeed = 0.1;
@Override
public void autonomousPeriodic() {
m_drivetrain.setControl(
m_driveRequest.withVelocityX(driveSpeed) // Drive in a straight line
.withVelocityY(0)
.withRotationalRate(0)
);
}
@Override
public void teleopInit() {
m_drivetrain.setControl(
m_driveRequest.withVelocityX(0) // Stop
.withVelocityY(0)
.withRotationalRate(0)
);
}
- 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) driveSpeed *= -1;
}
else
{
// Disable movement because of unassigned alliance state
driveSpeed = 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!
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!