diff --git a/Tools/CPUInfo/CPUInfo.cpp b/Tools/CPUInfo/CPUInfo.cpp index 30c28f76a1..87409d8474 100644 --- a/Tools/CPUInfo/CPUInfo.cpp +++ b/Tools/CPUInfo/CPUInfo.cpp @@ -10,6 +10,7 @@ #include #include #include +#include "EKF_Maths.h" void setup(); void loop(); @@ -24,7 +25,12 @@ static uint32_t sysclk = STM32_SYSCLK; static uint32_t sysclk = 0; #endif +static EKF_Maths ekf; + + + void setup() { + ekf.init(); } static void show_sizes(void) @@ -126,6 +132,7 @@ static void show_timings(void) TIMEIT("sq()",v_out = sq(v_f), 20); TIMEIT("powf(v,2)",v_out = powf(v_f, 2), 20); TIMEIT("powf(v,3.1)",v_out = powf(v_f, 3.1), 20); + TIMEIT("EKF",v_out = ekf.test(), 5); TIMEIT("iadd8", v_out_8 += v_8, 100); TIMEIT("isub8", v_out_8 -= v_8, 100); diff --git a/Tools/CPUInfo/EKF_Maths.cpp b/Tools/CPUInfo/EKF_Maths.cpp new file mode 100644 index 0000000000..a48c6c57d5 --- /dev/null +++ b/Tools/CPUInfo/EKF_Maths.cpp @@ -0,0 +1,121 @@ +#include "EKF_Maths.h" + +/* + code for measuring speed of EKF mag fusion code + */ + +static float RandFloat(void) +{ + return float(get_random16()+1.0) / 0xFFFF; +} + +void EKF_Maths::init(void) +{ + for (uint8_t i=0; i<24; i++) { + P[i][i] = RandFloat(); + } + for (uint8_t i=0; i<28; i++) { + statesArray[i] = RandFloat(); + } + float *m = (float *)&mag_state; + for (uint8_t i=0; i +#include + +typedef float ftype; + +class EKF_Maths { +public: + EKF_Maths() {} + + typedef ftype Vector2[2]; + typedef ftype Vector3[3]; + typedef ftype Vector4[4]; + typedef ftype Vector5[5]; + typedef ftype Vector6[6]; + typedef ftype Vector7[7]; + typedef ftype Vector8[8]; + typedef ftype Vector9[9]; + typedef ftype Vector10[10]; + typedef ftype Vector11[11]; + typedef ftype Vector13[13]; + typedef ftype Vector14[14]; + typedef ftype Vector15[15]; + typedef ftype Vector22[22]; + typedef ftype Vector23[23]; + typedef ftype Vector24[24]; + typedef ftype Vector25[25]; + typedef ftype Vector28[28]; + typedef ftype Matrix3[3][3]; + typedef ftype Matrix24[24][24]; + typedef ftype Matrix34_50[34][50]; + typedef uint32_t Vector_u32_50[50]; + + struct state_elements { + Vector3f angErr; // 0..2 + Vector3f velocity; // 3..5 + Vector3f position; // 6..8 + Vector3f gyro_bias; // 9..11 + Vector3f gyro_scale; // 12..14 + float accel_zbias; // 15 + Vector3f earth_magfield; // 16..18 + Vector3f body_magfield; // 19..21 + Vector2f wind_vel; // 22..23 + Quaternion quat; // 24..27 + }; + + union { + Vector28 statesArray; + struct state_elements stateStruct; + }; + + struct { + ftype q0; + ftype q1; + ftype q2; + ftype q3; + ftype magN; + ftype magE; + ftype magD; + ftype magXbias; + ftype magYbias; + ftype magZbias; + Matrix3f DCM; + Vector3f MagPred; + ftype R_MAG; + Vector9 SH_MAG; + } mag_state; + + Vector3f innovMag; + Vector3f varInnovMag; + + Matrix24 P; + Vector28 Kfusion; + + void init(void); + float test(void); +}; +