-
-
Notifications
You must be signed in to change notification settings - Fork 284
/
Copy pathRawImuDataSerial.ino
148 lines (124 loc) · 5.5 KB
/
RawImuDataSerial.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
===============================================
Example sketch for CurieIMU library for Intel(R) Curie(TM) devices.
Copyright (c) 2015 Intel Corporation. All rights reserved.
Based on I2C device class (I2Cdev) demonstration Arduino sketch for MPU6050
class by Jeff Rowberg: https://github.com/jrowberg/i2cdevlib
===============================================
I2Cdev device library code is placed under the MIT license
Copyright (c) 2011 Jeff Rowberg
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
===============================================
*/
#include "CurieIMU.h"
int ax, ay, az; // accelerometer values
int gx, gy, gz; // gyrometer values
const int ledPin = 13; // activity LED pin
bool blinkState = false; // state of the LED
int calibrateOffsets = 1; // int to determine whether calibration takes place or not
void setup() {
Serial.begin(9600); // initialize Serial communication
while (!Serial); // wait for the serial port to open
// initialize device
Serial.println("Initializing IMU device...");
CurieIMU.begin();
// verify connection
Serial.println("Testing device connections...");
if (CurieIMU.begin()) {
Serial.println("CurieIMU connection successful");
} else {
Serial.println("CurieIMU connection failed");
}
// use the code below to calibrate accel/gyro offset values
if (calibrateOffsets == 1) {
Serial.println("Internal sensor offsets BEFORE calibration...");
Serial.print(CurieIMU.getAccelerometerOffset(X_AXIS));
Serial.print("\t"); // -76
Serial.print(CurieIMU.getAccelerometerOffset(Y_AXIS));
Serial.print("\t"); // -235
Serial.print(CurieIMU.getAccelerometerOffset(Z_AXIS));
Serial.print("\t"); // 168
Serial.print(CurieIMU.getGyroOffset(X_AXIS));
Serial.print("\t"); // 0
Serial.print(CurieIMU.getGyroOffset(Y_AXIS));
Serial.print("\t"); // 0
Serial.println(CurieIMU.getGyroOffset(Z_AXIS));
// To manually configure offset compensation values,
// use the following methods instead of the autoCalibrate...() methods below
//CurieIMU.setAccelerometerOffset(X_AXIS,495.3);
//CurieIMU.setAccelerometerOffset(Y_AXIS,-15.6);
//CurieIMU.setAccelerometerOffset(Z_AXIS,491.4);
//CurieIMU.setGyroOffset(X_AXIS,7.869);
//CurieIMU.setGyroOffset(Y_AXIS,-0.061);
//CurieIMU.setGyroOffset(Z_AXIS,15.494);
Serial.println("About to calibrate. Make sure your board is stable and upright");
delay(5000);
// The board must be resting in a horizontal position for
// the following calibration procedure to work correctly!
Serial.print("Starting Gyroscope calibration and enabling offset compensation...");
CurieIMU.autoCalibrateGyroOffset();
Serial.println(" Done");
Serial.print("Starting Acceleration calibration and enabling offset compensation...");
CurieIMU.autoCalibrateAccelerometerOffset(X_AXIS, 0);
CurieIMU.autoCalibrateAccelerometerOffset(Y_AXIS, 0);
CurieIMU.autoCalibrateAccelerometerOffset(Z_AXIS, 1);
Serial.println(" Done");
Serial.println("Internal sensor offsets AFTER calibration...");
Serial.print(CurieIMU.getAccelerometerOffset(X_AXIS));
Serial.print("\t"); // -76
Serial.print(CurieIMU.getAccelerometerOffset(Y_AXIS));
Serial.print("\t"); // -2359
Serial.print(CurieIMU.getAccelerometerOffset(Z_AXIS));
Serial.print("\t"); // 1688
Serial.print(CurieIMU.getGyroOffset(X_AXIS));
Serial.print("\t"); // 0
Serial.print(CurieIMU.getGyroOffset(Y_AXIS));
Serial.print("\t"); // 0
Serial.println(CurieIMU.getGyroOffset(Z_AXIS));
}
// configure Arduino LED for activity indicator
pinMode(ledPin, OUTPUT);
}
void loop() {
// read raw accel/gyro measurements from device
CurieIMU.readMotionSensor(ax, ay, az, gx, gy, gz);
// these methods (and a few others) are also available
//CurieIMU.readAcceleration(ax, ay, az);
//CurieIMU.readRotation(gx, gy, gz);
//ax = CurieIMU.readAccelerometer(X_AXIS);
//ay = CurieIMU.readAccelerometer(Y_AXIS);
//az = CurieIMU.readAccelerometer(Z_AXIS);
//gx = CurieIMU.readGyro(X_AXIS);
//gy = CurieIMU.readGyro(Y_AXIS);
//gz = CurieIMU.readGyro(Z_AXIS);
// display tab-separated accel/gyro x/y/z values
Serial.print("a/g:\t");
Serial.print(ax);
Serial.print("\t");
Serial.print(ay);
Serial.print("\t");
Serial.print(az);
Serial.print("\t");
Serial.print(gx);
Serial.print("\t");
Serial.print(gy);
Serial.print("\t");
Serial.println(gz);
// blink LED to indicate activity
blinkState = !blinkState;
digitalWrite(ledPin, blinkState);
}