ButterFlight / butterflight

GNU General Public License v3.0
106 stars 26 forks source link

HELIOSPRING attitude correction (compute quaternion helper products) #119

Closed adrianmiriuta closed 6 years ago

adrianmiriuta commented 6 years ago

HELIOSPRING attitude correction (compute quaternion helper products) fix #116 HEADADJ (hope , cannot test).

orneryd commented 6 years ago

i think it needs to be be like this:

#ifndef USE_GYRO_IMUF9001
    quaternion vError = VECTOR_INITIALIZE;
    quaternion vGyroAverage;
    quaternion vAccAverage;
    gyroGetAverage(&vGyroAverage);
    accGetAverage(&vAccAverage);
    DEBUG_SET(DEBUG_IMU, DEBUG_IMU_VACCMODULUS, lrintf((quaternionModulus(&vAccAverage)/ acc.dev.acc_1G) * 1000));
    if (accIsHealthy(&vAccAverage)) {
         applyAccError(&vAccAverage, &vError);
    }
    applySensorCorrection(&vError);
    imuMahonyAHRSupdate(deltaT * 1e-6f, &vGyroAverage, &vError);
#else
    UNUSED(deltaT);
    UNUSED(applyAccError);
    UNUSED(imuMahonyAHRSupdate);
    qAttitude.w = imufQuat.w;
    qAttitude.x = imufQuat.x;
    qAttitude.y = imufQuat.y;
    qAttitude.z = imufQuat.z;
    applySensorCorrection(&qAttitude);
    quaternionComputeProducts(&qAttitude, &qpAttitude);    
#endif
    imuUpdateEulerAngles();

because the quaternionComputeProducts call is made within the imuMahonyAHRSupdate function when calculating ACC. if we put it before the imuUpdateEulerAngles it would end up getting called twice, no?

orneryd commented 6 years ago

Thank you @adrianmiriuta! I combined this into #118

kidBrazil commented 6 years ago

Included in #118 - Thanks @adrianmiriuta !

adrianmiriuta commented 6 years ago

@orneryd yes this is better !