Skip to content

Commit 870d772

Browse files
Manage private state efficiently
1 parent 151a9b1 commit 870d772

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/MadgwickAHRS.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@
3333
//---------------------------------------------------------------------------------------------------
3434
// AHRS algorithm update
3535

36+
Madgwick::Madgwick() {
37+
beta = betaDef;
38+
q0 = 1.0f;
39+
q1 = 0.0f;
40+
q2 = 0.0f;
41+
q3 = 0.0f;
42+
}
43+
3644
void Madgwick::update(float gx, float gy, float gz, float ax, float ay, float az, float mx, float my, float mz) {
3745
float recipNorm;
3846
float s0, s1, s2, s3;

src/MadgwickAHRS.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@
2424
// Variable declaration
2525
class Madgwick{
2626
private:
27-
float invSqrt(float x);
28-
volatile float beta = betaDef; // algorithm gain
29-
volatile float q0 = 1.0f;
30-
volatile float q1 = 0.0f;
31-
volatile float q2 = 0.0f;
32-
volatile float q3 = 0.0f; // quaternion of sensor frame relative to auxiliary frame
27+
static float invSqrt(float x);
28+
float beta; // algorithm gain
29+
float q0;
30+
float q1;
31+
float q2;
32+
float q3; // quaternion of sensor frame relative to auxiliary frame
3333

3434
//---------------------------------------------------------------------------------------------------
3535
// Function declarations
3636
public:
37-
Madgwick(void){};
37+
Madgwick(void);
3838
void update(float gx, float gy, float gz, float ax, float ay, float az, float mx, float my, float mz);
3939
void updateIMU(float gx, float gy, float gz, float ax, float ay, float az);
4040
float getPitch(){return atan2(2 * q2 * q3 - 2 * q0 * q1, 2 * q0 * q0 + 2 * q3 * q3 - 1);};

0 commit comments

Comments
 (0)