30 #ifndef AHRS_FLOAT_UTILS_H
31 #define AHRS_FLOAT_UTILS_H
44 const float phi = atan2f(-accelf.
y, -accelf.
z);
45 const float cphi = cosf(phi);
46 const float theta = atan2f(cphi * accelf.
x, -accelf.
z);
52 const float sphi = sinf(phi);
53 const float ctheta = cosf(theta);
54 const float stheta = sinf(theta);
55 const float mn = ctheta * magf.
x + sphi * stheta * magf.
y + cphi * stheta * magf.
z;
56 const float me = 0. * magf.
x + cphi * magf.
y - sphi * magf.
z;
57 float psi = -atan2f(me, mn) + atan2(AHRS_H_Y, AHRS_H_X);
58 if (psi > M_PI) { psi -= 2.*M_PI; }
if (psi < -M_PI) { psi += 2.*M_PI; }
72 if (ABS(acc_normalized.
z - 1.0) < 5 * FLT_MIN) {
81 q->
qx = - acc_normalized.
y;
82 q->
qy = acc_normalized.
x;
84 q->
qi = 1.0 - acc_normalized.
z;
112 float dot = mag_ltp.
x * AHRS_H_X + mag_ltp.
y * AHRS_H_Y;
119 if (ABS(norm2 + dot) < 5 * FLT_MIN) {
125 q_m.
qz = mag_ltp.
x * AHRS_H_Y - mag_ltp.
y * AHRS_H_X;
126 q_m.
qi = norm2 + dot;
#define EULERS_ASSIGN(_e, _phi, _theta, _psi)
void float_rmat_transp_vmult(struct FloatVect3 *vb, struct FloatRMat *m_b2a, struct FloatVect3 *va)
rotate 3D vector by transposed rotation matrix.
Paparazzi floating point algebra.
void float_rmat_of_quat(struct FloatRMat *rm, struct FloatQuat *q)
#define QUAT_ASSIGN(_q, _i, _x, _y, _z)
static void ahrs_float_get_quat_from_accel_mag(struct FloatQuat *q, struct Int32Vect3 *accel, struct Int32Vect3 *mag)
static void float_quat_normalize(struct FloatQuat *q)
#define ACCELS_FLOAT_OF_BFP(_ef, _ei)
static void ahrs_float_get_quat_from_accel(struct FloatQuat *q, struct Int32Vect3 *accel)
Compute a quaternion representing roll and pitch from an accelerometer measurement.
void float_quat_comp_norm_shortest(struct FloatQuat *a2c, struct FloatQuat *a2b, struct FloatQuat *b2c)
Composition (multiplication) of two quaternions with normalization.
#define MAGS_FLOAT_OF_BFP(_ef, _ei)
static void ahrs_float_get_euler_from_accel_mag(struct FloatEulers *e, struct Int32Vect3 *accel, struct Int32Vect3 *mag)
#define FLOAT_VECT3_NORMALIZE(_v)