Skip to content

YawPitchRaw algorithm mistake #222

Open
@yonoodle

Description

@yonoodle

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 -9090 to non degenerate -180180
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;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions