Dealing with Angles
A very common use case for PID controllers in FTC is turning your robot to a desired heading. However, a few modifications are necessary.
// This function normalizes the angle so it returns a value between -180° and 180° instead of 0° to 360°.
public double angleWrap(double radians) {
while (radians > Math.PI) {
radians -= 2 * Math.PI;
}
while (radians < -Math.PI) {
radians += 2 * Math.PI;
}
// keep in mind that the result is in radians
return radians;
}Last updated
Was this helpful?
