Swerve Requests#
Controlling the drivetrain is done using setControl(SwerveRequest request)
(Java) which takes a given SwerveRequest
(Java). There are multiple pre-defined SwerveRequest
implementations, or users can define their own (only recommended for advanced scenarios).
Applying a Request#
Requests are instantiated once and then mutated using various withX
functions. In the below example, a FieldCentric
(Java) request is created and given values from a joystick.
SwerveDrivetrain m_drivetrain = TunerConstants.DriveTrain;
SwerveRequest.FieldCentric m_driveRequest = new SwerveRequest.FieldCentric()
.withIsOpenLoop(true);
XboxController m_joystick = new XboxController(0);
@Override
public void teleopPeriodic() {
m_drivetrain.setControl(
m_driveRequest.withVelocityX(-joystick.getLeftY())
.withVelocityY(-joystick.getLeftX())
.withRotationalRate(-joystick.getRightX())
);
Tip
Users can optionally make their own SwerveRequests
by implementing the SwerveRequest
interface.