2
2
#include < MadgwickAHRS.h>
3
3
4
4
Madgwick filter;
5
- unsigned long microsPerReading, microsPrevious;
6
5
float accelScale, gyroScale;
7
6
8
7
void setup () {
@@ -18,10 +17,6 @@ void setup() {
18
17
CurieIMU.setAccelerometerRange (2 );
19
18
// Set the gyroscope range to 250 degrees/second
20
19
CurieIMU.setGyroRange (250 );
21
-
22
- // initialize variables to pace updates to correct rate
23
- microsPerReading = 1000000 / 25 ;
24
- microsPrevious = micros ();
25
20
}
26
21
27
22
void loop () {
@@ -30,11 +25,9 @@ void loop() {
30
25
float ax, ay, az;
31
26
float gx, gy, gz;
32
27
float roll, pitch, heading;
33
- unsigned long microsNow;
34
28
35
- // check if it's time to read data and update the filter
36
- microsNow = micros ();
37
- if (microsNow - microsPrevious >= microsPerReading) {
29
+ // Check if new data is available from gyroscope or accelerometer
30
+ if (CurieIMU.gyroDataReady () && CurieIMU.accelDataReady ()) {
38
31
39
32
// read raw data from CurieIMU
40
33
CurieIMU.readMotionSensor (aix, aiy, aiz, gix, giy, giz);
@@ -60,9 +53,6 @@ void loop() {
60
53
Serial.print (pitch);
61
54
Serial.print (" " );
62
55
Serial.println (roll);
63
-
64
- // increment previous time, so we keep proper pace
65
- microsPrevious = microsPrevious + microsPerReading;
66
56
}
67
57
}
68
58
0 commit comments