Software · Drivetrain

Swerve Kinematics Lab

Drive a swerve robot and watch two sticks become four wheel speeds and angles.

Step 1 of 7

Field

Robot velocity
Left stick · drive
ChassisSpeeds
vx –vy –ω –
Keys: W A S D, Q E · gamepads work too
Right stick · turn

Wheels

Wheel command Before desaturation
Show numbers
ModuleAngle (rad)Asked (m/s)Sent (m/s)Steer travel (rad)

Asked: straight out of kinematics. Sent: after desaturation and optimization (minus = wheel spins backward).

Heading θ–
Measured vx m/s–
Measured vy m/s–
Measured ω rad/s–

Measured speeds come back from the wheels. If they differ from what you asked, the robot isn't doing what the driver wanted.

Wheel fixes

More controls

Go deeper

Things to try
  1. Spin in place with only the right stick. Every wheel shows the same speed: ω × 0.269 m.
  2. Full forward plus full spin, then turn off Desaturate. The path bends.
  3. Turn off Optimize, set steering to 4 rad/s and flick from full forward to full back.
  4. Turn off Optimize and Cosine scaling, then reverse fast. The robot lurches the wrong way first.
  5. Turn off Discretize and drive straight while spinning hard in field-centric. The path drifts.
  6. In Rotation lock, strafe around the hub. The right stick does nothing.
In our robot code

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:

Robot constants and further reading

Modules, ChassisSpeeds, inverse kinematics and the wheel fixes are explained in How Swerve Works. Controller axes: Operator Interface.

Module positions
±0.1905 m (7.5 in)
Track width / wheelbase
0.381 m
SPEED_AT_12V_MPS
5.0 m/s
MAX_TRANSLATION_RATE
5.0 m/s
MAX_ANGULAR_RATE
10.0 rad/s
MAX_TRANSLATION_ACCEL
40 m/s²
CONTROLLER_DEADBAND
0.1
HEADING_CONTROLLER
kP 10, kD 1
Hub (blue)
(4.61, 4.02) m

From the 2026 robot's SwerveConstants (AlphaBot) and MWLib's MwSwerveConstants defaults. Keys: WASD drive, Q/E turn, Shift half stick.