Skip to content

Commit 67b901f

Browse files
committed
fix sa
1 parent 6762a08 commit 67b901f

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

components/filters/include/madgwick_filter.hpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,16 @@ class MadgwickFilter {
3737
/// fallback to using only accelerometer and gyroscope values
3838
void update(float dt, float ax, float ay, float az, float gx, float gy, float gz, float mx,
3939
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-
4740
// Use IMU algorithm if magnetometer measurement invalid (avoids NaN in magnetometer
4841
// normalisation)
4942
if ((mx == 0.0f) && (my == 0.0f) && (mz == 0.0f)) {
5043
update(dt, ax, ay, az, gx, gy, gz);
5144
return;
5245
}
5346

47+
float recipNorm;
48+
float qDot1, qDot2, qDot3, qDot4;
49+
5450
// Rate of change of quaternion from gyroscope
5551
qDot1 = 0.5f * (-q1 * gx - q2 * gy - q3 * gz);
5652
qDot2 = 0.5f * (q0 * gx + q2 * gz - q3 * gy);
@@ -60,6 +56,10 @@ class MadgwickFilter {
6056
// Compute feedback only if accelerometer measurement valid (avoids NaN in accelerometer
6157
// normalisation)
6258
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;
6363

6464
// Normalise accelerometer measurement
6565
recipNorm = fast_inv_sqrt(ax * ax + ay * ay + az * az);
@@ -164,9 +164,7 @@ class MadgwickFilter {
164164
/// @note Gyroscope values should be in rad/s
165165
void update(float dt, float ax, float ay, float az, float gx, float gy, float gz) {
166166
float recipNorm;
167-
float s0, s1, s2, s3;
168167
float qDot1, qDot2, qDot3, qDot4;
169-
float _2q0, _2q1, _2q2, _2q3, _4q0, _4q1, _4q2, _8q1, _8q2, q0q0, q1q1, q2q2, q3q3;
170168

171169
// Rate of change of quaternion from gyroscope
172170
qDot1 = 0.5f * (-q1 * gx - q2 * gy - q3 * gz);
@@ -177,6 +175,8 @@ class MadgwickFilter {
177175
// Compute feedback only if accelerometer measurement valid (avoids NaN in accelerometer
178176
// normalisation)
179177
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;
180180

181181
// Normalise accelerometer measurement
182182
recipNorm = fast_inv_sqrt(ax * ax + ay * ay + az * az);

0 commit comments

Comments
 (0)