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
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:
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.
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.Discretization, to compensate for system delay —
SwerveDriveConfig.withDiscretizationTime(). See chassis control for what this does and why it matters.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).
If you mess with a lower step, all the higher steps will be out of sync — and if you replace a part like your gyro, you may need to redo all of it anyway.
The math-heavy explanation of tuning out drift is available here:
Last updated
Was this helpful?