|
3 | 3 | //=====================================================================================================
|
4 | 4 | //
|
5 | 5 | // Implementation of Madgwick's IMU and AHRS algorithms.
|
6 |
| -// See: http://www.x-io.co.uk/node/8#open_source_ahrs_and_imu_algorithms |
| 6 | +// See: http://www.x-io.co.uk/open-source-imu-and-ahrs-algorithms/ |
| 7 | +// |
| 8 | +// From the x-io website "Open-source resources available on this website are |
| 9 | +// provided under the GNU General Public Licence unless an alternative licence |
| 10 | +// is provided in source." |
7 | 11 | //
|
8 | 12 | // Date Author Notes
|
9 | 13 | // 29/09/2011 SOH Madgwick Initial release
|
|
20 | 24 | // Variable declaration
|
21 | 25 | class Madgwick{
|
22 | 26 | private:
|
23 |
| - float invSqrt(float x); |
24 |
| - volatile float beta = betaDef; // algorithm gain |
25 |
| - volatile float q0 = 1.0f; |
26 |
| - volatile float q1 = 0.0f; |
27 |
| - volatile float q2 = 0.0f; |
28 |
| - 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 |
29 | 33 |
|
30 | 34 | //---------------------------------------------------------------------------------------------------
|
31 | 35 | // Function declarations
|
32 | 36 | public:
|
33 |
| - Madgwick(void){}; |
| 37 | + Madgwick(void); |
34 | 38 | void update(float gx, float gy, float gz, float ax, float ay, float az, float mx, float my, float mz);
|
35 | 39 | void updateIMU(float gx, float gy, float gz, float ax, float ay, float az);
|
36 |
| - float getPitch(){return atan2(2 * q2 * q3 - 2 * q0 * q1, 2 * q0 * q0 + 2 * q3 * q3 - 1);}; |
37 |
| - float getRoll(){return -1 * asin(2 * q1 * q3 + 2 * q0 * q2);}; |
38 |
| - float getYaw(){return atan2(2 * q1 * q2 - 2 * q0 * q3, 2 * q0 * q0 + 2 * q1 * q1 - 1);}; |
| 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);}; |
39 | 43 | };
|
40 | 44 | #endif
|
41 | 45 |
|
|
0 commit comments