For the complete documentation index, see llms.txt. This page is also available as Markdown.

Swerve Drive Drift: Causes and Tuning Order

Drift can be caused by anything and everything in a swerve drive...

Swerve drive drift has been a persistent problem for many years, and there have been many discussions as to why it happens. This is a lookup of common causes, followed by the fixed tuning order that removes what's left. For step-by-step tuning instructions, see How to Tune PIDF Gains.

It's important to keep in mind that SEVERAL of these issues could be present on your robot at once.

Hardware causes

Wiring

Incorrect, worn, or loose wiring produces different symptoms depending on which connector is affected.

Encoder

Motor controller

Gyroscope

Physical components

Magnetic (absolute) encoder

Motor

Swerve module

Robot

Software causes

Several runtime tuning knobs from older YAGSL versions (setCosineCompensator, setHeadingCorrection, setAntiJitter, chassisVelocityCorrection, setMaximumSpeeds, replaceSwerveModuleFeedforward, setOdometryPeriod, updateCacheValidityPeriods) no longer exist as runtime methods on SwerveDrive. Cosine compensation is now always enabled internally by the parser, and the rest are configured once, up front, via SwerveDriveConfig/SwerveModuleConfig (or pidfproperties.json's s/v/a feedforward terms) rather than toggled at runtime. See the API reference and schema changes reference for what replaced each.

PathPlanner

Configuration causes

Tuning order

Once hardware and configuration issues are ruled out, tune in this order — each step builds on the last, so redoing an earlier one (or replacing hardware like your gyro) means redoing everything after it:

  1. Drive and angle PID — see how to tune PIDF gains. Do this first; nothing else is worth tuning until the modules track their setpoints well.

  2. Vision standard deviation, if you're using vision to help odometry — tune SwerveDrive.setVisionMeasurementStdDevs() mostly by guess-and-check, scaling with distance. Some teams get better stability by filtering out vision poses beyond a certain distance.

  3. Discretization, to compensate for system delay — SwerveDriveConfig.withDiscretizationTime(). See chassis control for what this does and why it matters.

  4. Gyro angular velocity scale factor, to compensate for gyro system delay — SwerveDriveConfig.withGyroAngularVelocityScaleFactor() (less necessary with a Pigeon 2 on a CANivore, which has very low latency).

The math-heavy explanation of tuning out drift is available here:

Last updated

Was this helpful?