-
Notifications
You must be signed in to change notification settings - Fork 0
/
CoDrone_send.cpp
1088 lines (942 loc) · 24.6 KB
/
CoDrone_send.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
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "CoDrone.h"
#include "Arduino.h"
#include <EEPROM.h>
//-------------------------------------------------------------------------------------------------------//
//------------------------------------------ Command ----------------------------------------------------//
//-------------------------------------------------------------------------------------------------------//
void CoDroneClass::Send_Command(int sendCommand, int sendOption)
{
byte _packet[9];
byte _crc[2];
byte _cType = dType_Command;
byte _len = 0x02;
//header
_packet[0] = _cType;
_packet[1] = _len;
//data
_packet[2] = sendCommand;
_packet[3] = sendOption;
unsigned short crcCal = CRC16_Make(_packet, _len+2);
_crc[0] = (crcCal >> 8) & 0xff;
_crc[1] = crcCal & 0xff;
Send_Processing(_packet,_len,_crc);
}
void CoDroneClass::Send_Processing(byte _data[], byte _length, byte _crc[])
{
delay(50);
sendingData = true; //data sending start
byte _packet[30];
//START CODE
_packet[0] = START1;
_packet[1] = START2;
//HEADER & DATA
for(int i = 0; i < _length + 3 ; i++) _packet[i+2] = _data[i];
//CRC
_packet[_length + 4] =_crc[1];
_packet[_length + 5] =_crc[0];
if(sendDataControl == true) DRONE_SERIAL.write(_packet, _length + 6); //data send control
#if defined(DEBUG_MODE_ENABLE)
DEBUG_SERIAL.print("> SEND : ");
for(int i = 0; i < _length+6 ; i++)
{
DEBUG_SERIAL.print(_packet[i],HEX);
DEBUG_SERIAL.print(" ");
}
DEBUG_SERIAL.println("");
#endif
sendingData = false; //data sending end
}
void CoDroneClass::Send_Check(byte _data[], byte _length, byte _crc[])
{
if(sendCheckFlag == 1)
{
timeOutSendPreviousMillis = millis();
while(sendCheckFlag != 3)
{
while(!TimeOutSendCheck(SEND_CHECK_TIME))
{
Receive();
if(sendCheckFlag == 3) break;
}
if(sendCheckFlag == 3) break;
if(sendCheckCount == 3) break; //check count
Send_Processing(_data,_length,_crc);
sendCheckCount++;
}
sendCheckFlag = 0;
sendCheckCount = 0;
}
}
//-------------------------------------------------------------------------------------------------------//
//-------------------------------------------------------------------------------------------------------//
//--------------------------------------------- Send ----------------------------------------------------//
//-------------------------------------------------------------------------------------------------------//
void CoDroneClass::Send_Coordinate(byte mode)
{
if(mode == cSet_Absolute) Send_Command(cType_Coordinate, cSet_Absolute);
else if(mode == cSet_Relative) Send_Command(cType_Coordinate, cSet_Relative);
}
void CoDroneClass::Send_ClearGyroBiasAndTrim()
{
sendCheckFlag = 1;
Send_Command(cType_ClearGyroBiasAndTrim, 0);
}
void CoDroneClass::Send_ResetHeading()
{
Send_Command(cType_ResetHeading, 0);
}
void CoDroneClass::disconnect()
{
Send_Command(cType_LinkDisconnect, 0);
}
//-------------------------------------------------------------------------------------------------------//
//-------------------------------------------------------------------------------------------------------//
//----------------------------------------- Drone Event -------------------------------------------------//
//-------------------------------------------------------------------------------------------------------//
void CoDroneClass::DroneModeChange(byte event)
{
sendCheckFlag = 1;
Send_Command(cType_ModeDrone, event);
delay(300);
}
void CoDroneClass::FlightEvent(byte event)
{
sendCheckFlag = 1;
Send_Command(cType_FlightEvent, event);
}
void CoDroneClass::DriveEvent(byte event)
{
Send_Command(cType_DriveEvent, event);
}
//-------------------------------------------------------------------------------------------------------//
//-------------------------------------------------------------------------------------------------------//
//----------------------------------------- Flight Evnet -------------------------------------------------//
//-------------------------------------------------------------------------------------------------------//
/*
* function : takeOff()
* description : takeOff() make the drone take off when drone is ready.
* If drone is upside down, it will do turtle turn instead of take off.
* param : none
* return : none
*/
void CoDroneClass::takeoff()
{
CoDrone.Buzz(440,16);
sendCheckFlag = 1;
Send_Command(cType_FlightEvent, TakeOff);
delay(3000);
CoDrone.Buzz(440,16);
}
/*
* function : land()
* description : land() make the drone landing.
* Drone will going down and when drone is get close to floor, it will shut down motors.
* param : none
* return : none
*/
void CoDroneClass::land()
{
sendCheckFlag = 1;
Send_Command(cType_FlightEvent, Landing);
for(int i=0; i<400; i=i+15)
CoDrone.Buzz(700-i,20);
setRoll(0);
setPitch(0);
setYaw(0);
setThrottle(0);
}
/*
* function : emargencyStop()
* description : emargencyStop() shut down the power of motors imediately.
* Use this function for kill switch.
* param : none
* return : none
*/
void CoDroneClass::emergencyStop()
{
CoDrone.FlightEvent(Stop);
for(int i=0;i<3;i++){
CoDrone.Buzz(440,16);
CoDrone.Buzz(330,16);
CoDrone.Buzz(220,16);
}
setRoll(0);
setPitch(0);
setYaw(0);
setThrottle(0);
}
//-------------------------------------------------------------------------------------------------------//
//-------------------------------------------- Trim -----------------------------------------------------//
//-------------------------------------------------------------------------------------------------------//
void CoDroneClass::Set_Trim(byte event)
{
sendCheckFlag = 1;
Send_Command(cType_Trim, event);
}
void CoDroneClass::Set_TrimReset()
{
Set_TrimFlight(0, 0, 0, 0);
}
void CoDroneClass::Set_TrimFlight(int _roll, int _pitch, int _yaw, int _throttle)
{
sendCheckFlag = 1;
byte _packet[10];
byte _crc[2];
byte _cType = dType_TrimFlight;
byte _len = 8;
//header
_packet[0] = _cType;
_packet[1] = _len;
byte L_roll = _roll & 0xff;
byte H_roll = (_roll >> 8) & 0xff;
byte L_pitch = _pitch & 0xff;
byte H_pitch = (_pitch >> 8) & 0xff;
byte L_yaw = _yaw & 0xff;
byte H_yaw = (_yaw >> 8) & 0xff;
byte L_throttle = _throttle & 0xff;
byte H_throttle = (_throttle >> 8) & 0xff;
//data
_packet[2] = L_roll;
_packet[3] = H_roll;
_packet[4] = L_pitch;
_packet[5] = H_pitch;
_packet[6] = L_yaw;
_packet[7] = H_yaw;
_packet[8] = L_throttle;
_packet[9] = H_throttle;
unsigned short crcCal = CRC16_Make(_packet, _len + 2);
_crc[0] = (crcCal >> 8) & 0xff;
_crc[1] = crcCal & 0xff;
Send_Processing(_packet,_len,_crc);
}
//-------------------------------------------------------------------------------------------------------//
//------------------------------------------- Control ---------------------------------------------------//
//-------------------------------------------------------------------------------------------------------//
void CoDroneClass::Control(int interval)
{
if (TimeCheck(interval)) //delay
{
Control();
PreviousMillis = millis();
}
}
void CoDroneClass::Control()
{
byte _packet[10];
byte _crc[2];
byte _cType = dType_Control;
byte _len = 4;
//header
_packet[0] = _cType;
_packet[1] = _len;
//data
_packet[2] = roll;
_packet[3] = pitch;
_packet[4] = yaw;
_packet[5] = throttle;
unsigned short crcCal = CRC16_Make(_packet, _len+2);
_crc[0] = (crcCal >> 8) & 0xff;
_crc[1] = crcCal & 0xff;
Send_Processing(_packet,_len,_crc);
}
/*
* function : move()
* description : move() function is using global variables to control drone .
* Drone will move with roll, pitch, yaw, throttle value infinitely.
* If you wanna set variable's value, use setter function.
* if you wanna check variable's value, use getter function.
*
* param : none
* return : none
*/
void CoDroneClass::move(){
// delay(50);
byte _packet[10];
byte _crc[2];
/*
header + data
data type = Control(_packet[0])
data length = (_packet[1])
*/
//header
_packet[0] = dType_Control;
_packet[1] = 4;
//data
_packet[2] = roll;
_packet[3] = pitch;
_packet[4] = yaw;
_packet[5] = throttle;
unsigned short crcCal = CRC16_Make(_packet, _packet[1]+2);
_crc[0] = (crcCal >> 8) & 0xff;
_crc[1] = crcCal & 0xff;
//send control message to drone(write serial)
Send_Processing(_packet,_packet[1],_crc);
}
/*
* function : move(duration)
* description : move(duration) is extend function of move() for limit moving time.
Also instead of send command once, function will send every 100ms during duration time.
* Parameter "duration" will be set the timer for control drone.
*
*
* param :
- duration : float
* return : none
*/
void CoDroneClass::move(float duration)
{
//set the timer with duration.
// duration have to convert second to millisecond
unsigned long startMillis = millis();
while(millis() - startMillis < duration*1000)
{
move();
//gap for command sending
delay(50);
}
hover(1);
}
/*
* function : move(roll, pitch, yaw, throttle)
* description : move(roll, pitch, yaw, throttle) is extend function of move() for set instance values for control.
* Parameter "roll, pitch, yaw, throttle " are one time value for control.
*
* param :
* - roll : int
* - pitch : int
* - yaw : int
* - throttle : int
* return : none
*/
void CoDroneClass::move(int _roll, int _pitch, int _yaw, int _throttle)
{
delay(50);
byte _packet[10];
byte _crc[2];
/*
header + data
data type = Control(_packet[0])
data length = (_packet[1])
*/
//header
_packet[0] = dType_Control;
_packet[1] = 4;
//data
_packet[2] = _roll;
_packet[3] = _pitch;
_packet[4] = _yaw;
_packet[5] = _throttle;
unsigned short crcCal = CRC16_Make(_packet, _packet[1]+2);
_crc[0] = (crcCal >> 8) & 0xff;
_crc[1] = crcCal & 0xff;
Send_Processing(_packet,_packet[1],_crc);
}
/*
* function : move(duration, roll, pitch, yaw, throttle)
* description : move(duration, roll, pitch, yaw, throttle) is extend function of move() for set instance values for control.
* Parameter "duration" will be set the timer for control drone.
* Parameter "roll, pitch, yaw, throttle " are one time value for control.
*
* param :
* - duration : float
* - roll : int
* - pitch : int
* - yaw : int
* - throttle : int
* return : none
*/
void CoDroneClass::move(float duration, int _roll, int _pitch, int _yaw, int _throttle)
{
unsigned long startMillis = millis();
while(millis() - startMillis < duration*1000)
{
move(_roll, _pitch, _yaw, _throttle);
delay(50);
}
hover(1);
}
/*
* function : go(direction)
* description : go(direction) is simple version of move function.
* Instead of using "roll, pitch, yaw throttle", using direction for control drone.
* Parameter "direction" is enum for set direction.
* Power will be set 50% defualt, It will move infinitely.
*
* param :
* - direction : int
* return : none
*/
void CoDroneClass::go(int direction)
{
int r,p,t;
r = p = t = 0;
switch(direction)
{
case direction_forward:
p = 50;
break;
case direction_up:
t = 50;
break;
case direction_right:
r = 50;
break;
case direction_backward:
p = -50;
break;
case direction_down:
t = -50;
break;
case direction_left:
r = -50;
break;
}
move(r,p,0,t);
unsigned long startMillis = millis();
while(millis() - startMillis < 1000)
{
move(r,p,0,t);
delay(50);
}
hover(1);
}
/*
* function : go(direction, duration)
* description : go(direction, duration) adding duration parameter to go(direction)
* Parameter "direction" is enum for set direction.
* Parameter "duration" will be set the timer for control drone.
* Power will be set 50% defualt.
*
* param :
* - direction : int
* - duration : float
* return : none
*/
void CoDroneClass::go(int direction, float duration)
{
int r,p,t;
r = p = t = 0;
switch(direction)
{
case direction_forward:
p = 50;
break;
case direction_up:
t = 50;
break;
case direction_right:
r = 50;
break;
case direction_backward:
p = -50;
break;
case direction_down:
t = -50;
break;
case direction_left:
r = -50;
break;
}
move(r,p,0,t);
unsigned long startMillis = millis();
while(millis() - startMillis < duration*1000)
{
move(r,p,0,t);
delay(50);
}
if(duration != 0)
hover(1);
}
/*
* function : go(direction, duration, power)
* description : go(direction, duration, power) adding duration and power parameter to go(direction)
* Parameter "direction" is enum for set direction.
* Parameter "duration" will be set the timer for control drone.
* Parameter "power" will be set the movement power. (0 ~ 100)
*
* param :
* - direction : int
* - duration : float
* - power : int
* return : none
*/
void CoDroneClass::go(int direction, float duration, int power)
{
int r,p,t;
r = p = t = 0;
switch(direction)
{
case direction_forward:
p = power;
break;
case direction_up:
t = power;
break;
case direction_right:
r = power;
break;
case direction_backward:
p = (-1)*power;
break;
case direction_down:
t = (-1)*power;
break;
case direction_left:
r = (-1)*power;
break;
}
unsigned long startMillis = millis();
while(millis() - startMillis < duration*1000)
{
move(r,p,0,t);
delay(50);
}
if(duration != 0)
hover(1);
}
/*
* function : turn(direction)
* description : turn(direction) is function for turn left or right infinitely
* Parameter "direction" is enum for set direction.
*
* param :
* - direction : int
* return : none
*/
void CoDroneClass::turn(int direction)
{
int y = 0;
if (direction == direction_right)
y = 50;
else if (direction_left)
y = -50;
move(0,0,y,0);
unsigned long startMillis = millis();
while(millis() - startMillis < 1000)
{
move(0,0,y,0);
delay(100);
}
hover(1);
}
/*
* function : turn(direction, duration)
* description : turn(direction, duration) adding duration to for turn(direction)
* Parameter "direction" is enum for set direction.
* Parameter "duration" will be set the timer for control drone.
*
* param :
* - direction : int
* - duration : float
* return : none
*/
void CoDroneClass::turn(int direction, float duration)
{
int y = 0;
if (direction == direction_right)
y = 50;
else if (direction_left)
y = -50;
move(0,0,y,0);
unsigned long startMillis = millis();
while(millis() - startMillis < duration*1000)
{
move(0,0,y,0);
delay(50);
}
if(duration != 0)
hover(1);
}
/*
* function : turn(direction, duration, power)
* description : turn(direction, duration, power) adding duration and power parameter to turn(direction)
* Parameter "direction" is enum for set direction.
* Parameter "duration" will be set the timer for control drone.
* Parameter "power" will be set the movement power. (0 ~ 100)
*
* param :
* - direction : int
* - duration : float
* - power : int
* return : none
*/
void CoDroneClass::turn(int direction, float duration, int power)
{
int y = power ;
if(direction == direction_left)
y *= -1;
unsigned long startMillis = millis();
while(millis() - startMillis < duration*1000)
{
move(0,0,y,0);
delay(50);
}
if(duration != 0)
hover(1);
}
/*
* function : hover(duration)
* description : hover(duration) is make drone hover when drone get this message for duration.
* Parameter "duration" will be set the timer for control drone.
*
* param :
* - duration : float
* return : none
*/
void CoDroneClass::hover(float duration)
{
move(0,0,0,0);
delay(50);
unsigned long startMillis = millis();
while(millis() - startMillis < duration*1000)
{
move(0,0,0,0);
delay(50);
}
}
//-------------------------------------------------------------------------------------------------------//
//-------------------------------------------------------------------------------------------------------//
//-------------------------------------------- Move -----------------------------------------------------//
//-------------------------------------------------------------------------------------------------------//
void CoDroneClass::goToHeight(int _range)
{
int _dir = 0;
//---------------------------------------------------------------//
int value = getHeight();
if (value < _range) _dir = 1; // up
else if(value > _range) _dir = -1; // down
//---------------------------------------------------------------//
while(1)
{
value = getHeight();
if (receiveRangeSuccess)
{
if((_dir > 0) && (value < _range))
{
THROTTLE = 30;
CoDrone.Control();
}
else if((_dir < 0) && (value > _range))
{
THROTTLE = -30;
CoDrone.Control();
}
else
{
THROTTLE = 0;
CoDrone.Control();
break;
}
}
}
}
void CoDroneClass::turnDegree(int _dir, int _angle)
{
_dir = (_dir == RIGHT ? 1 : -1);
angledata angle;
angle = CoDrone.getGyroAngles();
int yawPast = angle.yaw;
_angle = _dir * (abs(_angle) - 5) + yawPast; //5 is bias
while (1)
{
angle = CoDrone.getGyroAngles();
int _nowAngle = angle.yaw;
if (abs(yawPast - _nowAngle) > 180) _angle -= _dir * 360;
yawPast = _nowAngle;
YAW = _dir * 20; //20 is power for yawing
if ((_dir > 0) && (_angle > _nowAngle)) CoDrone.Control(); // right turn
else if ((_dir < 0) && (_angle < _nowAngle)) CoDrone.Control(); // left turn
else
{
YAW = 0;
CoDrone.Control();
break;
}
}
}
//-------------------------------------------------------------------------------------------------------//
void CoDroneClass::calibrate()
{
byte _packet[9];
byte _crc[2];
//header
_packet[0] = dType_Command;
_packet[1] = 0x02;
//data
_packet[2] = 0x53;
_packet[3] = 0;
unsigned short crcCal = CRC16_Make(_packet, _packet[1]+2);
_crc[0] = (crcCal >> 8) & 0xff;
_crc[1] = crcCal & 0xff;
Send_Processing(_packet,_packet[1],_crc);
Send_Check(_packet,_packet[1],_crc);
delay(50);
CoDrone.Buzz(523,2);
CoDrone.Buzz(659,2);
CoDrone.Buzz(783,2);
CoDrone.Buzz(1055,2);
}
/*
* function : flySequence(shape)
* description : flySequence(shape) is do some of squence fly
* Option is ZIPZAG, SWAY, SQUARE, CIRCLE, SPIRAL, TRIANGLE, HOP
* param :
* - shape : int
* return : none
*/
void CoDroneClass::flySequence(int shape)
{
switch(shape)
{
case ZIGZAG :
zigzag();
break;
case SWAY :
sway();
break;
case SQUARE :
square();
break;
case CIRCLE :
circle();
break;
case SPIRAL :
spiral();
break;
case TRIANGLE:
triangle();
break;
case HOP:
hop();
break;
}
}
/*
* function : sway()
* description : sway() is function for move drone left and right twice
* this function is called by flySequence()
* param : none
* return : none
*/
void CoDroneClass::sway()
{
move(1, 50, 0, 0, 0);
move(1, -50, 0, 0, 0);
move(1, 50, 0, 0, 0);
move(1, -50, 0, 0, 0);
}
/*
* function : zigzag()
* description : zigzag() is function for move drone zigzag twice
* this function is called by flySequence()
* param : none
* return : none
*/
void CoDroneClass::zigzag()
{
move(1, 50, 50, 0, 0);
move(1, -50, 50, 0, 0);
move(1, 50, 50, 0, 0);
move(1, -50, 50, 0, 0);
}
/*
* function : square()
* description : square() is function for fly square shape
It will fly right -> forward -> left -> back
* this function is called by flySequence()
* param : none
* return : none
*/
void CoDroneClass::square()
{
move(2, 30, 0, 0, 0);
move(2, 0, 30, 0, 0);
move(2, -30, 0, 0, 0);
move(2, 0, -30, 0, 0);
}
/*
* function : triangle()
* description : triangle() is function for fly triangle shape
It will fly forward -> turn left 120 degree
* -> fly forward -> turn left 120 degree -> fly forward
* this function is called by flySequence()
* param : none
* return : none
*/
void CoDroneClass::triangle()
{
turnDegree(RIGHT,30);
move(2, 0,30,0,0);
turnDegree(LEFT,120);
move(2, 0,30,0,0);
turnDegree(LEFT,120);
move(2, 0,30,0,0);
}
/*
* function : hop()
* description : hop() is function for drone looks like hopping.
* Drone will go up and down for 1second each while flying forward
* this function is called by flySequence()
* param : none
* return : none
*/
void CoDroneClass::hop()
{
move(30, 0, 50, 1);
delay(1000);
move(30, 0, -50, 1);
delay(1000);
hover(1);
}
/*
* function : circle()
* description : circle() is function for fly circle shape
* Drone will do yaw and roll at the same time
* yaw direction and roll direction is oposite
* this function is called by flySequence()
* param : none
* return : none
*/
void CoDroneClass::circle()
{
CoDrone.move(40, 0, 0, 0);
delay(200);
CoDrone.move(40, 0, -60, 0);
delay(2500);
CoDrone.move(40, 0, -50, 0);
delay(1000);
CoDrone.move(30, 0, 0, 0);
delay(100);
CoDrone.hover(1);
}
/*
* function : spiral()
* description : spiral() is function for fly spiral shape
* set yaw for -50 and increase roll with for loop
* after finish
* the function is called by flySequence()
* param : none
* return : none
*/
void CoDroneClass::spiral()
{
for(int i = 0 ;i<5 ;i++){
setRoll(10+i*2);
setYaw(-50);
move();
delay(1000);
}
hover(1);
setRoll(0);
setYaw(0);
}
//-------------------------------------------------------------------------------------------------------//
//------------------------------------------ Battle -----------------------------------------------------//
//-------------------------------------------------------------------------------------------------------//
void CoDroneClass::BattleBegin(byte teamSelect)
{
team = teamSelect;
byte _color = 0;
switch (team)
{
case TEAM_RED:
weapon = RED_MISSILE;
_color = Red;
break;
case TEAM_BLUE:
weapon = BLUE_MISSILE;
_color = Blue;
break;
case TEAM_GREEN:
weapon = GREEN_MISSILE;
_color = Green;
break;
case TEAM_YELLOW:
weapon = YELLOW_MISSILE;
_color = Yellow;
break;
case FREE_PLAY:
weapon = FREE_MISSILE;
_color = White;
break;
}
CoDrone.LedColor(ArmHold, _color, 7);
delay(300);
CoDrone.LedColor(EyeDimming, _color, 7);
delay (300);
}
void CoDroneClass::BattleReceive()