What is Kinematics?
Kinematics converts between chassis motion (the robot’s overall movement) and individual wheel speeds:- Forward Kinematics: Wheel speeds → Chassis speeds
- Inverse Kinematics: Chassis speeds → Wheel speeds
- Converting joystick inputs to wheel commands
- Calculating robot velocity from encoders
- Implementing field-oriented drive
- Trajectory following
Differential Drive Kinematics
For robots with left and right wheel groups (tank drive, West Coast Drive).Creating the Kinematics Object
wpimath/src/main/native/include/frc/kinematics/DifferentialDriveKinematics.h:29
Inverse Kinematics
Convert desired chassis motion to wheel speeds:wpimath/src/main/native/include/frc/kinematics/DifferentialDriveKinematics.h:70
Forward Kinematics
Calculate chassis motion from wheel speeds:wpimath/src/main/native/include/frc/kinematics/DifferentialDriveKinematics.h:56
Mecanum Drive Kinematics
For mecanum drivetrains with omnidirectional movement.Creating the Kinematics Object
wpimath/src/main/native/include/frc/kinematics/MecanumDriveKinematics.h:43
Inverse Kinematics
Custom Center of Rotation
Mecanum drives can rotate around any point:wpimath/src/main/native/include/frc/kinematics/MecanumDriveKinematics.h:104
Swerve Drive Kinematics
For swerve drivetrains with independently rotating modules.Creating the Kinematics Object
wpimath/src/main/native/include/frc/kinematics/SwerveDriveKinematics.h:52
Inverse Kinematics
wpimath/src/main/native/include/frc/kinematics/SwerveDriveKinematics.h:158
Desaturating Wheel Speeds
Prevent wheel speeds from exceeding physical limits:wpimath/src/main/native/include/frc/kinematics/SwerveDriveKinematics.h:347
Odometry
Odometry tracks robot position on the field using encoder and gyro measurements.Differential Drive Odometry
wpimath/src/main/native/include/frc/kinematics/DifferentialDriveOdometry.h:29
Mecanum Drive Odometry
Swerve Drive Odometry
Resetting Odometry
Field-Oriented Drive
Field-oriented (field-relative) drive allows drivers to control the robot relative to the field rather than the robot:Best Practices
- Update Odometry Frequently: Call
Update()every robot periodic cycle (20ms) - Reset Encoders: Zero encoders when resetting odometry
- Calibrate Track Width: Tune track width empirically for accurate rotation
- Use Gyro for Heading: Gyros are more accurate than encoder-based heading
- Validate with Field Markers: Verify odometry accuracy against known field positions
Common Issues
Odometry Drift: Accumulates error over time- Solution: Use vision pose estimation to periodically reset
- Use WPILib’s Pose Estimator classes for sensor fusion
- Check track width measurement
- Ensure encoders return distance in meters
- Verify gyro angle is in correct direction
- Check encoder polarities
- Verify wheel speed signs