-
Notifications
You must be signed in to change notification settings - Fork 2
/
GyroCompass.ino
627 lines (580 loc) · 18.3 KB
/
GyroCompass.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
#include "NMEA2000_CAN.h"
#include "N2kMessages.h"
#include <MadgwickAHRS.h>
#include <i2c_t3.h>
#include "MPU9250.h"
#include <SparkFunBME280.h>
#include <EEPROM.h>
#include "kalman.h"
#define EEPROM_ADR_CONFIG 0 // eeprom address for config params
#define P0 1005.3
bool SerialDebug = false;
#define intPin 12
#define stbyPin 14
volatile boolean flagDataReady;
volatile boolean flagCalibrate;
#define MAGIC 24234
struct tConfig {
uint16_t Magic; //test if eeprom initialized
float magBias[3];
float magScale[3];
float accelBias[3];
float gyroBias[3];
float KpAcc; // proportional gain governs rate of convergence to accelerometer
float KiAcc; // integral gain governs rate of convergence of gyroscope biases
float KpMag; // proportional gain governs rate of convergence to magnetometer
float KiMag; // integral gain governs rate of convergence of gyroscope biases
float accelCutoff;
};
int SID = 1;
tConfig config;
const tConfig defConfig PROGMEM = {
MAGIC,
0.f,0.f,0.f, // magBias
1.f,1.f,1.f, // magScale
0.f,0.f,0.f, // accelBias
0.f,0.f,0.f, // gyroBias
1.0f,0.f, // KpAcc, KiAcc
5.0f,0.f, // KpMag ,KiMag
0.25f // accelCutoff
};
tN2kMsg N2kMsg;
MPU9250 IMU(0x68, 0);
float a12, a22, a31, a32, a33; // rotation matrix coefficients for Euler angles and gravity components
float ax, ay, az, gx, gy, gz, hx, hy, hz, t, mx, my, mz;
int beginStatus;
float SelfTest[6]; // holds results of gyro and accelerometer self test
float magBias[3] = { 0, 0, 0 }, magScale[3] = { 0, 0, 0 };
float factoryMagScale[3];
double T, P;
float pitch, yaw, roll, rollrate, pitchrate, yawrate, heading;
float deltat = 0.0f, sum = 0.0f; // integration interval for both filter schemes
uint32_t delt_t = 0; // used to control display output rate
uint32_t count = 0, sumCount = 0; // used to control display output rate
uint32_t lastUpdate = 0, firstUpdate = 0; // used to calculate integration interval
uint32_t Now = 0; // used to calculate integration interval
float lin_ax, lin_ay, lin_az; // linear acceleration (acceleration with gravity component subtracted)
float DECLINATION = 10.823; // magnetic declination @ annapolis 11d 9'
Madgwick ahrs;
BME280 bmp;
int16_t mmax[3] = { -9999 ,-9999 ,-9999 };
int16_t mmin[3] = { 9999 ,9999 ,9999 };
float mmaxf[3] = { -9999 ,-9999 ,-9999 };
float mminf[3] = { 9999 ,9999 ,9999 };
#define PROCESS_NOISE 0.00000001 // q process noise covariance
#define SENSOR_NOISE 0.01 // r measurement noise covariance
#define INITIAL_Q 500.0 // p estimation error covariance
Kalman Filter(PROCESS_NOISE, SENSOR_NOISE, INITIAL_Q, 10);
int srd = 9; // 5;
float mxa, mya, mza;
long slowloop = 0;
long veryslowloop = 0;
// List here messages your device will transmit.
const unsigned long TransmitMessagesCompass[] PROGMEM = { 127250L,127251L, 127257L , 0 }; //Vessel Heading, Rate of Turn, Attitude
const unsigned long TransmitMessagesEnv[] PROGMEM = { 130310L, 130311L,0 }; //Atmospheric Pressure, Temperature
#define DEV_COMPASS 0 // 60-140
#define DEV_ENV 1 //
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
pinMode(stbyPin, OUTPUT);
digitalWrite(stbyPin, LOW);
Blink(5, 300);
Serial.begin(115200);
delay(100);
Serial.println("Start");
pinMode(intPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(intPin), myinthandler, RISING);
Serial.println("Attach Interrupt");
delay(100);
Serial.println("IMU initialization");
beginStatus = IMU.begin(ACCEL_RANGE_2G, GYRO_RANGE_250DPS);
if (beginStatus < 0) {
delay(1000);
Serial.println("IMU initialization unsuccessful");
Serial.println("try cycling power");
delay(10000);
beginStatus = IMU.begin(ACCEL_RANGE_4G, GYRO_RANGE_250DPS);
}
else Serial.println("IMU init success!");
IMU.setFilt(DLPF_BANDWIDTH_5HZ, srd);
IMU.getMagScale(factoryMagScale);
ReadConfig();
if (config.Magic != MAGIC) {
//InitializeEEPROM();
Serial.println(F("\nNo stored calibration\r\n Press 'a' to run accel/gyro cal\n Press 'c' to run mag cal"));
delay(1000);
}
else
{
Serial.println(F("Loading stored calibration\n"));
PrintConfig();
IMU.setAccelBias(config.accelBias);
IMU.setGyroBias(config.gyroBias);
IMU.setMagBias(config.magBias);
IMU.setMagScale(config.magScale);
}
//selfTest();
Serial.println("BMP Start");
bmp.settings.commInterface = I2C_MODE;
bmp.settings.I2CAddress = 0x76;
bmp.settings.runMode = 3;
bmp.settings.filter = 0;
bmp.settings.tempOverSample = 1;
bmp.settings.pressOverSample = 1;
//bmp.settings.disableHumidity = true;
if (!bmp.begin()) {
Serial.println(F("BMP init failed!"));
while (1);
}
else Serial.println(F("BMP init success!"));
delay(50);
while (!flagDataReady) {}
ahrs.begin(34);
NMEA2000.SetDeviceCount(2);
NMEA2000.SetInstallationDescription1("Mr Bubble Compass");
NMEA2000.SetInstallationDescription2("");
NMEA2000.SetProductInformation("01290517", // Manufacturer's Model serial code
666, // Manufacturer's product code
"Gyro Compass", // Manufacturer's Model ID
"1.0.0.1 (2015-08-14)", // Manufacturer's Software version code
"1.0.0.0 (2018-01-20)", // Manufacturer's Model version
1, // load equivalency *50ma
0xffff, // NMEA 2000 version - use default
0xff, // Sertification level - use default
DEV_COMPASS
);
NMEA2000.SetProductInformation("01290517", // Manufacturer's Model serial code
667, // Manufacturer's product code
"Barometer", // Manufacturer's Model ID
"1.0.0.0 (2015-08-14)", // Manufacturer's Software version code
"1.0.0.0 (2018-01-20)", // Manufacturer's Model version
1, // load equivalency *50ma
0xffff, // NMEA 2000 version - use default
0xff, // Sertification level - use default
DEV_ENV
);
// Set device information
NMEA2000.SetDeviceInformation(290517, // Unique number. Use e.g. Serial number.
140, // Device function=Temperature See codes on http://www.nmea.org/Assets/20120726%20nmea%202000%20class%20%26%20function%20codes%20v%202.00.pdf
60, // Device class=Sensor Communication Interface. See codes on http://www.nmea.org/Assets/20120726%20nmea%202000%20class%20%26%20function%20codes%20v%202.00.pdf
2040, // Just choosen free from code list on http://www.nmea.org/Assets/20121020%20nmea%202000%20registration%20list.pdf
4,
DEV_COMPASS
);
NMEA2000.SetDeviceInformation(290517, // Unique number. Use e.g. Serial number.
130, // Device function=Temperature See codes on http://www.nmea.org/Assets/20120726%20nmea%202000%20class%20%26%20function%20codes%20v%202.00.pdf
85, // Device class=Sensor Communication Interface. See codes on http://www.nmea.org/Assets/20120726%20nmea%202000%20class%20%26%20function%20codes%20v%202.00.pdf
2040, // Just choosen free from code list on http://www.nmea.org/Assets/20121020%20nmea%202000%20registration%20list.pdf
4,
DEV_ENV
);
NMEA2000.SetMode(tNMEA2000::N2km_NodeOnly, 22);
NMEA2000.EnableForward(false);
NMEA2000.ExtendTransmitMessages(TransmitMessagesCompass, DEV_COMPASS);
NMEA2000.ExtendTransmitMessages(TransmitMessagesEnv, DEV_ENV);
NMEA2000.SetN2kCANMsgBufSize(5);
NMEA2000.Open();
delay(100);
Serial.println(F("Starting\n a=Accl/Gyro cal.\n c=Start Mag cal.\n d=toggle output mag x,y,x\n h=toggle output heading.\n p=print config.\n t=Self Test.\n\n"));
}
bool SDEBUG = false; // debug print for spreadsheet
bool SPRINT = false; // send test output
int pointcount = 0; // data points for mag test
void loop() {
char command = getCommand();
switch (command)
{
case 'c': // start mag calibration
if (!flagCalibrate)
{
StartMagCal();
}
else
{
Serial.println(F("Calibration already running!"));
}
break;
case 'f': // finish mag calibration
FinishMagCal();
break;
case 'h': //toggle debug
SDEBUG = !SDEBUG;
delay(100);
break;
case 's':
SPRINT = !SPRINT;
break;
case 'p':
PrintConfig();
PrintIMUConfig();
break;
case 'a':
Serial.println(F("Accel Calibration Starting - hold still"));
CalibrateAG();
break;
case 't':
selfTest();
break;
case 'l':
printMag();
break;
case 'r':
RemoveCal();
break;
default:
break;
}
if (flagDataReady) { //wait for interrupt
if (flagCalibrate)
{
magCalLoop();
}
else
{
IMU.getMotion9(&ax, &ay, &az, &gx, &gy, &gz, &mx, &my, &mz);
ahrs.update(gx, gy, gz, ax, ay, az, mx, my, mz);
}
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
flagDataReady = false;
}
// display at 0.25s rate independent of data rates
delt_t = millis() - count;
if (delt_t > 250) { // update once per half-second independent of read rate
Now = micros();
deltat = ((Now - lastUpdate) / 1000000.0f); // set integration time by time elapsed since last filter update
lastUpdate = Now;
count = millis();
if (!flagCalibrate)
{
roll = ahrs.getRoll();
pitch = ahrs.getPitch();
yaw = ahrs.getYaw();
heading = ahrs.getYaw();
//heading += DECLINATION;
//heading = YawtoHeading(yaw);
if (SDEBUG) {
if (pointcount < 5000) {
printMag();
pointcount++;
}
else {
SDEBUG = false;
pointcount = 0;
}
}
if (SPRINT) { printHeading(); }
SetN2kAttitude(N2kMsg, SID, yaw*DEG_TO_RAD, pitch*DEG_TO_RAD, roll*DEG_TO_RAD);
NMEA2000.SendMsg(N2kMsg, DEV_COMPASS);
SetN2kRateOfTurn(N2kMsg, SID, gz/36); // radians
NMEA2000.SendMsg(N2kMsg, DEV_COMPASS);
SID++; if (SID > 254) { SID = 1; }
}
slowloop++;
}
//1 s
if (slowloop > 4) { slowloop = 0; SlowLoop(); }
NMEA2000.ParseMessages();
}
void RemoveCal()
{
Serial.println(F("Remove calibration"));
for (int ii = 0; ii < 3; ii++) {
config.accelBias[ii] = 0;
config.gyroBias[ii] = 0;
config.magBias[ii] = 0;
config.magScale[ii] = 1;
}
UpdateConfig();
IMU.setAccelBias(config.accelBias);
IMU.setGyroBias(config.gyroBias);
IMU.setMagBias(config.magBias);
IMU.setMagScale(config.magScale);
}
void SlowLoop()
{
if (flagCalibrate) {
Serial.print('.');
}
// send magnetic heading
SetN2kMagneticHeading(N2kMsg, SID, heading*DEG_TO_RAD, N2kDoubleNA, N2kDoubleNA);
NMEA2000.SendMsg(N2kMsg, DEV_COMPASS);
// Send Temperature & Pressure
T = bmp.readTempC();
P = bmp.readFloatPressure();
SetN2kEnvironmentalParameters(N2kMsg, SID, N2kts_MainCabinTemperature, CToKelvin(T), N2khs_Undef, 0, P);
NMEA2000.SendMsg(N2kMsg, DEV_ENV);
}
void myinthandler()
{
flagDataReady = true;
}
void CalibrateAG()
{
float x, y, z;
float aa[3], ga[3];
IMU.setAccelBias(aa); //zero current bias calibration
IMU.setGyroBias(ga);
uint8_t i = 0;
const uint8_t samples = 100;
while (i < samples)
{
if (flagDataReady) {
IMU.getAccel(&x, &y, &z);
aa[0] += x; aa[1] += y; aa[2] += z;
IMU.getGyro(&x, &y, &z);
ga[0] += x; ga[1] += y; ga[2] += z;
delay(20);
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
flagDataReady = false;
i++;
}
}
for (uint8_t ii = 0; ii < 3; ii++) { // Get the average
aa[ii] /= (float)samples;
ga[ii] /= (float)samples;
}
aa[2] -= 10; // subtract Gravity from acc Z
IMU.setAccelBias(aa);
IMU.setGyroBias(ga);
for (uint8_t ii = 0; ii < 3; ii++) {
config.accelBias[ii] = aa[ii];
config.gyroBias[ii] = ga[ii];
}
Serial.println("\nAverage");
Serial.print("Accel X "); Serial.print(aa[0] );
Serial.print(" Y "); Serial.print(aa[1]);
Serial.print(" Z "); Serial.print(aa[2]);
Serial.print(" Gyro X "); Serial.print(ga[0]);
Serial.print(" Y "); Serial.print(ga[1]);
Serial.print(" Z "); Serial.println(ga[2]);
delay(500);
Serial.println("\nWriting EEPROM");
UpdateConfig();
delay(2000);
flagCalibrate = false;
}
void selfTest()
{
IMU.MPU9250SelfTest(IMU.SelfTest);
Serial.print("x-axis self test: acceleration trim within : ");
Serial.print(IMU.SelfTest[0], 1); Serial.println("% of factory value");
Serial.print("y-axis self test: acceleration trim within : ");
Serial.print(IMU.SelfTest[1], 1); Serial.println("% of factory value");
Serial.print("z-axis self test: acceleration trim within : ");
Serial.print(IMU.SelfTest[2], 1); Serial.println("% of factory value");
Serial.print("x-axis self test: gyration trim within : ");
Serial.print(IMU.SelfTest[3], 1); Serial.println("% of factory value");
Serial.print("y-axis self test: gyration trim within : ");
Serial.print(IMU.SelfTest[4], 1); Serial.println("% of factory value");
Serial.print("z-axis self test: gyration trim within : ");
Serial.print(IMU.SelfTest[5], 1); Serial.println("% of factory value");
}
void PrintConfig()
{
Serial.print("Config Accel bias\t");
Serial.print(config.accelBias[0]); Serial.print("\t");
Serial.print(config.accelBias[1]); Serial.print("\t");
Serial.print(config.accelBias[2]); Serial.println("\t");
Serial.print("Config Gyro bias\t");
Serial.print(config.gyroBias[0]); Serial.print("\t");
Serial.print(config.gyroBias[1]); Serial.print("\t");
Serial.print(config.gyroBias[2]); Serial.println("\t");
Serial.print("Config Mag bias \t");
Serial.print(config.magBias[0]); Serial.print("\t");
Serial.print(config.magBias[1]); Serial.print("\t");
Serial.print(config.magBias[2]); Serial.println("\t");
Serial.print("Config Mag scale\t");
Serial.print(config.magScale[0]); Serial.print("\t");
Serial.print(config.magScale[1]); Serial.print("\t");
Serial.print(config.magScale[2]); Serial.println("\t");
}
void PrintIMUConfig()
{
float buff[3];
IMU.getAccelBias(buff);
Serial.println("");
Serial.print("IMU Accel bias\t");
Serial.print(buff[0],2); Serial.print("\t");
Serial.print(buff[1],2); Serial.print("\t");
Serial.print(buff[2],2); Serial.println("\t");
IMU.getGyroBias(buff);
Serial.print("IMU Gyro bias\t");
Serial.print(buff[0],2); Serial.print("\t");
Serial.print(buff[1],2); Serial.print("\t");
Serial.print(buff[2],2); Serial.println("\t");
IMU.getMagBias(buff);
Serial.print("IMU Mag bias\t");
Serial.print(buff[0],2); Serial.print("\t");
Serial.print(buff[1],2); Serial.print("\t");
Serial.print(buff[2],2); Serial.println("\t");
IMU.getMagScale(buff);
Serial.print("Mag scale\t");
Serial.print(buff[0],4); Serial.print("\t");
Serial.print(buff[1],4); Serial.print("\t");
Serial.print(buff[2],4); Serial.println("\t");
}
float YawtoHeading(float yaw)
{
float hdm;
hdm = yaw - 90; // converts yaw to heading magnetic
if (yaw < 90 && yaw >= -179.99) {
hdm = yaw + 270;
}
return hdm;
}
void printData() {
Serial.println("");
if (SerialDebug) {
Serial.print("gx\t"); Serial.print(gx*RAD_TO_DEG, 2); Serial.println(" deg/s");
Serial.print("gy\t"); Serial.print(gy*RAD_TO_DEG, 2); Serial.println(" deg/s");
Serial.print("ax\t"); Serial.println((ax), 2);
Serial.print("ay\t"); Serial.println((ay), 2);
Serial.print("az\t"); Serial.println((az), 2);
Serial.print("mx\t"); Serial.print(mx); Serial.println(" milliGauss");
Serial.print("my\t"); Serial.print(my); Serial.println(" milliGauss");
Serial.print("mz\t"); Serial.print(mz); Serial.println(" milliGauss");
//Serial.print("q0 = "); Serial.print(*(getQ()));
//Serial.print(" qx = "); Serial.print(*(getQ() + 1));
//Serial.print(" qy = "); Serial.print(*(getQ() + 2));
//Serial.print(" qz = "); Serial.println(*(getQ() + 3));
}
Serial.print(F("Pressure: "));
Serial.print(P/100, 1);
Serial.println(" P");
Serial.print(F("Temp: "));
Serial.print(T, 2);
Serial.println(" *C");
Serial.print("Pitch:\t"); Serial.println(pitch, 2);
Serial.print("Roll:\t"); Serial.println(roll, 2);
Serial.print("Yaw:\t"); Serial.println(yaw, 2);
Serial.print("Heading\t"); Serial.print(heading); Serial.println(" deg");
Serial.print("RateOfTurn\t"); Serial.print(gz*RAD_TO_DEG, 2); Serial.println(" deg/s");
if (SerialDebug) {
Serial.print("rate = "); Serial.print((float)sumCount / sum, 2); Serial.println(" Hz");
}
}
char getCommand()
{
char c = '\0';
if (Serial.available())
{
c = Serial.read();
}
return c;
}
// tbd mag cal circle detection
//int magCalCircles = 3;
//void magCalLoop()
//{
// // collect data points
// float x, y, z;
// IMU.getMag(&x, &y, &z);
// magcalMinMax(x, y, z); //accumulate min max
// //detect circles
// //if(completed) magCalCalc
//}
void StartMagCal()
{
flagCalibrate = true;
IMU.startMagCal();
Serial.println(F("Begin calibration, press 'f' to finish"));
}
void magCalLoop()
{
IMU.updateMagCal();
}
void FinishMagCal()
{
Serial.println("\nCal complete");
IMU.stopMagCal();
Serial.print("Computed new values from: ");
Serial.print(IMU.getCalCount());
Serial.println(" samples");
// read new values
IMU.getMagBias(magBias);
IMU.getMagScale(magScale);
//update config
for (uint8_t i = 0; i < 3; i++) {
config.magBias[i] = magBias[i];
config.magScale[i] = magScale[i];
}
IMU.getMinMax(mmin, mmax);
Serial.println("\nMag min max");
Serial.print("\tX "); Serial.print(mmin[0]); Serial.print("\t"); Serial.println(mmax[0]);
Serial.print("\tY "); Serial.print(mmin[1]); Serial.print("\t"); Serial.println(mmax[1]);
Serial.print("\tZ "); Serial.print(mmin[2]); Serial.print("\t"); Serial.println(mmax[2]);
Serial.println();
PrintConfig();
PrintIMUConfig();
Serial.println("\nWriting EEPROM");
UpdateConfig();
flagCalibrate = false;
}
// LED blinker
// count flashes in duration ms
void Blink(int count, unsigned long duration)
{
unsigned long d = duration / count;
for (int counter = 0; counter < count; counter++) {
digitalWrite(LED_BUILTIN, HIGH);
delay(d / 2);
digitalWrite(LED_BUILTIN, LOW);
delay(d / 2);
}
}
//Load From EEPROM
void ReadConfig()
{
EEPROM.get(EEPROM_ADR_CONFIG, config);
}
//Write to EEPROM - Teensy non-volatile area size is 2048 bytes 100,000 cycles
void UpdateConfig()
{
Blink(5, 2000);
Serial.print("Updating config");
config.Magic = MAGIC;
EEPROM.put(EEPROM_ADR_CONFIG, config);
}
void InitializeEEPROM()
{
Serial.print("Initialize EEPROM");
config = defConfig;
UpdateConfig();
}
void printJSON()
{
String s = String("{\"time\":") + millis()
+ String(",\"pitch\":") + pitch
+ String(",\"roll\":") + roll
+ String(",\"yaw\":") + yaw
+ String(",\"gz\":") + gz
+ String(",\"t_celsius\":") + T
+ String(",\"P\":") + P
+ "}";
Serial.println(s);
}
void dumpData() {
Serial.print(pitch, 2); Serial.print("\t");
Serial.print(roll, 2);Serial.print("\t");
Serial.print(yaw, 2); Serial.print("\t");
Serial.print(heading,2);
Serial.println();
}
void printHeading() {
Serial.print(heading, 2);
Serial.println();
}
void printMag()
{
//int16_t d[3];
//IMU.getMagCounts(&d[0], &d[1], &d[2]);
//Serial.print(""); Serial.print(d[0]);
//Serial.print("\t"); Serial.print(d[1]);
//Serial.print("\t"); Serial.println(d[2]);
float d[3];
IMU.getMag(&d[0], &d[1], &d[2]);
Serial.print(""); Serial.print(d[0],3);
Serial.print("\t"); Serial.print(d[1],3);
Serial.print("\t"); Serial.println(d[2],3);
}