@@ -29,6 +29,11 @@ class Madgwick{
29
29
float q2;
30
30
float q3; // quaternion of sensor frame relative to auxiliary frame
31
31
float invSampleFreq;
32
+ float roll;
33
+ float pitch;
34
+ float yaw;
35
+ char anglesComputed;
36
+ void computeAngles ();
32
37
33
38
// -------------------------------------------------------------------------------------------
34
39
// Function declarations
@@ -37,9 +42,33 @@ class Madgwick{
37
42
void begin (float sampleFrequency) { invSampleFreq = 1 .0f / sampleFrequency; }
38
43
void update (float gx, float gy, float gz, float ax, float ay, float az, float mx, float my, float mz);
39
44
void updateIMU (float gx, float gy, float gz, float ax, float ay, float az);
40
- float getPitch (){return atan2f (2 .0f * q2 * q3 - 2 .0f * q0 * q1, 2 .0f * q0 * q0 + 2 .0f * q3 * q3 - 1 .0f );};
41
- float getRoll (){return -1 .0f * asinf (2 .0f * q1 * q3 + 2 .0f * q0 * q2);};
42
- float getYaw (){return atan2f (2 .0f * q1 * q2 - 2 .0f * q0 * q3, 2 .0f * q0 * q0 + 2 .0f * q1 * q1 - 1 .0f );};
45
+ // float getPitch(){return atan2f(2.0f * q2 * q3 - 2.0f * q0 * q1, 2.0f * q0 * q0 + 2.0f * q3 * q3 - 1.0f);};
46
+ // float getRoll(){return -1.0f * asinf(2.0f * q1 * q3 + 2.0f * q0 * q2);};
47
+ // float getYaw(){return atan2f(2.0f * q1 * q2 - 2.0f * q0 * q3, 2.0f * q0 * q0 + 2.0f * q1 * q1 - 1.0f);};
48
+ float getRoll () {
49
+ if (!anglesComputed) computeAngles ();
50
+ return roll * 57 .29578f ;
51
+ }
52
+ float getPitch () {
53
+ if (!anglesComputed) computeAngles ();
54
+ return pitch * 57 .29578f ;
55
+ }
56
+ float getYaw () {
57
+ if (!anglesComputed) computeAngles ();
58
+ return yaw * 57 .29578f + 180 .0f ;
59
+ }
60
+ float getRollRadians () {
61
+ if (!anglesComputed) computeAngles ();
62
+ return roll;
63
+ }
64
+ float getPitchRadians () {
65
+ if (!anglesComputed) computeAngles ();
66
+ return pitch;
67
+ }
68
+ float getYawRadians () {
69
+ if (!anglesComputed) computeAngles ();
70
+ return yaw;
71
+ }
43
72
};
44
73
#endif
45
74
0 commit comments