Using Gyro to maintain heading to avoid drift

Hi all,

Recently I have been noticing rotational drift in our swerve drive and I want to use the gyro to account for this drift. I want the robot to lock onto the gyro reading and maintain this heading if I am not sending any joystick input to rotate the bot(change the heading).

In case this information is needed:
Gyro- Navx
Swerve- SDS

Please let me know if there is already a thread I haven’t found that answers my question.
Thank you!

1 Like

We did this for our kiwi drive in 2015. When moving the turning stick you just do output control, when not pressing the joystick and your rotational velocity is low enough enable the PID control to lock to the heading you were at once you stopped turning.

1 Like

Update to the pigeon 2 if you can. It’s a game changer!


See this thread for one way a team accomplished this. How you do it could be much different depending on your code base. The logic @Kaleb_Dodd describes above is a good guide for what to code. If the joystick is commanding a rotation rate, use it. Otherwise, let the rotation PID generate a rotation rate needed to maintain the rotational attitude of the robot and use that.

1 Like

We had drift issues early in the 2021 build season and the drift was a result of our Pigeon 1 not being able to keep up with the rotation of our bot. We switched to the 2 and life got so much better.

1 Like

Haha, maybe next season

Thank you for this thread. It worked for me.