i2cdevlib icon indicating copy to clipboard operation
i2cdevlib copied to clipboard

YawPitchRaw algorithm mistake

Open yonoodle opened this issue 8 years ago • 7 comments

Thank you for this WONDERFUL lib.

but the "roll" algorithm in the dmpGetYawPitchRoll should be data[2] = atan2(gravity -> y , gravity -> z);

(at least one of the pitch or roll should be as simple as that, and only one uses sqrt) see complete derivation https://cache.freescale.com/files/sensors/doc/app_note/AN3461.pdf

about extending pitch and roll from degenerate -90~90 to non degenerate -180~180 i simply used the code below.

uint8_t MPU6050::dmpGetYawPitchRoll(float *data, Quaternion *q, VectorFloat *gravity) {

// yaw: (about Z axis)
data[0] = atan2(2*q -> x*q -> y - 2*q -> w*q -> z, 2*q -> w*q -> w + 2*q -> x*q -> x - 1);

//pitch

data[1] = atan2(gravity -> x , sqrt(gravity -> y*gravity -> y + gravity -> z*gravity -> z));
//roll
data[2] = atan2(gravity -> y , gravity -> z);

if(gravity->z<0)
{
    if(data[1]>0)
    {  data[1] = 3.1415926 - data[1] ; }
    else { data[1] = -3.1415926 - data[1] ; }
}

return 0; }

yonoodle avatar Mar 26 '16 02:03 yonoodle

If we had a development branch I could check-in quick fixes like this. The community could then take part in the testing. What do you think @jrowberg? You will still have the final say on what gets merged intomaster.

eadf avatar Apr 01 '16 12:04 eadf

@eadf: I'd be perfectly happy with that approach. Back when I first created the repository, I knew very little about Git and best practices, so doing that at the time didn't even occur to me.

jrowberg avatar Apr 01 '16 13:04 jrowberg

I've just pushed an updated MPU6050::dmpGetYawPitchRoll() implementation to the 'develop' branch. The new roll value (thanks @yonoodle) can detect if the device is upside down. The old roll could not.

You can compare old and new dmpGetYawPitchRoll() with this (temporary) #define:

#define USE_OLD_DMPGETYAWPITCHROLL
#include "MPU6050_6Axis_MotionApps20.h"

eadf avatar Apr 16 '16 16:04 eadf

#216 seems to be the better choice. I think the develop branch can be archived now, as it is badly out of date.

eadf avatar Sep 23 '21 20:09 eadf

I think the develop branch can be archived now, as it is badly out of date.

I don't see a way to truly archive a branch, only delete. Is there anything necessary to keep? Should I tag the develop HEAD and then just delete the branch? (Or would that delete the tag and everything with it?)

jrowberg avatar Sep 23 '21 20:09 jrowberg

Hm, I don't know what the best solution is. Maybe just leave it for a few days so we can evaluate the content

eadf avatar Sep 23 '21 20:09 eadf

Well, this solution is in master MPU6050_6Axis_MotionApps_V6_12.h now. (Can't find #216) Close?

eadf avatar Sep 26 '21 12:09 eadf