PathPlanner is going the wrong direction

Hello! I’ve been working on my team’s PathPlanner autonomous and am facing some issues.
When given a path that looks like this:
expectedpath

the robot executes a path that is more like this:
image

I’m unsure of how to proceed at this point and would really appreciate any help I can get. Our most recent code is here.

we encountered this issue today and our problem was our gyro rotation made the x axis different than what we thought it was

2 Likes

Make sure that your:

  • PID Values are correct
  • Your Gyro is fully seated and connected to the rio; and you reset the gyro to 0 on robot init

Your code seems to be fine. Can you show a video of what the robot does when you run the path? That may give more hints to if this is a programming or hardware issue.

As @nevadexehs pointed out, you should take a look at the Coordinate System documentation. Looking at your code, there are several indications that you’re not using the coordinate system properly. In short, PathPlanner is telling you to drive forward along the X axis, but your code drives sideways along the Y axis.

You’re not negating the joystick inputs:

double xSpeed = joy.getLeftY();
double ySpeed = joy.getLeftX();
double rotateSpeed = joy.getRawAxis(4);

You’re not negating your NavX gyro heading:

public double getHeading() {
  return Math.IEEEremainder(gyro.getAngle(), 360);
}

You are negating and swapping the X and Y speeds.

public void drive(ChassisSpeeds speeds) {

  ChassisSpeeds targetSpeeds = new ChassisSpeeds(-speeds.vyMetersPerSecond, -speeds.vxMetersPerSecond, speeds.omegaRadiansPerSecond);
  ...
2 Likes

@VZamora if this is the case, ive designed the robot in such a way that the nav-x should be facing the right way. I dont know whether it is or not on the test chassis.

Thanks, all, for the responses! I haven’t had the opportunity to test or make changes, but I appreciate the suggestions for when I can. :slight_smile:

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