1717
1818// Math function wrappers for CMSIS-DSP optimization
1919#if USE_CMSIS_DSP
20- #define VQF_SIN (x ) arm_sin_f32(x)
21- #define VQF_COS (x ) arm_cos_f32(x)
2220static inline vqf_real_t vqf_sqrt (vqf_real_t x )
2321{
2422 float32_t out = 0 ;
@@ -33,8 +31,6 @@ static inline vqf_real_t vqf_atan2(vqf_real_t y, vqf_real_t x) {
3331}
3432#define VQF_ATAN2 (y ,x ) vqf_atan2((y), (x))
3533#else
36- #define VQF_SIN (x ) sinf(x)
37- #define VQF_COS (x ) cosf(x)
3834#define VQF_SQRT (x ) sqrtf(x)
3935#define VQF_ATAN2 (y ,x ) atan2f((y), (x))
4036#endif
@@ -177,8 +173,13 @@ static void quatApplyDelta(vqf_real_t q[4], vqf_real_t delta, vqf_real_t out[4])
177173{
178174 // out = quatMultiply([cos(delta/2), 0, 0, sin(delta/2)], q)
179175 // sin and cos can be replaced by arm_sin_f32 and arm_cos_f32 from CMSIS-DSP
180- vqf_real_t c = VQF_COS (delta /2 );
181- vqf_real_t s = VQF_SIN (delta /2 );
176+ #if USE_CMSIS_DSP
177+ vqf_real_t s , c ;
178+ arm_sin_cos_f32 (delta * (vqf_real_t )(180.0f /M_PIf /2 ), & s , & c );
179+ #else
180+ vqf_real_t c = cosf (delta /2 );
181+ vqf_real_t s = sinf (delta /2 );
182+ #endif
182183 vqf_real_t w = c * q [0 ] - s * q [3 ];
183184 vqf_real_t x = c * q [1 ] - s * q [2 ];
184185 vqf_real_t y = c * q [2 ] + s * q [1 ];
@@ -434,8 +435,14 @@ void updateGyr(vqf_params_t *const params, vqf_state_t *const state, vqf_coeffs_
434435 vqf_real_t angle = gyrNorm * coeffs -> gyrTs ;
435436 if (gyrNorm > EPS ) {
436437 // sin cos can be replaced by arm_sin_f32 and arm_cos_f32 from CMSIS-DSP
437- vqf_real_t c = VQF_COS (angle /2 );
438- vqf_real_t s = VQF_SIN (angle /2 )/gyrNorm ;
438+ #if USE_CMSIS_DSP
439+ vqf_real_t s , c ;
440+ arm_sin_cos_f32 (angle * (vqf_real_t )(180.0f /M_PIf /2 ), & s , & c );
441+ s /= gyrNorm ;
442+ #else
443+ vqf_real_t c = cosf (angle /2 );
444+ vqf_real_t s = sinf (angle /2 )/gyrNorm ;
445+ #endif
439446 vqf_real_t gyrStepQuat [4 ] = {c , s * gyrNoBias [0 ], s * gyrNoBias [1 ], s * gyrNoBias [2 ]};
440447 quatMultiply (state -> gyrQuat , gyrStepQuat , state -> gyrQuat );
441448 normalize (state -> gyrQuat , 4 );
0 commit comments