I'm working on a vehicle control and using a 9DOF sensor (accelerometer, magnetometer and gyroscope). For the yaw angle, I have a discontinuity problem at pi rad. (180 deg.). I'm controlling the vehicle with a PID controller and when the vehicle turns more than 180 deg, the sign suddenly changes (from 180 to -180) and this makes the controller act weird. The same problem will occur when it turns more than -180 deg too.
As the method, I'm using a direction cosine matrix to calculate euler angles. (recommended method for the sparkfun sensor.)
My question is what kind of approach should I use? How to deal with this discontinuity in the case of using a PID controller to control yaw angle.
Is this your problem?
For example.
If your problem is same as I understood, how about this? Before we go, note that It is assumed that every angle values are in range of [-pi,pi].
This method always chooses a direction such that control input becomes smaller.(You know there are two choices for direction)