-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTBVC_XY-rtheta_Gyro_PID_BLUE_HEXAGON.ino
803 lines (695 loc) · 19 KB
/
TBVC_XY-rtheta_Gyro_PID_BLUE_HEXAGON.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
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
790
791
792
793
794
795
796
797
798
799
800
801
802
803
/*
* Author List : Kaiwalya Belsare, Sarang Badgujar , Avinash Kangare, Pratik Gaikwad
* Filename : TBVC_XY-rtheta_Gyro_PID_BLUETOOTH
* Functions : void go_forward(int fpwm)
* void go_forward_PID(int xpwm)
* void brake()
* void linear_distance_cm(unsigned int DistanceInCM)
* void doEncoder_L()
* void doEncoder_R()
* void InitEncoder()
* void left_sharp()
* void right_sharp()
* void pins()
* void angle_rotate(unsigned int Degrees)
* void rot_left_till(int ang)
* void count_zero()
* void go_forward_till(int x)
* void only_straight(int d)
* void rot_right_till(int ang)
* void gyro()
* void InitGyro()
* void gotoxy_r_theta(int x,int y)
* void gotoxy_XY(int x,int y)
* void setup()
* void loop()
* Variables :
long unsigned int Count_L=0, Count_R=0;
int i=0,z = 0,angle=0,d=0,L_pwm = 87,R_pwm = 80;
float dist_L = 0,dist_R = 0,dist_av = 0;
int arg_pwm = 100,arg_spwm = 20;
char q;
int h,yaw=0,theta=0,ros;
float vel_R,vel_L;
double hyp = 0, pro =0 ,sq_side;
int zom=0,u=0;
int valy, tempy;
int valp, tempp;
int valr, tempr;
int flag = 0;
*/
#include <I2Cdev.h>
#include <PID_v1.h>
double Setpoint, Input, Output, control;
double Kp = 11, Ki = 0.2, Kd = 0.0;
PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);
//Right Motor Encoder
#define Encoder_La 3 ////interrupt 1
#define Encoder_Lb 32
//Left Motor Encoder
#define Encoder_Ra 2 ////interrupt 0
#define Encoder_Rb 30
//Right Motor
#define motorRdir 42
#define motorRpwm 44 //OC5C
//Left Motor
#define motorLdir 48
#define motorLpwm 46 //OC5A
#define PPR 1120
#define DIAMETER 11.0
#define circum PI*DIAMETER
#define WIDTH 23.0
long unsigned int Count_L=0, Count_R=0;
int i=0,z = 0,angle=0,d=0,L_pwm = 87,R_pwm = 80;
float dist_L = 0,dist_R = 0,dist_av = 0;
int arg_pwm = 100,arg_spwm = 20;
char q;
int h,yaw=0,theta=0,ros,hex_side;
float vel_R,vel_L;
double hyp = 0, pro =0 ;
int zom=0,u=0;
int valy, tempy;
int valp, tempp;
int valr, tempr;
int flag = 0;
#include "I2Cdev.h"
#include "MPU6050_6Axis_MotionApps20.h"
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
#include "Wire.h"
#endif
MPU6050 mpu;
#define OUTPUT_READABLE_YAWPITCHROLL
#define LED_PIN 13 // (Arduino is 13, Teensy is 11, Teensy++ is 6)
bool blinkState = false;
// MPU control/status vars
bool dmpReady = false; // set true if DMP init was successful
uint8_t mpuIntStatus; // holds actual interrupt status byte from MPU
uint8_t devStatus; // return status after each device operation (0 = success, !0 = error)
uint16_t packetSize; // expected DMP packet size (default is 42 bytes)
uint16_t fifoCount; // count of all bytes currently in FIFO
uint8_t fifoBuffer[64]; // FIFO storage buffer
// orientation/motion vars
Quaternion m; // [w, x, y, z] quaternion container
VectorFloat gravity; // [x, y, z] gravity vector
float ypr[3]; // [yaw, pitch, roll] yaw/pitch/roll container and gravity vector
volatile bool mpuInterrupt = false; // indicates whether MPU interrupt pin has gone high
void dmpDataReady()
{
mpuInterrupt = true;
}
/*
* Function Name: setup
* Input: none
* Output: none
* Logic: initiates all functions and executes once.
* Example call: void setup();
*/
void setup()
{
Serial2.begin(9600);
Serial.begin(9600);
InitGyro();
InitEncoder();
myPID.SetMode(AUTOMATIC);
myPID.SetOutputLimits(-120, 120);
Setpoint = 0.00;
myPID.SetSampleTime(100);
pins();
attachInterrupt(1,doEncoder_L,RISING);
attachInterrupt(0,doEncoder_R,RISING);
}
/*
* Function Name: go_forward(int fpwm)
* Input: pwm in integer
* Output: none
* Logic: traverses in forward direction with no feedback.
* Example call: void go_forward(int fpwm);
*/
void go_forward(int fpwm)
{
digitalWrite(motorRdir,LOW);
digitalWrite(motorLdir,LOW);
analogWrite(motorRpwm,fpwm);
analogWrite(motorLpwm,fpwm*1.08);
}
/*
* Function Name: go_forward_PID(int xpwm)
* Input: pwm in integer
* Output: none
* Logic: traverses in forward direction with gyro correction with PID
* Example call: void go_forward_PID(int xpwm);
*/
void go_forward_PID(int xpwm)
{
myPID.Compute();
if (Output < 0)
{
digitalWrite(motorRdir,LOW);
digitalWrite(motorLdir,LOW);
analogWrite(motorRpwm,xpwm- Output);
analogWrite(motorLpwm,xpwm*1.08 );
}
else if (Output > 0)
{
digitalWrite(motorRdir,LOW);
digitalWrite(motorLdir,LOW);
analogWrite(motorRpwm,xpwm );
analogWrite(motorLpwm,(xpwm*1.08)+ Output);
}
else
{
digitalWrite(motorRdir,LOW);
digitalWrite(motorLdir,LOW);
analogWrite(motorRpwm,xpwm);
analogWrite(motorLpwm,xpwm*1.08);
}
}
/*
* Function Name: brake
* Input: none
* Output: none
* Logic: brakes the bot
* Example call: void brake();
*/
void brake()
{
digitalWrite(motorRdir,HIGH);
digitalWrite(motorLdir,HIGH);
analogWrite(motorRpwm,0);
analogWrite(motorLpwm,0);
}
/*
* Function Name: linear_distance_cm
* Input: distance in cm in integer
* Output: none
* Logic: robot travels the specified distance taking feedback from encoders.
* Example call: linear_distance_cm(100);
*/
void linear_distance_cm(unsigned int DistanceInCM)
{
float ReqdShaftCount = 0;
unsigned long int ReqdShaftCountInt = 0;
ReqdShaftCount = DistanceInCM*31.0; // division by resolution to get shaft count
ReqdShaftCountInt = (unsigned long int) ReqdShaftCount;
Count_L = 0;
Count_R = 0;
while(1)
{
delay(1);
if((Count_L+Count_R)*0.5 > ReqdShaftCountInt)
{break;}
}
brake(); //Stop robot
}
/*
* Function Name: doEncoder_L
* Input: none
* Output: none
* Logic: increments a variable for left encoder
* Example call: attachInterrupt(0,doEncoder_L,FALLING);
*/
void doEncoder_L()
{
Count_L++;
/*if(digitalRead(Encoder_La) && !digitalRead(Encoder_Lb))
{
Count_L --; //CCW for encoder shaft
}
if(digitalRead(Encoder_La) && digitalRead(Encoder_Lb))
{
Count_L ++; //CW for encoder shaft
}*/
}
/*
* Function Name: doEncoder_R
* Input: none
* Output: none
* Logic: increments a variable for left encoder
* Example call: attachInterrupt(0,doEncoder_R,FALLING);
*/
void doEncoder_R()
{
Count_R++;
/*if(digitalRead(Encoder_Ra) && !digitalRead(Encoder_Rb))
{
Count_R--;
//CCW for encoder shaft
}
if(digitalRead(Encoder_Ra) && digitalRead(Encoder_Rb))
{
Count_R++; //CW for encoder shaft
}*/
}
/*
* Function Name: InitEncoder
* Input: none
* Output: none
* Logic: Set encoder pins as input and pull up interrupt pins
* Example call: void InitEncoder();
*/
void InitEncoder()
{
pinMode(Encoder_La,INPUT);
pinMode(Encoder_Ra,INPUT);
pinMode(Encoder_Lb,INPUT);
pinMode(Encoder_Rb,INPUT);
digitalWrite(Encoder_La, HIGH);
digitalWrite(Encoder_Ra, HIGH);
}
/*
* Function Name: left_sharp
* Input: none
* Output: none
* Logic: turn left sharply
* Example call: void left_sharp();
*/
void left_sharp()
{
digitalWrite(motorRdir,LOW);
digitalWrite(motorLdir,HIGH);
analogWrite(motorRpwm,arg_spwm);
analogWrite(motorLpwm,arg_spwm);
}
/*
* Function Name: right_sharp
* Input: none
* Output: none
* Logic: turn right sharply
* Example call: void right_sharp();
*/
void right_sharp()
{
digitalWrite(motorRdir,HIGH);
digitalWrite(motorLdir,LOW);
analogWrite(motorRpwm,arg_spwm);
analogWrite(motorLpwm,arg_spwm);
}
/*
* Function Name: pins
* Input: none
* Output: none
* Logic: sets pins as input or output
* Example call: void pins();
*/
void pins()
{
pinMode(motorRpwm,OUTPUT); //motor1 pwm
pinMode(motorRdir,OUTPUT); //motor1 dir
pinMode(motorLpwm,OUTPUT); //motor2 pwm
pinMode(motorLdir,OUTPUT); //motor2 dir
}
/*
* Function Name: angle_rotate
* Input: degrees in integer
* Output: none
* Logic: robot rotates till input degrees taking feedback from encoders.
* Example call: angle_rotate(90);
*/
void angle_rotate(unsigned int Degrees)
{
float ReqdShaftCount = 0;
unsigned long int ReqdShaftCountInt = 0;
ReqdShaftCount = (float) Degrees* 6.1; // division by resolution to get shaft count
ReqdShaftCountInt = (unsigned int) ReqdShaftCount;
Count_L = 0;
Count_R = 0;
while (true)
{
delay(1);
if((Count_L >= ReqdShaftCountInt) | (Count_R >= ReqdShaftCountInt))
{break;}
}
brake(); //Stop robot
}
/*
* Function Name: rot_left_till(int ang)
* Input: degrees in integer
* Output: none
* Logic: robot rotates left until a certain angle.
* Example call: void rot_left_till(90);
*/
void rot_left_till(int ang)
{
left_sharp();
angle_rotate(ang);
}
/*
* Function Name: count_zero()
* Input: degrees in integer
* Output: none
* Logic: sets counts of right and left encoder to zero
* Example call: void count_zero();
*/
void count_zero()
{
Count_L = 0;
Count_R = 0;
dist_L = 0;
dist_R = 0;
dist_av = 0;
}
/*
* Function Name: loop
* Input: none
* Output: none
* Logic: loops all functions written in while(1) fashion.
* Example call: void loop();
*/
void loop()
{
dist_L = (((float)Count_L/PPR))*circum;
dist_R = (((float)Count_R/PPR))*circum;
dist_av = (0.5*(dist_L + dist_R));
Serial.print(dist_L);
Serial.print("\t");
Serial.println(dist_R);
gyro();
if(ros==0)
{
gyro();
if(Serial2.available() > 0)
{
hex_side = Serial2.read(); //read side in cms
Serial.println(hex_side);
while(dist_av < hex_side)//1
{
gyro();
dist_L = (((float)Count_L/PPR))*circum;
dist_R = (((float)Count_R/PPR))*circum;
dist_av = (0.5*(dist_L + dist_R));
if(zom==0)
{
for(u=0; u < arg_pwm ;u++)
{
go_forward(u);
}
zom++;}
go_forward_PID(arg_pwm);
}
brake();
Serial.println(dist_av);
delay(1000);
rot_right_till(60);
delay(1000);
count_zero();
Serial.println(dist_av);
Setpoint = 60;//2
while(dist_av < hex_side)//2
{
gyro();
dist_L = (((float)Count_L/PPR))*circum;
dist_R = (((float)Count_R/PPR))*circum;
dist_av = (0.5*(dist_L + dist_R));
if(zom==0)
{
for(u=0; u < arg_pwm ;u++)
{
go_forward(u);
}
zom++;}
go_forward_PID(arg_pwm);
}
brake();
delay(1000);
rot_right_till(60);
delay(1000);
count_zero();
Serial.println(dist_av);
Setpoint = 120;//3
while(dist_av < hex_side)//3
{
gyro();
dist_L = (((float)Count_L/PPR))*circum;
dist_R = (((float)Count_R/PPR))*circum;
dist_av = (0.5*(dist_L + dist_R));
if(zom==0)
{
for(u=0; u < arg_pwm ;u++)
{
go_forward(u);
}
zom++;}
go_forward_PID(arg_pwm);
}
brake();
delay(1000);
rot_right_till(60);
Setpoint = -180;//4
delay(1000);
count_zero();
while(dist_av < hex_side)//4
{
gyro();
dist_L = (((float)Count_L/PPR))*circum;
dist_R = (((float)Count_R/PPR))*circum;
dist_av = (0.5*(dist_L + dist_R));
if(zom==0)
{
for(u=0; u < arg_pwm ;u++)
{
go_forward(u);
}
zom++;}
go_forward_PID(arg_pwm);
}
brake();
delay(1000);
rot_right_till(60);
brake();
delay(1000);
Setpoint = -120;//5
count_zero();
while(dist_av < hex_side)//5
{
gyro();
dist_L = (((float)Count_L/PPR))*circum;
dist_R = (((float)Count_R/PPR))*circum;
dist_av = (0.5*(dist_L + dist_R));
if(zom==0)
{
for(u=0; u < arg_pwm ;u++)
{
go_forward(u);
}
zom++;}
go_forward_PID(arg_pwm);
}
brake();
delay(1000);
rot_right_till(60);
brake();
delay(1000);
count_zero();
Setpoint = -60;//6
while(dist_av < hex_side)//6
{
gyro();
dist_L = (((float)Count_L/PPR))*circum;
dist_R = (((float)Count_R/PPR))*circum;
dist_av = (0.5*(dist_L + dist_R));
if(zom==0)
{
for(u=0; u < arg_pwm ;u++)
{
go_forward(u);
}
zom++;}
go_forward_PID(arg_pwm);
}
brake();
delay(3000);
rot_right_till(60);
brake();
}
ros++;
}
brake();
}
/*
* Function Name: go_forward_till(int x)
* Input: distance(cms) in integer
* Output: none
* Logic: goes forward only till specified distance with feedback from encoder
* Example call: void go_forward_till(int x);
*/
void go_forward_till(int x)
{
go_forward(100);
linear_distance_cm(x);
}
/*
* Function Name: only_straight(int d)
* Input: distance(cms) in integer
* Output: none
* Logic: goes forward only till specified distance by taking gyro correction
* Example call: void only_straight(int d);
*/
void only_straight(int d)
{
int m=0,u=0;
while( dist_av < d )
{
gyro();
dist_L = (((float)Count_L/PPR))*circum;
dist_R = (((float)Count_R/PPR))*circum;
dist_av = (0.5*(dist_L + dist_R));
if(m == 0){
for(u=0; u <= arg_pwm ;u++)
{
go_forward(u);
delay(20);
}
m++;
}
go_forward_PID(arg_pwm);
//Serial.print(dist_av);
//Serial.print('\t');
//Serial.println(Output);
}
}
/*
* Function Name: rot_right_till(int ang)
* Input: degrees in integer
* Output: none
* Logic: robot rotates right until a certain angle.
* Example call: void rot_right_till(int ang);
*/
void rot_right_till(int ang)
{
right_sharp();
angle_rotate(ang);
}
/*
* Function Name: gyro
* Input: none
* Output: none
* Logic: computes readings of gyroscope
* Example call: void gyro();
*/
void gyro()
{
//////////////////////////////Gyro initialisation starts
// if programming failed, don't try to do anything
if (!dmpReady) return;
// wait for MPU interrupt or extra packet(s) available
while (!mpuInterrupt && fifoCount < packetSize) {}
// reset interrupt flag and get INT_STATUS byte
mpuInterrupt = false;
mpuIntStatus = mpu.getIntStatus();
// get current FIFO count
fifoCount = mpu.getFIFOCount();
// check for overflow (this should never happen unless our code is too inefficient)
if ((mpuIntStatus & 0x10) || fifoCount == 1024) {
// reset so we can continue cleanly
mpu.resetFIFO();
Serial.println(F("FIFO overflow!"));
// otherwise, check for DMP data ready interrupt (this should happen frequently)
} else if (mpuIntStatus & 0x02) {
// wait for correct available data length, should be a VERY short wait
while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();
// read a packet from FIFO
mpu.getFIFOBytes(fifoBuffer, packetSize);
// track FIFO count here in case there is > 1 packet available
// (this lets us immediately read more without waiting for an interrupt)
fifoCount -= packetSize;
#ifdef OUTPUT_READABLE_YAWPITCHROLL
// display Euler angles in degrees
mpu.dmpGetQuaternion(&m, fifoBuffer);
mpu.dmpGetGravity(&gravity, &m);
mpu.dmpGetYawPitchRoll(ypr, &m, &gravity);
// Serial.print("ypr\t");
// Serial.print(ypr[0] * 180/M_PI);
// Serial.print("\t");
// Serial.print(ypr[1] * 180/M_PI);
// Serial.print("\t");
// Serial.println(ypr[2] * 180/M_PI);
#endif
// blink LED to indicate activity
blinkState = !blinkState;
digitalWrite(LED_PIN, blinkState);
}
if (flag < 3)
{
tempy = (ypr[0] * 180 / M_PI);
tempp = (ypr[1] * 180 / M_PI);
tempr = (ypr[2] * 180 / M_PI);
flag++;
Input = tempy;
yaw = tempy;
Serial.print(tempy); Serial.print("\t");
//Serial.print(tempp);Serial.print("\t");
//Serial.print(tempr);Serial.println("");
}
else
{
valy = (ypr[0] * 180 / M_PI);
valy = valy - tempy;
valp = (ypr[1] * 180 / M_PI);
valp = valp - tempp;
valr = (ypr[2] * 180 / M_PI);
valr = valr - tempr;
Input = valy;
yaw = valy;
Serial.print(valy); Serial.print("\t");
//Serial.print(valp);Serial.print("\t");
//Serial.print(valr);Serial.println("");
}
}
/*
* Function Name: gotoxy_r_theta(int x,int y)
* Input: x,y (cms) in integers
* Output: none
* Logic: traverses to particular point using r-theta method
* Example call: void gotoxy_r_theta(int x,int y);
*/
void InitGyro()
{
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
Wire.begin();
TWBR = 24; // 400kHz I2C clock (200kHz if CPU is 8MHz)
#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
Fastwire::setup(400, true);
#endif
Serial.begin(115200);
while (!Serial); // wait for Leonardo enumeration, others continue immediately
Serial.println(F("Initializing I2C devices..."));
mpu.initialize();
// verify connection
Serial.println(F("Testing device connections..."));
Serial.println(mpu.testConnection() ? F("MPU6050 connection successful") : F("MPU6050 connection failed"));
// wait for ready
//Serial.println(F("\nSend any character to begin DMP programming and demo: "));
//while (Serial.available() && Serial.read()); // empty buffer
//while (!Serial.available()); // wait for data
//while (Serial.available() && Serial.read()); // empty buffer again
// load and configure the DMP
Serial.println(F("Initializing DMP..."));
devStatus = mpu.dmpInitialize();
// supply your own gyro offsets here, scaled for min sensitivity
mpu.setXGyroOffset(220);
mpu.setYGyroOffset(76);
mpu.setZGyroOffset(-85);
mpu.setZAccelOffset(1788); // 1688 factory default for my test chip
// make sure it worked (returns 0 if so)
if (devStatus == 0) {
// turn on the DMP, now that it's ready
//Serial.println(F("Enabling DMP..."));
mpu.setDMPEnabled(true);
// enable Arduino interrupt detection
//Serial.println(F("Enabling interrupt detection (Arduino external interrupt 0)..."));
attachInterrupt(4, dmpDataReady, RISING);
mpuIntStatus = mpu.getIntStatus();
// set our DMP Ready flag so the main loop() function knows it's okay to use it
//Serial.println(F("DMP ready! Waiting for first interrupt..."));
dmpReady = true;
// get expected DMP packet size for later comparison
packetSize = mpu.dmpGetFIFOPacketSize();
} else {
Serial.print(F("DMP Initialization failed (code "));
Serial.print(devStatus);
Serial.println(F(")"));
}
// configure LED for output
pinMode(LED_PIN, OUTPUT);
delay(20000);
}