I would like to estimate the yaw angle from accelerometer and gyroscope data. For roll and pitch estimate I've used the following trigonometric equations:

roll  = atan2(Ax,Az)  * RAD_TO_DEG
pitch = atan2(Ay,Az)  * RAD_TO_DEG

and a simpified version of the Kalman Filter to consider also angular rates. The roll and pitch estimates are accurate (accelerometer values need to be filtered in presence of chassis vibrations).

enter image description here

In order to get the Yaw angle I'm using the following equation:

yaw = atan2(Ax,Ay)  * RAD_TO_DEG;

but the it doesn't work. Do you have any advice?


Gyroscopes will only give you the rate of change of the yaw angle, not the absolute yaw angle.

Unless you plan to set the yaw angle initially and have it drift further and further into garbage values (as you integrate the rate of change), you'll need another sensor to provide periodic updates on your actual yaw. This could be a magnetometer (compass), or a GPS, or a pair of GPSes, or some other method of finding your heading, which would provide input to a correction algorithm (e.g. Sebastian Madgwick's filter).

| improve this answer | |
  • $\begingroup$ What about the Madgwick Filter? It can measure the yaw angle from a 6 dof IMU and it does not drift. Don't know how it works... $\endgroup$ – UserK Mar 30 '15 at 8:00
  • $\begingroup$ My understanding is that the Madgwick Filter uses a magnetometer and an accelerometer to prevent drift in the gyroscope measurement. $\endgroup$ – Ian Mar 30 '15 at 12:37
  • $\begingroup$ I've noticed that this filter runs also on a 6 dof (acc + gyro) and produces an estimate of the yaw angle. I'm using an MPU6050 and this library. $\endgroup$ – UserK Mar 30 '15 at 15:17
  • 1
    $\begingroup$ I should have written "magnetometer and/or accelerometer". These sensors don't have inherent drift in them, so they can be fused with the gyro measurements to correct for drift there. $\endgroup$ – Ian Apr 2 '15 at 12:56

Assuming your vehicle is roughly horizontal to the ground, you won't be able get a good estimate of yaw from the accelerometer. Consider the nominal case: when your accelerometer is pointing straight down (Ax=0, Ay=0, Az=g) the reading will never change as you change yaw angle.

Normally, to get yaw angle vehicles use a magnometer (measure earth's magnetic field) or cameras and track the scene.

| improve this answer | |
  • $\begingroup$ Unfortunatly I threw away my magnetometer after having noticed that angular positions were not steady because of the magnetic filed of the motors. There are 4 brushless motors around the shield. That's why I'm trying to estimate roll, pitch and yaw $\endgroup$ – UserK Oct 5 '14 at 23:09
  • $\begingroup$ Yup, that's a common problem. You can get around that to some extent by using very low bandwidth filters. $\endgroup$ – ryan0270 Oct 5 '14 at 23:11
  • $\begingroup$ I should have tried it. I had to filter accelerometer's data to suppress noise which was causing the same problem. Now I changed the circuit, the magnetometer has no place anymore. Is the last formula incorrect? $\endgroup$ – UserK Oct 5 '14 at 23:15
  • $\begingroup$ I think it's correct (not sure though, would have to think about it more) but it is undefined for Ax=0 and Ay=0 and, since you are near hover both Ax and Ay are close to zero so the noise dominates. $\endgroup$ – ryan0270 Oct 5 '14 at 23:58
  • $\begingroup$ I can't even upvote you...not enough rep. I can't use a camera in this application. I think the only solution is a complete Kalman Filter... I need to check this link out $\endgroup$ – UserK Oct 6 '14 at 0:21

yaw can be measured by rate gyro and magnetometer not with accelerometer because accelerometer values depends on gravity component but on rotation in z axis only there is no change in gravity componets

| improve this answer | |
  • 1
    $\begingroup$ How does the 6 dof mpu 6050 estimates the yaw angle then? It has only an accelerometer and a gyroscope and produces a really good yaw angle estimate $\endgroup$ – UserK Mar 30 '15 at 7:56
  • $\begingroup$ I don't really understand this, but from what I can tell you can fuse the accelerometer data with gyroscope data to get much more precise readings because the accelerometer data is meaningful when you rotate the device (gravity no longer looks downward, and you can use that to say "hey, I'm tilted this much"). In contrast if you are working with yaw, rotation about yaw doesn't affect the gravity vector so it isn't useful. $\endgroup$ – Warty Jun 5 '16 at 7:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.