Software · Drivetrain
Drive a swerve robot and watch two sticks become four wheel speeds and angles.
| Module | Angle (rad) | Asked (m/s) | Sent (m/s) | Steer travel (rad) |
|---|
Asked: straight out of kinematics. Sent: after desaturation and optimization (minus = wheel spins backward).
Measured speeds come back from the wheels. If they differ from what you asked, the robot isn't doing what the driver wanted.
The state RobotContainer asks for:
Which fixes we use. MWLib's Module.runSetpoint calls optimize and cosineScale on every module, and every drive request calls ChassisSpeeds.discretize. The drive requests do not call desaturateWheelSpeeds: in open-loop teleop a wheel asked for more than SPEED_AT_12V_MPS just runs at 12 V. Turn Desaturate off to see that.
From stick to ChassisSpeeds. MWLib's calculateSpeedsBasedOnJoystickInputs() deadbands each axis, flips the sign (stick forward reads negative, and WPILib +y is left), multiplies by the max rate, then slew-limits vx and vy:
Modules, ChassisSpeeds, inverse kinematics and the wheel fixes are explained in How Swerve Works. Controller axes: Operator Interface.
From the 2026 robot's SwerveConstants (AlphaBot) and MWLib's MwSwerveConstants defaults. Keys: WASD drive, Q/E turn, Shift half stick.