Run a pathplanner route with the robot in reverse

We are trying to use PathPlanner for our auto routes, but we’re running into a problem - not sure if this group has run into this before. Basically, it seems to think our robot is backwards. When we drive the robot via teleop, and we push forward on the stick, the front of our robot drives forward as we’d expect - left, right, front, and back all work as expected. However, in an auto written with PathPlanner, we want to start with the robot in front of a scoring position, deposit a cube, then go back to get a second cube. If we run that auto, the robot drives forward into the scoring platform instead of away from it - almost as if PathPlanner thinks our robot is backwards. Is there a way to tell PathPlanner to flip it (if that’s even the right solution here)? We’re using Team364’s swerve code as our base.

Side note - If we change the starting pose rotation to 180 degrees, then it travels in the correct direction, but we haven’t done any more complicated paths than this yet.

Have you done a “robot-oriented” driving test in teleop? If not, this may not give you a valid idea of whether the front of your robot is actually correct.

Is there anything special we need to do to do that? Driving the bot with the joystick is working as expected.

Which way are you starting the robot in the real world?

If it’s facing towards the grid then you need to set your starting pose to 180.

As a diagnostic step, I’d try sending the robot odometry to your dashboard to ensure that your Pose2d forward direction corresponds with the front of your robot.

2 Likes

When we drive with the joystick, the intake is at the front, which is what we want. When we start auto, the intake is pointed at the scoring grid, and we want it to go backwards from the starting point onto the field to pick up another cube (it will need to rotate too). However, when we start the path I posted, the robot drives forward into the scoring grid, not away from it.

I had to start odometry pose 180 degrees.

  // Odometry class for tracking robot pose
  SwerveDriveOdometry m_odometry = new SwerveDriveOdometry(
      DriveConstants.kDriveKinematics,
      Rotation2d.fromDegrees(m_gyro.getAngle()),
      new SwerveModulePosition[] {
          m_frontLeft.getPosition(),
          m_frontRight.getPosition(),
          m_rearLeft.getPosition(),
          m_rearRight.getPosition()
      },
      new Pose2d(new Translation2d(),new Rotation2d(Units.degreesToRadians(180)))
  );

If forward for your robot is intake side, and your robot starts with the intake pointed towards the grid, then your initial pose is 180 deg. Making that 180 deg is exactly correct.

1 Like

One thing to realize is that joystick forward is Y axis negative. So you can have the case where joystick driving is reversed from autonomous driving if you don’t take care. Thus why people are suggesting more sophisticated tests.

A more robust solution to manually assigning the start pose to have a heading of 180 degrees is to use PathPlanner’s getInitialHolonomicPose() API which can update your odometry to reference the path’s starting pose.

2 Likes

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