How to deal with a 180 degree rotation gap

I work on driving and use the 9DOF sensor (accelerometer, magnetometer and gyroscope). For the yaw angle, I have a tear problem in pi rad. (180 deg.). I control the car with a PID controller, and when the car turns more than 180 degrees, the sign suddenly changes (from 180 to -180), and this makes the controller act strange. The same problem will occur when it becomes greater than -180 degrees.

As a method, I use the directional cosine matrix to calculate Euler angles. (Recommended method for spark sensor.)

My question is which approach should I use? How to deal with this gap when using a PID controller to control yaw angle.

+5
source share
2 answers

I had the same problem and I am doing the following:

#define MOD(a) ((a > 180.0) ? (a - 360.0) : ((a < -180.0) ? (a + 360.0) : a))

The difference of 2 angles can simply be returned to -180d / + 180d with this formula.

0
source

It's your problem?

After desired angle changes it sign(ie. 180->-180) 
then suddenly control input(ie. P * error) becomes bigger.

For instance.

--------------------------------
|  desired  |  real  |  error  |
|-----------|--------|---------|
|    170    |   160  |   10    |
|   -170    |   160  |  -330   |
--------------------------------

If your problem is the same as I understood, how about this? Before you go, please note that it is assumed that all angle values ​​are in the range from [-pi, pi].

error = desired - real;
if(error > 180)
   error = error - 360;
else if(error < -180)
   error = error + 360;
else
   error = error;//do nothing

This method always selects the direction, so that the control input becomes smaller. (You know that there are two options for referral)

0
source

All Articles