How to correct gyro heading mounted off-center


Our swerve drive robot has a slight problem with the NavX Gyro Heading reading. While the robot is rotating and driving fast in Field- Oriented control at the same time, it pulls to the left as the gyroscope is not aligned with the center of the frame.

Mounting the gyroscope in the center resolves the issue on our bare-chassis Robot. However center-align is unfeasable when our planned mechanism is fully mounted on the Robot.

Since it would not be possible for the gyroscope to be mounted perfectly in the center later on, is there any equation or piece of code that will compensate for the fixed offset of the gyroscope?

I am using the original NavX gyroscope with latest firmware and fresh calibration, with a SDS MkIII chassis.


I’m going to restate to make sure I understand the problem. You have the gyro mounted in a flat position, parallel to the floor, but it is not at the robot’s center of rotation. Is that correct?

If that’s the case, there isn’t much you can do, it will drift. You can use the AprilTags on the field to compensate for the drift, using the SwerveDrivePoseEstimator. Then, plug the estimated pose rotation into ChassisSpeeds.fromFieldRelativeSpeeds instead of the gyro reading. That way the gyro can drift, but you’re drive uses the compensated heading.

Thank you for replying. Yes, you were correct about the problem I was having. I did some more research as well and it doesn’t appear there are many solutions.

I might just need to try my best to move the gyro as close to the center as possible to reduce drift. Maybe the drift won’t be terrible in just 2 minutes?

Some info/perspective from a 2020 thread on the same question: Off centering a gyro? - #8 by juchong

1 Like