29 #define INT32_SQRT_MAX_ITER 40
77 m_a2c->
m[0] = (m_b2c->
m[0] * m_a2b->
m[0] + m_b2c->
m[1] * m_a2b->
m[3] + m_b2c->
m[2] * m_a2b->
m[6]) >>
INT32_TRIG_FRAC;
78 m_a2c->
m[1] = (m_b2c->
m[0] * m_a2b->
m[1] + m_b2c->
m[1] * m_a2b->
m[4] + m_b2c->
m[2] * m_a2b->
m[7]) >>
INT32_TRIG_FRAC;
79 m_a2c->
m[2] = (m_b2c->
m[0] * m_a2b->
m[2] + m_b2c->
m[1] * m_a2b->
m[5] + m_b2c->
m[2] * m_a2b->
m[8]) >>
INT32_TRIG_FRAC;
80 m_a2c->
m[3] = (m_b2c->
m[3] * m_a2b->
m[0] + m_b2c->
m[4] * m_a2b->
m[3] + m_b2c->
m[5] * m_a2b->
m[6]) >>
INT32_TRIG_FRAC;
81 m_a2c->
m[4] = (m_b2c->
m[3] * m_a2b->
m[1] + m_b2c->
m[4] * m_a2b->
m[4] + m_b2c->
m[5] * m_a2b->
m[7]) >>
INT32_TRIG_FRAC;
82 m_a2c->
m[5] = (m_b2c->
m[3] * m_a2b->
m[2] + m_b2c->
m[4] * m_a2b->
m[5] + m_b2c->
m[5] * m_a2b->
m[8]) >>
INT32_TRIG_FRAC;
83 m_a2c->
m[6] = (m_b2c->
m[6] * m_a2b->
m[0] + m_b2c->
m[7] * m_a2b->
m[3] + m_b2c->
m[8] * m_a2b->
m[6]) >>
INT32_TRIG_FRAC;
84 m_a2c->
m[7] = (m_b2c->
m[6] * m_a2b->
m[1] + m_b2c->
m[7] * m_a2b->
m[4] + m_b2c->
m[8] * m_a2b->
m[7]) >>
INT32_TRIG_FRAC;
85 m_a2c->
m[8] = (m_b2c->
m[6] * m_a2b->
m[2] + m_b2c->
m[7] * m_a2b->
m[5] + m_b2c->
m[8] * m_a2b->
m[8]) >>
INT32_TRIG_FRAC;
93 m_a2b->
m[0] = (m_b2c->
m[0] * m_a2c->
m[0] + m_b2c->
m[3] * m_a2c->
m[3] + m_b2c->
m[6] * m_a2c->
m[6]) >>
INT32_TRIG_FRAC;
94 m_a2b->
m[1] = (m_b2c->
m[0] * m_a2c->
m[1] + m_b2c->
m[3] * m_a2c->
m[4] + m_b2c->
m[6] * m_a2c->
m[7]) >>
INT32_TRIG_FRAC;
95 m_a2b->
m[2] = (m_b2c->
m[0] * m_a2c->
m[2] + m_b2c->
m[3] * m_a2c->
m[5] + m_b2c->
m[6] * m_a2c->
m[8]) >>
INT32_TRIG_FRAC;
96 m_a2b->
m[3] = (m_b2c->
m[1] * m_a2c->
m[0] + m_b2c->
m[4] * m_a2c->
m[3] + m_b2c->
m[7] * m_a2c->
m[6]) >>
INT32_TRIG_FRAC;
97 m_a2b->
m[4] = (m_b2c->
m[1] * m_a2c->
m[1] + m_b2c->
m[4] * m_a2c->
m[4] + m_b2c->
m[7] * m_a2c->
m[7]) >>
INT32_TRIG_FRAC;
98 m_a2b->
m[5] = (m_b2c->
m[1] * m_a2c->
m[2] + m_b2c->
m[4] * m_a2c->
m[5] + m_b2c->
m[7] * m_a2c->
m[8]) >>
INT32_TRIG_FRAC;
99 m_a2b->
m[6] = (m_b2c->
m[2] * m_a2c->
m[0] + m_b2c->
m[5] * m_a2c->
m[3] + m_b2c->
m[8] * m_a2c->
m[6]) >>
INT32_TRIG_FRAC;
100 m_a2b->
m[7] = (m_b2c->
m[2] * m_a2c->
m[1] + m_b2c->
m[5] * m_a2c->
m[4] + m_b2c->
m[8] * m_a2c->
m[7]) >>
INT32_TRIG_FRAC;
101 m_a2b->
m[8] = (m_b2c->
m[2] * m_a2c->
m[2] + m_b2c->
m[5] * m_a2c->
m[5] + m_b2c->
m[8] * m_a2c->
m[8]) >>
INT32_TRIG_FRAC;
162 rm->
m[0] += _2qi2_m1;
163 rm->
m[3] = rm->
m[1] - _2qiqz;
164 rm->
m[6] = rm->
m[2] + _2qiqy;
165 rm->
m[7] = rm->
m[5] - _2qiqx;
166 rm->
m[4] += _2qi2_m1;
170 rm->
m[8] += _2qi2_m1;
211 RMAT_ELMT(*rm, 1, 0) = sphi_stheta_cpsi - cphi_spsi;
212 RMAT_ELMT(*rm, 1, 1) = sphi_stheta_spsi + cphi_cpsi;
214 RMAT_ELMT(*rm, 2, 0) = cphi_stheta_cpsi + sphi_spsi;
215 RMAT_ELMT(*rm, 2, 1) = cphi_stheta_spsi - sphi_cpsi;
251 RMAT_ELMT(*rm, 0, 0) = ctheta_cpsi - sphi_stheta_spsi;
252 RMAT_ELMT(*rm, 0, 1) = ctheta_spsi + sphi_stheta_cpsi;
257 RMAT_ELMT(*rm, 2, 0) = stheta_cpsi + sphi_ctheta_spsi;
258 RMAT_ELMT(*rm, 2, 1) = stheta_spsi - sphi_ctheta_cpsi;
331 hr->
qi += - ((int64_t) omega->
p) * q->
qx - ((int64_t) omega->
q) * q->
qy - ((int64_t) omega->
r) * q->
qz;
332 hr->
qx += ((int64_t) omega->
p) * q->
qi + ((int64_t) omega->
r) * q->
qy - ((int64_t) omega->
q) * q->
qz;
333 hr->
qy += ((int64_t) omega->
q) * q->
qi - ((int64_t) omega->
r) * q->
qx + ((int64_t) omega->
p) * q->
qz;
334 hr->
qz += ((int64_t) omega->
r) * q->
qi + ((int64_t) omega->
q) * q->
qx - ((int64_t) omega->
p) * q->
qy;
365 v_out->
x = (_2qi2_m1 * v_in->
x + _2qx2 * v_in->
x + m01 * v_in->
y + m02 * v_in->
z) >>
INT32_QUAT_FRAC;
366 v_out->
y = (_2qi2_m1 * v_in->
y + m01 * v_in->
x - 2 * _2qiqz * v_in->
x + _2qy2 * v_in->
y + m12 * v_in->
z) >>
368 v_out->
z = (_2qi2_m1 * v_in->
z + m02 * v_in->
x + 2 * _2qiqy * v_in->
x + m12 * v_in->
y - 2 * _2qiqx * v_in->
y + _2qz2 *
513 BoundAbs(dcm02, 1.0);
515 const float phi = atan2f(dcm12, dcm22);
516 const float theta = -asinf(dcm02);
517 const float psi = atan2f(dcm01, dcm00);
559 BoundAbs(dcm02, 1.0);
561 const float phi = atan2f(dcm12, dcm22);
562 const float theta = -asinf(dcm02);
563 const float psi = atan2f(dcm01, dcm00);
610 ed->
phi = r->
p + (
int32_t)((sphi_stheta * (int64_t)r->
q) / ctheta) + (
int32_t)((cphi_stheta * (int64_t)r->
r) / ctheta);
612 ed->
psi = (
int32_t)(((int64_t)sphi * (int64_t)r->
q) / ctheta) + (
int32_t)(((int64_t)cphi * (int64_t)r->
r) / ctheta);
#define RMAT_ELMT(_rm, _row, _col)
int32_t p
in rad/s with INT32_RATE_FRAC
int32_t r
in rad/s with INT32_RATE_FRAC
int32_t phi
in rad with INT32_ANGLE_FRAC
int32_t q
in rad/s with INT32_RATE_FRAC
int32_t psi
in rad with INT32_ANGLE_FRAC
int32_t theta
in rad with INT32_ANGLE_FRAC
static void int32_quat_normalize(struct Int32Quat *q)
normalize a quaternion inplace
void int32_eulers_of_quat(struct Int32Eulers *e, struct Int32Quat *q)
void int32_quat_comp(struct Int32Quat *a2c, struct Int32Quat *a2b, struct Int32Quat *b2c)
Composition (multiplication) of two quaternions.
void int32_quat_of_axis_angle(struct Int32Quat *q, struct Int32Vect3 *uv, int32_t angle)
Quaternion from unit vector and angle.
void int32_rmat_ratemult(struct Int32Rates *rb, struct Int32RMat *m_a2b, struct Int32Rates *ra)
rotate anglular rates by rotation matrix.
#define INT_MULT_RSHIFT(_a, _b, _r)
#define QUAT1_BFP_OF_REAL(_qf)
void int32_quat_comp_norm_shortest(struct Int32Quat *a2c, struct Int32Quat *a2b, struct Int32Quat *b2c)
Composition (multiplication) of two quaternions with normalization.
void int32_rmat_of_quat(struct Int32RMat *rm, struct Int32Quat *q)
Convert unit quaternion to rotation matrix.
#define TRIG_FLOAT_OF_BFP(_ti)
#define ANGLE_BFP_OF_REAL(_af)
void int32_quat_of_rmat(struct Int32Quat *q, struct Int32RMat *r)
Quaternion from rotation matrix.
void int32_eulers_dot_321_of_rates(struct Int32Eulers *ed, struct Int32Eulers *e, struct Int32Rates *r)
uint32_t int32_sqrt(uint32_t in)
void int32_quat_inv_comp_norm_shortest(struct Int32Quat *b2c, struct Int32Quat *a2b, struct Int32Quat *a2c)
Composition (multiplication) of two quaternions with normalization.
void int32_quat_comp_inv(struct Int32Quat *a2b, struct Int32Quat *a2c, struct Int32Quat *b2c)
Composition (multiplication) of two quaternions.
void int32_rmat_vmult(struct Int32Vect3 *vb, struct Int32RMat *m_a2b, struct Int32Vect3 *va)
rotate 3D vector by rotation matrix.
void int32_quat_comp_inv_norm_shortest(struct Int32Quat *a2b, struct Int32Quat *a2c, struct Int32Quat *b2c)
Composition (multiplication) of two quaternions with normalization.
uint32_t int32_gcd(uint32_t a, uint32_t b)
void int32_rmat_comp_inv(struct Int32RMat *m_a2b, const struct Int32RMat *m_a2c, const struct Int32RMat *m_b2c)
Composition (multiplication) of two rotation matrices.
static void int32_quat_wrap_shortest(struct Int32Quat *q)
void int32_rmat_transp_ratemult(struct Int32Rates *rb, struct Int32RMat *m_b2a, struct Int32Rates *ra)
rotate anglular rates by transposed rotation matrix.
void int32_rmat_of_eulers_312(struct Int32RMat *rm, struct Int32Eulers *e)
Rotation matrix from 312 Euler angles.
void int32_quat_integrate_fi(struct Int32Quat *q, struct Int64Quat *hr, struct Int32Rates *omega, int freq)
in place quaternion first order integration with constant rotational velocity.
void int32_quat_derivative(struct Int32Quat *qd, const struct Int32Rates *r, struct Int32Quat *q)
Quaternion derivative from rotational velocity.
void int32_quat_vmult(struct Int32Vect3 *v_out, struct Int32Quat *q, struct Int32Vect3 *v_in)
rotate 3D vector by quaternion.
void int32_quat_of_eulers(struct Int32Quat *q, struct Int32Eulers *e)
Quaternion from Euler angles.
void int32_rates_of_eulers_dot_321(struct Int32Rates *r, struct Int32Eulers *e, struct Int32Eulers *ed)
void int32_rmat_transp_vmult(struct Int32Vect3 *vb, struct Int32RMat *m_b2a, struct Int32Vect3 *va)
rotate 3D vector by transposed rotation matrix.
void int32_rmat_comp(struct Int32RMat *m_a2c, const struct Int32RMat *m_a2b, const struct Int32RMat *m_b2c)
Composition (multiplication) of two rotation matrices.
void int32_rmat_of_eulers_321(struct Int32RMat *rm, struct Int32Eulers *e)
Rotation matrix from 321 Euler angles.
#define TRIG_BFP_OF_REAL(_tf)
void int32_quat_inv_comp(struct Int32Quat *b2c, struct Int32Quat *a2b, struct Int32Quat *a2c)
Composition (multiplication) of two quaternions.
#define INT_EULERS_ZERO(_e)
void int32_eulers_of_rmat(struct Int32Eulers *e, struct Int32RMat *rm)
#define INT32_SQRT_MAX_ITER
Paparazzi fixed point algebra.
#define PPRZ_ITRIG_SIN(_s, _a)
#define PPRZ_ITRIG_COS(_c, _a)
int int32_t
Typedef defining 32 bit int type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.