MK4 drift

If the encoder values are the same then to the repo, everything is working correctly. I’m pretty stumped on this.

You’re running open-loop drive velocities. Variable friction in the module gearboxes will cause drift, for the same reason that differential drives often fail to drive straight under open-loop control.

To track straighter, implement better velocity control or add gyro feedback.

We considered this, we thought of using the gryo to keep the robot at a set heading and only updating the heading when the robot is spinning. Would this be a good remedy or is there another solution we should try?

You should update the odometry with the current (rather than desired) heading, but yes, that’s the idea.

If it is too close the the magent what we did was put small pieces of paper between the sensor and the magnet until it turned green. You are right that that should not be the cause of the problem but my ocd demanded them all to be green.

Im also apart the original poster’s team, this seems to the solution, we have it adjusting for the drift in real time and update it’s heading. We just need to tune our PID values to make it feel less mushy and stop it from overshooting slightly. We will post the code once we think we got it fixed.


If your PID loop is closed on gyro heading, I’d advise focusing mostly on the D term to keep the robot stable while moving, with a little bit of P to clean up the steady-state error.

PID driftCorrectionPID = new PID(0.07, 0.00, 0.004);
double desiredHeading;
double pXY = 0;

public void driftCorrection(ChassisSpeeds speeds){

double xy = Math.abs(speeds.vxMetersPerSecond) + Math.abs(speeds.vyMetersPerSecond);

if(Math.abs(speeds.omegaRadiansPerSecond) > 0.0 || pXY <= 0) desiredHeading = pose.getRotation().getDegrees();

else if(xy > 0) speeds.omegaRadiansPerSecond += driftCorrectionPID.calculate(pose.getRotation().getDegrees(), desiredHeading);

pXY = xy;


This seems to have fixed our drift problems and work pretty reliably, the PID could probably use a bit more tuning but it works pretty good for what it is