-
Notifications
You must be signed in to change notification settings - Fork 0
/
SparkFunMPU9250-DMP.cpp
789 lines (664 loc) · 16.4 KB
/
SparkFunMPU9250-DMP.cpp
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
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
/******************************************************************************
SparkFunMPU9250-DMP.cpp - MPU-9250 Digital Motion Processor Arduino Library
Jim Lindblom @ SparkFun Electronics
original creation date: November 23, 2016
https://github.com/sparkfun/SparkFun_MPU9250_DMP_Arduino_Library
This library implements motion processing functions of Invensense's MPU-9250.
It is based on their Emedded MotionDriver 6.12 library.
https://www.invensense.com/developers/software-downloads/
Corrections:
computeEulerAngles function under Sparkfun-DMP-lib is corrected according to issue below.
Now angles are correct too. https://github.com/sparkfun/SparkFun_MPU-9250-DMP_Arduino_Library/issues/5
******************************************************************************/
#include "SparkFunMPU9250-DMP.h"
#include "MPU9250_RegisterMap.h"
#include "util/mdcompat.h"
extern "C" {
#include "util/inv_mpu.h"
}
extern I2C * imu_i2c;
extern Timer * imu_timer;
static unsigned char mpu9250_orientation;
static unsigned char tap_count;
static unsigned char tap_direction;
static bool _tap_available;
static void orient_cb(unsigned char orient);
static void tap_cb(unsigned char direction, unsigned char count);
MPU9250_DMP::MPU9250_DMP()
{
_mSense = 6.665f; // Constant - 4915 / 32760
_aSense = 0.0f; // Updated after accel FSR is set
_gSense = 0.0f; // Updated after gyro FSR is set
}
inv_error_t MPU9250_DMP::begin(void)
{
inv_error_t result;
struct int_param_s int_param;
init_i2c();
result = mpu_init(&int_param);
if (result)
return result;
// mpu_set_bypass(1); // Place all slaves (including compass) on primary bus
// mpu_set_bypass(0); // do not place compass on primary bus
setSensors(INV_XYZ_GYRO | INV_XYZ_ACCEL);
// setSensors(INV_XYZ_GYRO | INV_XYZ_ACCEL | INV_XYZ_COMPASS);
_gSense = getGyroSens();
_aSense = getAccelSens();
return result;
}
inv_error_t MPU9250_DMP::enableInterrupt(unsigned char enable)
{
return set_int_enable(enable);
}
inv_error_t MPU9250_DMP::setIntLevel(unsigned char active_low)
{
return mpu_set_int_level(active_low);
}
inv_error_t MPU9250_DMP::setIntLatched(unsigned char enable)
{
return mpu_set_int_latched(enable);
}
short MPU9250_DMP::getIntStatus(void)
{
short status;
if (mpu_get_int_status(&status) == INV_SUCCESS)
{
return status;
}
return 0;
}
// Accelerometer Low-Power Mode. Rate options:
// 1.25 (1), 2.5 (2), 5, 10, 20, 40,
// 80, 160, 320, or 640 Hz
// Disables compass and gyro
inv_error_t MPU9250_DMP::lowPowerAccel(unsigned short rate)
{
return mpu_lp_accel_mode(rate);
}
inv_error_t MPU9250_DMP::setGyroFSR(unsigned short fsr)
{
inv_error_t err;
err = mpu_set_gyro_fsr(fsr);
if (err == INV_SUCCESS)
{
_gSense = getGyroSens();
}
return err;
}
inv_error_t MPU9250_DMP::setAccelFSR(unsigned char fsr)
{
inv_error_t err;
err = mpu_set_accel_fsr(fsr);
if (err == INV_SUCCESS)
{
_aSense = getAccelSens();
}
return err;
}
unsigned short MPU9250_DMP::getGyroFSR(void)
{
unsigned short tmp;
if (mpu_get_gyro_fsr(&tmp) == INV_SUCCESS)
{
return tmp;
}
return 0;
}
unsigned char MPU9250_DMP::getAccelFSR(void)
{
unsigned char tmp;
if (mpu_get_accel_fsr(&tmp) == INV_SUCCESS)
{
return tmp;
}
return 0;
}
unsigned short MPU9250_DMP::getMagFSR(void)
{
unsigned short tmp;
if (mpu_get_compass_fsr(&tmp) == INV_SUCCESS)
{
return tmp;
}
return 0;
}
inv_error_t MPU9250_DMP::setLPF(unsigned short lpf)
{
return mpu_set_lpf(lpf);
}
unsigned short MPU9250_DMP::getLPF(void)
{
unsigned short tmp;
if (mpu_get_lpf(&tmp) == INV_SUCCESS)
{
return tmp;
}
return 0;
}
inv_error_t MPU9250_DMP::setSampleRate(unsigned short rate)
{
return mpu_set_sample_rate(rate);
}
unsigned short MPU9250_DMP::getSampleRate(void)
{
unsigned short tmp;
if (mpu_get_sample_rate(&tmp) == INV_SUCCESS)
{
return tmp;
}
return 0;
}
inv_error_t MPU9250_DMP::setCompassSampleRate(unsigned short rate)
{
return mpu_set_compass_sample_rate(rate);
}
unsigned short MPU9250_DMP::getCompassSampleRate(void)
{
unsigned short tmp;
if (mpu_get_compass_sample_rate(&tmp) == INV_SUCCESS)
{
return tmp;
}
return 0;
}
float MPU9250_DMP::getGyroSens(void)
{
float sens;
if (mpu_get_gyro_sens(&sens) == INV_SUCCESS)
{
return sens;
}
return 0;
}
unsigned short MPU9250_DMP::getAccelSens(void)
{
unsigned short sens;
if (mpu_get_accel_sens(&sens) == INV_SUCCESS)
{
return sens;
}
return 0;
}
float MPU9250_DMP::getMagSens(void)
{
return 0.15; // Static, 4915/32760
}
unsigned char MPU9250_DMP::getFifoConfig(void)
{
unsigned char sensors;
if (mpu_get_fifo_config(&sensors) == INV_SUCCESS)
{
return sensors;
}
return 0;
}
inv_error_t MPU9250_DMP::configureFifo(unsigned char sensors)
{
return mpu_configure_fifo(sensors);
}
inv_error_t MPU9250_DMP::resetFifo(void)
{
return mpu_reset_fifo();
}
inv_error_t MPU9250_DMP::resetDmp(void)
{
return mpu_reset_dmp();
}
unsigned short MPU9250_DMP::fifoAvailable(void)
{
unsigned char fifoH, fifoL;
if (mpu_read_reg(MPU9250_FIFO_COUNTH, &fifoH) != INV_SUCCESS)
return 0;
if (mpu_read_reg(MPU9250_FIFO_COUNTL, &fifoL) != INV_SUCCESS)
return 0;
return (fifoH << 8 ) | fifoL;
}
inv_error_t MPU9250_DMP::updateFifo(void)
{
short gyro[3], accel[3];
unsigned long timestamp;
unsigned char sensors, more;
if (mpu_read_fifo(gyro, accel, ×tamp, &sensors, &more) != INV_SUCCESS)
return INV_ERROR;
if (sensors & INV_XYZ_ACCEL)
{
ax = accel[X_AXIS];
ay = accel[Y_AXIS];
az = accel[Z_AXIS];
}
if (sensors & INV_X_GYRO)
gx = gyro[X_AXIS];
if (sensors & INV_Y_GYRO)
gy = gyro[Y_AXIS];
if (sensors & INV_Z_GYRO)
gz = gyro[Z_AXIS];
time = timestamp;
return INV_SUCCESS;
}
inv_error_t MPU9250_DMP::setSensors(unsigned char sensors)
{
return mpu_set_sensors(sensors);
}
bool MPU9250_DMP::dataReady()
{
unsigned char intStatusReg;
if (mpu_read_reg(MPU9250_INT_STATUS, &intStatusReg) == INV_SUCCESS)
{
return (intStatusReg & (1<<INT_STATUS_RAW_DATA_RDY_INT));
}
return false;
}
inv_error_t MPU9250_DMP::update(unsigned char sensors)
{
inv_error_t aErr = INV_SUCCESS;
inv_error_t gErr = INV_SUCCESS;
inv_error_t mErr = INV_SUCCESS;
inv_error_t tErr = INV_SUCCESS;
if (sensors & UPDATE_ACCEL)
aErr = updateAccel();
if (sensors & UPDATE_GYRO)
gErr = updateGyro();
if (sensors & UPDATE_COMPASS)
mErr = updateCompass();
if (sensors & UPDATE_TEMP)
tErr = updateTemperature();
return aErr | gErr | mErr | tErr;
}
int MPU9250_DMP::updateAccel(void)
{
short data[3];
if (mpu_get_accel_reg(data, &time))
{
return INV_ERROR;
}
ax = data[X_AXIS];
ay = data[Y_AXIS];
az = data[Z_AXIS];
return INV_SUCCESS;
}
int MPU9250_DMP::updateGyro(void)
{
short data[3];
if (mpu_get_gyro_reg(data, &time))
{
return INV_ERROR;
}
gx = data[X_AXIS];
gy = data[Y_AXIS];
gz = data[Z_AXIS];
return INV_SUCCESS;
}
int MPU9250_DMP::updateCompass(void)
{
short data[3];
if (mpu_get_compass_reg(data, &time))
{
return INV_ERROR;
}
mx = data[X_AXIS];
my = data[Y_AXIS];
mz = data[Z_AXIS];
return INV_SUCCESS;
}
inv_error_t MPU9250_DMP::updateTemperature(void)
{
return mpu_get_temperature(&temperature, &time);
}
int MPU9250_DMP::selfTest(long * gyro, long *accel)
{
// long gyro[3], accel[3];
return mpu_run_self_test(gyro, accel);
}
inv_error_t MPU9250_DMP::dmpBegin(unsigned short features, unsigned short fifoRate)
{
unsigned short feat = features;
unsigned short rate = fifoRate;
if (dmpLoad() != INV_SUCCESS)
return INV_ERROR;
// 3-axis and 6-axis LP quat are mutually exclusive.
// If both are selected, default to 3-axis
if (feat & DMP_FEATURE_LP_QUAT)
{
feat &= ~(DMP_FEATURE_6X_LP_QUAT);
dmp_enable_lp_quat(1);
}
else if (feat & DMP_FEATURE_6X_LP_QUAT)
dmp_enable_6x_lp_quat(1);
if (feat & DMP_FEATURE_GYRO_CAL)
dmp_enable_gyro_cal(1);
if (dmpEnableFeatures(feat) != INV_SUCCESS)
return INV_ERROR;
rate = constrain(rate, 1, 200);
if (dmpSetFifoRate(rate) != INV_SUCCESS)
return INV_ERROR;
return mpu_set_dmp_state(1);
}
inv_error_t MPU9250_DMP::dmpLoad(void)
{
return dmp_load_motion_driver_firmware();
}
unsigned short MPU9250_DMP::dmpGetFifoRate(void)
{
unsigned short rate;
if (dmp_get_fifo_rate(&rate) == INV_SUCCESS)
return rate;
return 0;
}
inv_error_t MPU9250_DMP::dmpSetFifoRate(unsigned short rate)
{
if (rate > MAX_DMP_SAMPLE_RATE) rate = MAX_DMP_SAMPLE_RATE;
return dmp_set_fifo_rate(rate);
}
inv_error_t MPU9250_DMP::dmpUpdateFifo(void)
{
short gyro[3];
short accel[3];
long quat[4];
unsigned long timestamp;
short sensors;
unsigned char more;
if (dmp_read_fifo(gyro, accel, quat, ×tamp, &sensors, &more)
!= INV_SUCCESS)
{
return INV_ERROR;
}
if (sensors & INV_XYZ_ACCEL)
{
ax = accel[X_AXIS];
ay = accel[Y_AXIS];
az = accel[Z_AXIS];
}
if (sensors & INV_X_GYRO)
gx = gyro[X_AXIS];
if (sensors & INV_Y_GYRO)
gy = gyro[Y_AXIS];
if (sensors & INV_Z_GYRO)
gz = gyro[Z_AXIS];
if (sensors & INV_WXYZ_QUAT)
{
qw = quat[0];
qx = quat[1];
qy = quat[2];
qz = quat[3];
}
time = timestamp;
return INV_SUCCESS;
}
inv_error_t MPU9250_DMP::dmpEnableFeatures(unsigned short mask)
{
unsigned short enMask = 0;
enMask |= mask;
// Combat known issue where fifo sample rate is incorrect
// unless tap is enabled in the DMP.
enMask |= DMP_FEATURE_TAP;
return dmp_enable_feature(enMask);
}
unsigned short MPU9250_DMP::dmpGetEnabledFeatures(void)
{
unsigned short mask;
if (dmp_get_enabled_features(&mask) == INV_SUCCESS)
return mask;
return 0;
}
inv_error_t MPU9250_DMP::dmpSetTap(
unsigned short xThresh, unsigned short yThresh, unsigned short zThresh,
unsigned char taps, unsigned short tapTime, unsigned short tapMulti)
{
unsigned char axes = 0;
if (xThresh > 0)
{
axes |= TAP_X;
xThresh = constrain(xThresh, 1, 1600);
if (dmp_set_tap_thresh(1<<X_AXIS, xThresh) != INV_SUCCESS)
return INV_ERROR;
}
if (yThresh > 0)
{
axes |= TAP_Y;
yThresh = constrain(yThresh, 1, 1600);
if (dmp_set_tap_thresh(1<<Y_AXIS, yThresh) != INV_SUCCESS)
return INV_ERROR;
}
if (zThresh > 0)
{
axes |= TAP_Z;
zThresh = constrain(zThresh, 1, 1600);
if (dmp_set_tap_thresh(1<<Z_AXIS, zThresh) != INV_SUCCESS)
return INV_ERROR;
}
if (dmp_set_tap_axes(axes) != INV_SUCCESS)
return INV_ERROR;
if (dmp_set_tap_count(taps) != INV_SUCCESS)
return INV_ERROR;
if (dmp_set_tap_time(tapTime) != INV_SUCCESS)
return INV_ERROR;
if (dmp_set_tap_time_multi(tapMulti) != INV_SUCCESS)
return INV_ERROR;
dmp_register_tap_cb(tap_cb);
return INV_SUCCESS;
}
unsigned char MPU9250_DMP::getTapDir(void)
{
_tap_available = false;
return tap_direction;
}
unsigned char MPU9250_DMP::getTapCount(void)
{
_tap_available = false;
return tap_count;
}
bool MPU9250_DMP::tapAvailable(void)
{
return _tap_available;
}
inv_error_t MPU9250_DMP::dmpSetOrientation(const signed char * orientationMatrix)
{
unsigned short scalar;
scalar = orientation_row_2_scale(orientationMatrix);
scalar |= orientation_row_2_scale(orientationMatrix + 3) << 3;
scalar |= orientation_row_2_scale(orientationMatrix + 6) << 6;
dmp_register_android_orient_cb(orient_cb);
return dmp_set_orientation(scalar);
}
unsigned char MPU9250_DMP::dmpGetOrientation(void)
{
return mpu9250_orientation;
}
inv_error_t MPU9250_DMP::dmpEnable3Quat(void)
{
unsigned short dmpFeatures;
// 3-axis and 6-axis quat are mutually exclusive
dmpFeatures = dmpGetEnabledFeatures();
dmpFeatures &= ~(DMP_FEATURE_6X_LP_QUAT);
dmpFeatures |= DMP_FEATURE_LP_QUAT;
if (dmpEnableFeatures(dmpFeatures) != INV_SUCCESS)
return INV_ERROR;
return dmp_enable_lp_quat(1);
}
unsigned long MPU9250_DMP::dmpGetPedometerSteps(void)
{
unsigned long steps;
if (dmp_get_pedometer_step_count(&steps) == INV_SUCCESS)
{
return steps;
}
return 0;
}
inv_error_t MPU9250_DMP::dmpSetPedometerSteps(unsigned long steps)
{
return dmp_set_pedometer_step_count(steps);
}
unsigned long MPU9250_DMP::dmpGetPedometerTime(void)
{
unsigned long walkTime;
if (dmp_get_pedometer_walk_time(&walkTime) == INV_SUCCESS)
{
return walkTime;
}
return 0;
}
inv_error_t MPU9250_DMP::dmpSetPedometerTime(unsigned long time)
{
return dmp_set_pedometer_walk_time(time);
}
float MPU9250_DMP::calcAccel(int axis)
{
return (float) axis / (float) _aSense;
}
float MPU9250_DMP::calcGyro(int axis)
{
return (float) axis / (float) _gSense;
}
float MPU9250_DMP::calcMag(int axis)
{
return (float) axis / (float) _mSense;
}
float MPU9250_DMP::calcQuat(long axis)
{
return qToFloat(axis, 30);
}
float MPU9250_DMP::qToFloat(long number, unsigned char q)
{
// unsigned long mask = 0;
// for (int i=0; i<q; i++)
// {
// mask |= (1<<i);
// }
// return (number >> q) + ((number & mask) / (float) (2<<(q-1)));
return (float)((double)number / (double)(1 << q));
}
void MPU9250_DMP::computeEulerAngles(bool degrees)
{
// float ysqr = dqy * dqy;
// float t0 = -2.0f * (ysqr + dqz * dqz) + 1.0f;
// float t1 = +2.0f * (dqx * dqy - dqw * dqz);
// float t2 = -2.0f * (dqx * dqz + dqw * dqy);
// float t3 = +2.0f * (dqy * dqz - dqw * dqx);
// float t4 = -2.0f * (dqx * dqx + ysqr) + 1.0f;
// // Keep t2 within range of asin (-1, 1)
// t2 = t2 > 1.0f ? 1.0f : t2;
// t2 = t2 < -1.0f ? -1.0f : t2;s
// pitch = asin(t2) * 2;
// roll = atan2(t3, t4);
// yaw = atan2(t1, t0);
// if (degrees)
// {
// pitch *= (180.0 / PI);
// roll *= (180.0 / PI);
// yaw *= (180.0 / PI);
// if (pitch < 0) pitch = 360.0 + pitch;
// if (roll < 0) roll = 360.0 + roll;
// if (yaw < 0) yaw = 360.0 + yaw;
// }
float dqw = qToFloat(qw, 30);
float dqx = qToFloat(qx, 30);
float dqy = qToFloat(qy, 30);
float dqz = qToFloat(qz, 30);
float norm = sqrt(dqw*dqw + dqx*dqx + dqy*dqy + dqz*dqz);
dqw = dqw/norm;
dqx = dqx/norm;
dqy = dqy/norm;
dqz = dqz/norm;
float ysqr = dqy * dqy;
// roll (x-axis rotation)
float t0 = +2.0 * (dqw * dqx + dqy * dqz);
float t1 = +1.0 - 2.0 * (dqx * dqx + ysqr);
roll = atan2(t0, t1);
// pitch (y-axis rotation)
float t2 = +2.0 * (dqw * dqy - dqz * dqx);
t2 = t2 > 1.0 ? 1.0 : t2;
t2 = t2 < -1.0 ? -1.0 : t2;
pitch = asin(t2);
// yaw (z-axis rotation)
float t3 = +2.0 * (dqw * dqz + dqx * dqy);
float t4 = +1.0 - 2.0 * (ysqr + dqz * dqz);
yaw = atan2(t3, t4);
if (degrees) // values will have +180 (right) or -180 (left)
{
pitch *= (180.0 / PI);
roll *= (180.0 / PI);
yaw *= (180.0 / PI);
// if enabled the angle will be in <0, 360>
// if (pitch < 0) pitch = 360.0 + pitch;
// if (roll < 0) roll = 360.0 + roll;
// if (yaw < 0) yaw = 360.0 + yaw;
}
}
float MPU9250_DMP::computeCompassHeading(void)
{
if (my == 0)
heading = (mx < 0) ? PI : 0;
else
heading = atan2(mx, my);
if (heading > PI) heading -= (2 * PI);
else if (heading < -PI) heading += (2 * PI);
else if (heading < 0) heading += 2 * PI;
heading*= 180.0 / PI;
return heading;
}
unsigned short MPU9250_DMP::orientation_row_2_scale(const signed char *row)
{
unsigned short b;
if (row[0] > 0)
b = 0;
else if (row[0] < 0)
b = 4;
else if (row[1] > 0)
b = 1;
else if (row[1] < 0)
b = 5;
else if (row[2] > 0)
b = 2;
else if (row[2] < 0)
b = 6;
else
b = 7; // error
return b;
}
static void tap_cb(unsigned char direction, unsigned char count)
{
_tap_available = true;
tap_count = count;
tap_direction = direction;
}
static void orient_cb(unsigned char orient)
{
mpu9250_orientation = orient;
}
//=================
#define BIT_DMP_RST (0x08)
// static long gyro_bias[] = {-206654,-8404381,-67672};
static long gyro_bias[] = {0,0,0};
void MPU9250_DMP::resetDMPgyro(long* out)
{
// unsigned char data = 0;
// data = BIT_DMP_RST;
// mpu_write_reg(106, &data); //USER_CTRL register
//dmp_set_gyro_bias(gyro_bias);
int result;
static long gyro[3], accel[3];
result = mpu_run_self_test(gyro, accel);
if (result == 0x7) {
/* Test passed. We can trust the gyro data here, so let's push it down
* to the DMP.
*/
float sens;
unsigned short accel_sens;
mpu_get_gyro_sens(&sens);
gyro[0] = (long)(gyro[0] * sens);
gyro[1] = (long)(gyro[1] * sens);
gyro[2] = (long)(gyro[2] * sens);
dmp_set_gyro_bias(gyro);
mpu_get_accel_sens(&accel_sens);
accel[0] *= accel_sens;
accel[1] *= accel_sens;
accel[2] *= accel_sens;
dmp_set_accel_bias(accel);
}
out = gyro;
}
int MPU9250_DMP::dmpState(unsigned char enable)
{
mpu_set_dmp_state(enable);
}
//=================