Skip to content

Commit bb47312

Browse files
committed
Merge pull request #7 from PaulStoffregen/master
Improve performance
2 parents 36a80ee + ab62100 commit bb47312

File tree

4 files changed

+30
-14
lines changed

4 files changed

+30
-14
lines changed

keywords.txt

100755100644
File mode changed.

library.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name=Madgwick
2-
version=1.0
2+
version=1.1
33
author=Arduino
44
maintainer=Arduino <[email protected]>
55
sentence=Helpers for MadgwickAHRS algorithm
66
paragraph=This library wraps the official implementation of MadgwickAHRS algorithm to get orientation of an object based on accelerometer and gyroscope readings
77
category=Data Processing
8-
url=http://arduino.cc/en/Reference/XXXXXX
8+
url=https://github.com/arduino-libraries/MadgwickAHRS
99
architectures=*

src/MadgwickAHRS.cpp

100755100644
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
//=====================================================================================================
44
//
55
// 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."
711
//
812
// Date Author Notes
913
// 29/09/2011 SOH Madgwick Initial release
@@ -29,6 +33,14 @@
2933
//---------------------------------------------------------------------------------------------------
3034
// AHRS algorithm update
3135

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

src/MadgwickAHRS.h

100755100644
Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
//=====================================================================================================
44
//
55
// 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."
711
//
812
// Date Author Notes
913
// 29/09/2011 SOH Madgwick Initial release
@@ -20,22 +24,22 @@
2024
// Variable declaration
2125
class Madgwick{
2226
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
2933

3034
//---------------------------------------------------------------------------------------------------
3135
// Function declarations
3236
public:
33-
Madgwick(void){};
37+
Madgwick(void);
3438
void update(float gx, float gy, float gz, float ax, float ay, float az, float mx, float my, float mz);
3539
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);};
3943
};
4044
#endif
4145

0 commit comments

Comments
 (0)