Skip to content
learnFRC.org
programminglesson30 min

Swerve Kinematics & Field-Oriented Drive

Mathematical transformations between chassis velocities and swerve module states, gyro field orientation, and wheel speed desaturation.

What you will learn

  • Understand NWU coordinate conventions and ChassisSpeeds representation.
  • Implement forward and inverse kinematics transformations.
  • Normalize wheel speeds using desaturation to preserve heading control.

Prerequisites:Swerve Project Generation & Calibration

A swerve drivebase achieves omnidirectional motion by independently commanding the drive velocity and steering azimuth of each of its four wheel modules.

To control this system, software must continuously convert between overall chassis motion and individual wheel states using Swerve Kinematics.


WPILib robotics standardizes on the NWU (North-West-Up) coordinate system:

  • +X: Forward downfield
  • +Y: Left
  • +θ\theta: Counter-clockwise rotation (in radians or degrees)

A robot’s instantaneous motion is represented by a ChassisSpeeds object:

// Robot commanded: 3.0 m/s forward, 1.0 m/s strafe left, 1.5 rad/s counter-clockwise rotation
ChassisSpeeds speeds = new ChassisSpeeds(3.0, 1.0, 1.5);

2. Field-Oriented vs. Robot-Oriented Drive

Section titled “2. Field-Oriented vs. Robot-Oriented Drive”
  • Robot-Oriented: Pushing the joystick forward drives in the direction the robot’s front bumper currently points. If the robot spins 180°, pushing forward drives toward the driver station.
  • Field-Oriented: Pushing the joystick forward drives away from the driver station regardless of robot heading.

WPILib converts field-oriented velocity vectors into robot-centric velocities using the robot’s gyro heading:

ChassisSpeeds robotSpeeds = ChassisSpeeds.fromFieldRelativeSpeeds(
fieldVx, fieldVy, fieldOmega, m_gyro.getRotation2d()
);

The transformation rotates the (vx,vy)(v_x, v_y) translation vector by −θ-\theta:

v_robot_x = v_field_x · cos(θ) + v_field_y · sin(θ)
v_robot_y = -v_field_x · sin(θ) + v_field_y · cos(θ)

3. Inverse Kinematics: toSwerveModuleStates

Section titled “3. Inverse Kinematics: toSwerveModuleStates”

Given the chassis velocity vector (vx,vy,ω)(v_x, v_y, \omega), Inverse Kinematics computes the target speed and steering angle for each module:

// Convert chassis speeds to 4 SwerveModuleState objects [FL, FR, BL, BR]
SwerveModuleState[] moduleStates = m_kinematics.toSwerveModuleStates(robotSpeeds);

Each module state contains:

  • speedMetersPerSecond: Target linear velocity of the drive wheel.
  • angle: Target azimuth steering angle (Rotation2d).

Consider a robot capable of a physical maximum wheel speed of 4.5 m/s. If the driver commands full forward throttle (4.5 m/s) while simultaneously commanding full spin rotation (3.0 rad/s), the outer wheels will mathematically be demanded to travel at 6.5 m/s.

Because the physical motors cannot exceed 4.5 m/s, the outer wheels will saturate at maximum output while the inner wheels run at lower commanded speeds. This destroys the velocity ratios and causes the robot to skew off course.

To prevent saturation, always call desaturateWheelSpeeds:

// Scales all module speeds down proportionally if any module exceeds physical limit
SwerveDriveKinematics.desaturateWheelSpeeds(moduleStates, MAX_PHYSICAL_SPEED_MPS);
Always Desaturate Before Setting Modules

Calling desaturateWheelSpeeds preserves the ratio between translation and rotation so the robot follows the commanded heading even at 100% throttle.


  • Symptom: Field-oriented driving veers in bizarre circles or inverts controls when the robot rotates.
  • Cause: Gyro yaw is reporting clockwise positive instead of counter-clockwise positive (NWU).
  • Fix: Verify gyro direction. In Phoenix 6, Pigeon 2.0 natively outputs CCW-positive angles matching WPILib.
  • Symptom: Driving straight works, but spinning while translating causes the robot to veer sharply.
  • Cause: Forgot to call SwerveDriveKinematics.desaturateWheelSpeeds(states, MAX_SPEED).
  • Fix: Add desaturation immediately after toSwerveModuleStates().

  1. In simulation or on the cart, command forward translation with the robot at 0° heading. Verify all 4 wheels steer to 0° and spin forward.
  2. Manually rotate the robot 90° CCW. Command forward translation again.
  3. Verify that the wheels steer to -90° (robot-relative) to maintain true field-forward motion.

Verified Sources & Standards

Evergreen Standard Verified: Sep 25, 2026