@@ -37,20 +37,16 @@ class MadgwickFilter {
37
37
// / fallback to using only accelerometer and gyroscope values
38
38
void update (float dt, float ax, float ay, float az, float gx, float gy, float gz, float mx,
39
39
float my, float mz) {
40
- float recipNorm;
41
- float s0, s1, s2, s3;
42
- float qDot1, qDot2, qDot3, qDot4;
43
- float hx, hy;
44
- float _2q0mx, _2q0my, _2q0mz, _2q1mx, _2bx, _2bz, _4bx, _4bz, _2q0, _2q1, _2q2, _2q3, _2q0q2,
45
- _2q2q3, q0q0, q0q1, q0q2, q0q3, q1q1, q1q2, q1q3, q2q2, q2q3, q3q3;
46
-
47
40
// Use IMU algorithm if magnetometer measurement invalid (avoids NaN in magnetometer
48
41
// normalisation)
49
42
if ((mx == 0 .0f ) && (my == 0 .0f ) && (mz == 0 .0f )) {
50
43
update (dt, ax, ay, az, gx, gy, gz);
51
44
return ;
52
45
}
53
46
47
+ float recipNorm;
48
+ float qDot1, qDot2, qDot3, qDot4;
49
+
54
50
// Rate of change of quaternion from gyroscope
55
51
qDot1 = 0 .5f * (-q1 * gx - q2 * gy - q3 * gz);
56
52
qDot2 = 0 .5f * (q0 * gx + q2 * gz - q3 * gy);
@@ -60,6 +56,10 @@ class MadgwickFilter {
60
56
// Compute feedback only if accelerometer measurement valid (avoids NaN in accelerometer
61
57
// normalisation)
62
58
if (!((ax == 0 .0f ) && (ay == 0 .0f ) && (az == 0 .0f ))) {
59
+ float s0, s1, s2, s3;
60
+ float hx, hy;
61
+ float _2q0mx, _2q0my, _2q0mz, _2q1mx, _2bx, _2bz, _4bx, _4bz, _2q0, _2q1, _2q2, _2q3, _2q0q2,
62
+ _2q2q3, q0q0, q0q1, q0q2, q0q3, q1q1, q1q2, q1q3, q2q2, q2q3, q3q3;
63
63
64
64
// Normalise accelerometer measurement
65
65
recipNorm = fast_inv_sqrt (ax * ax + ay * ay + az * az);
@@ -164,9 +164,7 @@ class MadgwickFilter {
164
164
// / @note Gyroscope values should be in rad/s
165
165
void update (float dt, float ax, float ay, float az, float gx, float gy, float gz) {
166
166
float recipNorm;
167
- float s0, s1, s2, s3;
168
167
float qDot1, qDot2, qDot3, qDot4;
169
- float _2q0, _2q1, _2q2, _2q3, _4q0, _4q1, _4q2, _8q1, _8q2, q0q0, q1q1, q2q2, q3q3;
170
168
171
169
// Rate of change of quaternion from gyroscope
172
170
qDot1 = 0 .5f * (-q1 * gx - q2 * gy - q3 * gz);
@@ -177,6 +175,8 @@ class MadgwickFilter {
177
175
// Compute feedback only if accelerometer measurement valid (avoids NaN in accelerometer
178
176
// normalisation)
179
177
if (!((ax == 0 .0f ) && (ay == 0 .0f ) && (az == 0 .0f ))) {
178
+ float s0, s1, s2, s3;
179
+ float _2q0, _2q1, _2q2, _2q3, _4q0, _4q1, _4q2, _8q1, _8q2, q0q0, q1q1, q2q2, q3q3;
180
180
181
181
// Normalise accelerometer measurement
182
182
recipNorm = fast_inv_sqrt (ax * ax + ay * ay + az * az);
0 commit comments