We’re encountering a bizarre issue while using PathPlanner for our autonomous routines, where the robot follows a different path about once every 3 power cycles of the robot, despite no code or mechanical changes between those power cycles. However, re-running the auto routine without power cycling will consistently follow the exact same path (even if it’s not the path we’re asking for). Our robot is quite precise, but hardly accurate!
We believe this issue stems from incorrect odometry, as some simple straight-line paths have revealed that the distances measured by each individual drive encoder are not always the same as the distance calculated from our WPILib SwerveDriveOdometry object. For example, in this video (where the robot was told to drive its front bumper to the end of the measuring tape), the individual drive encoders correctly measure that the robot has overshot its target, while our Pose2d object claims we hit our target pose within a few centimeters;
Furthermore, when we turn off the closed loop trajectory following (by setting the PID gains given to PathPlannerLib’s SwerveAutoBuilder to all be 0), we always follow the same path no matter how many times we power cycle, and the path also gets us to the correct end pose (within reason). This leads us to believe that when the robot misbehaves, it’s because it’s trying to correct for an error that doesn’t exist.
However, there are also some power cycles where the drive encoders and Pose2d object both agree on the distance traveled, and will continue to agree until we roll the dice on the next power cycle. And just to reiterate, we are making no code or mechanical changes between power cycles.
We have tried:
- Swapping out our gyro, first to a different navX-MXP (1st gen), and then upgrading to a navX2-Micro.
- Waiting a full minute after connecting to the robot before running auto, to make sure everything has had enough time to initialize
- Verifying that the conversion factor between motor rotations and distance traveled by the drive wheels (in meters) is correct and is constant.