Field Relative SwerveDrive Drift (Even With Simulated Perfect Modules)

So our team has not used a Swerve Drive in any of our seasons before, but we were experimenting with it using the simulation tools within WPILib. We noticed that when doing field relative controls, if you turned while moving, you would slightly drift in the direction you were turning. We thought that this was because the PID loops were not perfect (which does contribute to some drifting), but even when we simulate perfect modules, there is still a bit of drift while moving and turning.

We soon realized that this is a bi-product of controlling the robot in discrete time steps. As you can see from this desmos we made, the swerve drive will drift slightly in the direction you’re turning due to the robot traveling in a curved path. We also found the exact amount you can rotate your translation vector by to account for this which is 0.5 * w * dt where w is your angular velocity and dt is the time between each robot update. But even this wasn’t perfect, because when your swerve drive desaturates the motor velocities, it changes your angular velocity, so you need to adjust w based on how much your wheels are being desaturated. Accounting for all of this, we were able to get our swerve drive to move in a straight line while turning in the simulation.

However more issues arose when we simulated our PID loop. Because the modules were not perfectly following their trajectories, the robot would drift while moving and turning. We are using NEO’s on our swerve drive as we do not have access to falcons, which makes the PID loops a little bit worse for our modules. Is there any way to account for the drift caused by imperfect swerve modules? or do teams generally just ignore the drift that happens during a match.


Are you guys running custom swerve modules or COTS ones? As I know SDS has base code with PIDs for their modules, which it seems that a lot of teams used, so I don’t know if they are doing anything special.


We are using COTS ones, but we are using NEO’s and we are also using an absolute encoder. It still drifts when moving and turning though, due to provided PID loop not being great and there just being some fundamental math issues that cause drift.

I haven’t really worked with swerve so this might not work at all, but couldn’t you try to use the gyro to measure any drift that is occurring and then compensate by nudging the robot in opposite direction it is drifting.

You could try running a PID loop using the gyro angle as the input and the output being a target robot rotation that gets sent to the swerve modules. This would serve as an “active” method of compensating for the drift of the robot angle. This is the approach I took for the same issue on our robot.

We don’t have issues with the robot angle drifting, but just that, when we are turning and moving, the robot does not move in the direction that we are telling it to.

Oh I misunderstood. Are you using the onboard PID controllers, because those are not limited by the robot code’s running frequency.

We are planning on using these, but there we will have to see if the drift issue persists even when using those.

Have you tuned your PID controllers? if you haven’t that could be another explanation for the improper angles.

if you are using sds ones I’m 99% sure they have code for both NEOs and absolute encoders built in so I would consider looking at it if you want a fast solution

1 Like

Have you verified this behavior on a robot or is this all in the simulator?