Holonomic Controller rotating long way around 180

We are having an issue where the Holonomic Controller won’t pass 180 to -180 or when the robot goes past 180 it tries to correct all the way around rather than go backwards. Is this the intended behavior? Anything I might be doing wrong?

1 Like

When you create your ProfiledPIDController, are you calling enableContinuousInput?


no. Thanks!


This still doesn’t seem to fix it. It fixed the issue with going the long way around but as soon as we cross the 180 point, the robot starts rotating at full speed and slows down as we approach the 180 point again. It then crosses and takes off again. We are using this in combination with PathPlanner 2.0 currently.

It would help a lot if we could see your code.

1 Like

We had this issue as well, here’s a list of things we went through:

  • Making sure the profiled controller was continuous (already mentioned)
  • Making sure that a p of 0 did nothing to the heading
  • Checking that odometry was CCW-positive

After this, and a long debugging process of using different values, we ended up just using a negative p-value for the rotation controller, and that fixed it so we called it a day. Still have no idea why.

You also have to make sure positive control inputs make the robot move the correct direction. Positive feedback (negative P gain) is typically unstable.


If you are using Rotation2D objects some of their functions will keep the angle between -180 and 180. We replaced .plus and .minus functions to solve it.

Replaced what exactly? Is this a WPILib bug?

I`m not sure if this is a bug or intended. the .plus and .minus function do the calculation on the sin and cos of the angle so it doesn’t keep count of the number of rotations. We did something like this instead:
rot3 = Rotation2D.fromDegrees(rot1.getDegrees() - rot2.getDegrees);

That’s intended since angles should wrap. If your angle difference is over 360 degrees, you don’t want the robot to spin2win to get to the desired angle.

More specifically, you want minus() to always give you the shortest distance to the desired angle.

That makes sense, we didn’t know about the continuous input so we had problems with our PID controller

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