PathPlanner acting as though odometry is inverted

We’ve been working on getting PathPlanner going on our swerve, but we’ve run into a weird issue where PathPlanner seems to be acting as though it’s whole coordinate system is inverted as compared to the odometry.
We first just tried a simple path that drove the swerve forward one meter, but that had a weird issue where it drive backwards instead of forwards, and would all the sudden do a 360. On a hunch that PathPlanner was trying to correct for the swerve turning slightly as it drives, and getting an inverted reading from the gyro, and then trying to turn the wrong way because of that, we tried un-inverting the gyro (we use a NavX2, which reads clockwise positive), and that did seem to fix it from doing the 360, but it still went backwards and the odometry tracking was wrong in teleop. So then we went back to inverting the reading from the gyro, and just inverted it again when PathPlanner grabs the current position from the odometry, and that seemed to work fine, other than the swerve still driving backwards.
We then tried a slightly more complex path that would drive the robot forwards a bit, and then to the right, while rotating to the counterclockwise. Instead, the robot went backwards a bit, rotated to the clockwise, started going to the left, and then started accelerating very rapidly to the right, until it was disabled to stop it from bashing into a wall. The telemetry page on the PathPlanner app said the robot was following the path until the end when it started going the wrong way. I didn’t get video or screenshots of this at the time, I can try to later today, but here’s some from the PathPlanner UI that I just made:

What we wanted:
Screenshot from 2024-01-24 11-14-23

What it seemed like it wanted to do:
Screenshot from 2024-01-24 11-14-02

What it actually did:
Screencast from 01-24-2024 11_26_44 AM

Our github is here
Any help would be appreciated!

You’re actually driving the robot incorrectly in teleop. You motors must be inverted incorrectly as well

        swerveDrive.setDefaultCommand(
                swerveDrive.run(() -> swerveDrive.teleopDriveSwerve(
                        driver::getLeftY,
                        driver::getLeftX,
                        driver::getRightX,
                        () -> driver.leftBumper().getAsBoolean()
                ))
        );

This is incorrect, the joystick axis values need to be inverted. I’m working on a documentation page here with details, this is a common problem. Pay special attention to the Using Joystick and controller input to drive a robot section.

NavX values return from getYaw() do need to be inverted.
You should confirm these things:

  • Positive output on your drive motors is forward. You probably have them inverted incorrectly.
  • CCW rotation of the steering is a positive encoder value.
  • Positive output on the steer motors is CCW rotation.
  • Rotating the robot CCW is positive yaw.
2 Likes

Yes this was exactly it, we fixed this and it worked perfectly afterwards. Thanks for the tip! Although the NavX does read CW+, so you do have to invert it, maybe you meant that we don’t need to invert it again for PathPlanner?

Correct, I meant the NavX needs to be inverted once to get from CW+ to CCW+. You don’t need to invert it again for PathPlanner.

I’m glad you got it working!

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.