-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathWDS1.0.0.13.py
1155 lines (926 loc) · 52.4 KB
/
WDS1.0.0.13.py
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
import string
import sys, os, json, time
from fly_tello import FlyTello
import logging
import datetime
from leds import LED
import pandas as pd
colnames=['Serial No']
ID=pd.read_csv('DroneID.csv',names=colnames)
my_tellos = list() #Creating a list for the drones
led=LED() #Object created for Led program to access the method from leds.py
###Definitions for String modification
import string
LOG_FILENAME = 'example.log'
logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG)
buffer_Size = 40 # Defining the buffer size that is received from Beyond
type(buffer_Size)
def String_Modified(x: string): # An important function that modifies the string received from Beyond/ User/PacketSender
global drones
global parameters
# A list that separates string received from beyond
parameters = x.split(' ')
drones = parameters[0] # Reading the first parameter as drones to be given command
global move # Reading the 2nd parameter as move which takes input for various commands eg. up down takeoff
move = parameters[1]
global numofdrones # reads the length of first parameter to figure out number of drones
numofdrones = int(len(list(drones)))
drones = drones.lower()
drone_list = list(drones)
print(" %s Command for following drones %s"%(move ,list(drones)))
def nameofdrones(drones): # Reads the first parameter and separates the alphabets to make a list
return list(drones)
values = dict() #Creating a variable of type dictionary
for index, dronename in enumerate(string.ascii_lowercase): # Converts alphabets to num for eg a=1,b=2
values[dronename] = index + 1 #Creates a key value type pair .For eg values[a]= index +1
# Instruction received from client(from Beyond)
#################################################################################################
####### CONNECTION SETUP OF TCP WITH BEYOND
import socket
# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Bind the socket to the port
server_address = ('localhost', 50524) #localhost for using our own PC as server
#server_address = ('192.168.0.118', 50524) #or you can enter address of the server
print('starting up on %s port %s' % server_address)
sock.bind(server_address)
# Listen for incoming connections
sock.listen(1)
####################################################################################################
###### DIFFERENT MOTION FUNCTIONS
def hover(): # Hover is a command to stay in air. This command is necessary when you want it in the air witjout any specific movement
with fly.individual_behaviours():
if numofdrones == 1:
try:
fly.stop(tello=values[drones[0]])
except:
print("Error for hover of single drone: " )
else:
for num in range(0,
numofdrones):
# For loop to give commands to number of drones from 0 to the number of drones mentioned
try:
fly.stop(tello=values[drones[num]])
except:
print("Exception for hovering Drone %s" % values[drones[num]])
def rotate(r_dir: str, degree: int): #Function to rotate the drone in clockwise or anticlockwise direction by entered degree
if numofdrones == 1:
try:
if r_dir == 'ac':
fly.rotate_ccw(tello=values[drones[0]], angle=degree)
time.sleep(hold)
elif r_dir == 'c':
fly.rotate_cw(tello=values[drones[0]], angle=degree)
time.sleep(hold)
except:
print("Error for rotate of single drone: %s" %values[drones[0]] )
else:
for num in range(0, numofdrones):
try:
if r_dir == 'ac':
fly.rotate_ccw(tello=values[drones[num]], angle=degree)
time.sleep(hold)
elif r_dir == 'c':
fly.rotate_cw(tello=values[drones[num]], angle=degree)
time.sleep(hold)
except:
print("Rotation error for Drone %s" %values[drones[num]])
# for front,right,up values=+1 to +500 cm
# for back,left,down values=-1 to -500 cm
def go_to_point(front_back: int, left_right: int, up_down: int,
dronespeed: int): # front_back=x axis left_right=yaxis and up down=z axis
# go_to_point is a dunction for directly going to a point in xyz coordinate system.
if numofdrones == 1:
try:
fly.straight(x=front_back, y=left_right, z=up_down, speed=dronespeed, tello=values[drones[0]])
time.sleep(hold)
except:
print("Go to Point exception for Drone %s" %values[drones[0]])
else:
for num in range(0, numofdrones):
try:
fly.straight(x=front_back, y=left_right, z=up_down, speed=dronespeed, tello=values[drones[num]])
time.sleep(hold)
except:
print("Go to Point exception for Drone %s" %values[drones[num]])
def wave_ORIGINAL():
with fly.individual_behaviours():
for num in range(0, numofdrones):
fly.run_individual(fly.up(dist=100, tello=values[drones[num]]))
time.sleep(0.35)
time.sleep(1)
for num in range(0, numofdrones):
fly.run_individual(fly.down(dist=100, tello=values[drones[num]]))
time.sleep(0.35)
def Bird():
left_wing=int(parameters[2])
right_wing=int(parameters[2])
with fly.individual_behaviours():
if numofdrones%2==0:
center= numofdrones/2
else:
center=(numofdrones+1)/2
center=int(center)
if parameters[3] is None:
parameters[3]=1
for num in range(0,int(parameters[3])):
fly.run_individual(fly.straight(x=0, y=0, z=int(parameters[2]) - act_height[center], speed=50, tello=center))
for num in range(center, numofdrones):
right_wing=right_wing+30
fly.run_individual(fly.straight(x=0, y=0, z=int(right_wing - act_height[num]), speed=50,tello=values[drones[num]]))
for num in range(0,center-1):
left_wing=left_wing + 30
fly.run_individual(fly.straight(x=0, y=0, z=int(left_wing - act_height[num]), speed=50,tello=values[drones[num]]))
time.sleep(1)
fly.run_individual(fly.straight(x=0, y=0, z=int(parameters[2])+right_wing - act_height[center], speed=50, tello=center))
for num in range(center, numofdrones):
right_wing=int(act_height[num])-30
fly.run_individual(fly.straight(x=0, y=0, z=int(right_wing), speed=50,tello=values[drones[num]]))
for num in range(0,center-1):
left_wing=int(act_height[num]) - 30
fly.run_individual(fly.straight(x=0, y=0, z=int(left_wing), speed=50,tello=values[drones[num]]))
#def wave():
# with fly.individual_behaviours():
# for num in range(0,numofdrones):
# fly.run_individual(fly.up(dist=100,tello=values[drones[num]]))
# time.sleep(0.35)
# fly.run_individual(fly.down(dist=100,tello=values[drones[num]]))
# time.sleep(0.35)
# for num in range(0,numofdrones):
# fly.run_individual(fly.down(dist=100,tello=values[drones[num]]))
# time.sleep(0.35)
def Motion(mot: str):# Function to call different kinds of motion(All drones will do the same motion in the own axis)
if numofdrones == 1:
try:
if mot == 'triangle':
fly.straight(x=100, y=100, z=100, speed=100, tello=values[drones[0]])
fly.straight(x=0, y=-100, z=0, speed=100, tello=values[drones[0]])
fly.straight(x=-100, y=100, z=-100, speed=100, tello=values[drones[0]])
time.sleep(hold)
elif mot == '1':
fly.straight(x=0, y=0, z=50, speed=100, tello=values[drones[0]])
fly.straight(x=0, y=0, z=-50, speed=100, tello=values[drones[0]])
fly.straight(x=0, y=0, z=50, speed=100, tello=values[drones[0]])
time.sleep(hold)
else:
print("Unsupported command")
except :
print("Motion function error for Drone %s"%values[drones[0]] )
else:
for num in range(0, numofdrones):
try:
if mot == 'triangle':
fly.straight(x=100, y=100, z=100, speed=100, tello=values[drones[num]])
fly.straight(x=0, y=-100, z=0, speed=100, tello=values[drones[num]])
fly.straight(x=-100, y=100, z=-100, speed=100, tello=values[drones[num]])
time.sleep(hold)
elif mot == '1':
fly.straight(x=0, y=0, z=50, speed=100, tello=values[drones[num]])
fly.straight(x=0, y=0, z=-50, speed=100, tello=values[drones[num]])
fly.straight(x=0, y=0, z=50, speed=100, tello=values[drones[num]])
time.sleep(hold)
else:
print("Unsupported command")
except :
print("Motion function error for Drone %s"%values[drones[num]] )
def semicircle(dir: str):# DO a semicircle curve with size: s,m,l,xl,xxl
try:
if parameters[3]=='s':
a1=55
b1=55
c1=55
a2=a1*2
b2=b1*2
c2=c1*2
elif parameters[3]=='m':
a1=70
b1=70
c1=70
a2=a1*2
b2=b1*2
c2=c1*2
elif parameters[3]=='l':
a1=90
b1=90
c1=90
a2=a1*2
b2=b1*2
c2=c1*2
elif parameters[3]=='xl':
a1=110
b1=110
c1=110
a2=a1*2
b2=b1*2
c2=c1*2
elif parameters[3]=='xxl':
a=130
b=130
c=130
a2=a1*2
b2=b1*2
c2=c1*2
else:
a1=50
b1=50
c1=50
a2=a1*2
b2=b1*2
c2=c1*2
except:
print("Size of semi circle not entered")
if numofdrones == 1:
try:
if dir == 'fr': # A semi-circle going in front from right to left
fly.curve(x1=a1, y1=-b1, z1=0, x2=a2, y2=0, z2=0, speed=60, tello=values[drones[0]])
time.sleep(hold)
elif dir == 'fl': # A semi-circle going in front from left to right
fly.curve(x1=a1, y1=b1, z1=0, x2=a2, y2=0, z2=0, speed=60, tello=values[drones[0]])
time.sleep(hold)
elif dir == 'bl': # A semi-circle going back from left to right
fly.curve(x1=-a1, y1=b1, z1=0, x2=-a2, y2=0, z2=0, speed=60, tello=values[drones[0]])
time.sleep(hold)
elif dir == 'br': # A semi-circle going back from left to right
fly.curve(x1=-a1, y1=-b1, z1=0, x2=-a2, y2=0, z2=0, speed=60, tello=values[drones[0]])
time.sleep(hold)
elif dir == 'leftl': # A semi-circle going back from left to right
fly.curve(x1=-a1, y1=b1, z1=0, x2=0, y2=b2, z2=0, speed=60, tello=values[drones[0]])
time.sleep(hold)
elif dir == 'leftr': # A semi-circle going back from left to right
fly.curve(x1=a1, y1=b1, z1=0, x2=0, y2=b2, z2=0, speed=60, tello=values[drones[0]])
time.sleep(hold)
elif dir == 'rightl': # A semi-circle going back from left to right
fly.curve(x1=a1, y1=-b1, z1=0, x2=0, y2=-b2, z2=0, speed=60, tello=values[drones[0]])
time.sleep(hold)
elif dir == 'rightr': # A semi-circle going back from left to right
fly.curve(x1=-a1, y1=-b1, z1=0, x2=0, y2=-b2, z2=0, speed=60, tello=values[drones[0]])
time.sleep(hold)
else:
print("Unsupported values entered")
except:
print("SemiCircle function error for Single Drone %s" %values[drones[0]])
else:
for num in range(0,
numofdrones): # For loop to give commands to number of drones from 0 to the number of drones mentioned
try:
if dir == 'fr': # A semi-circle going in front from right to left
fly.curve(x1=a1, y1=-b1, z1=0, x2=a2, y2=0, z2=0, speed=60, tello=values[drones[num]])
time.sleep(hold)
elif dir == 'fl': # A semi-circle going in front from left to right
fly.curve(x1=a1, y1=b1, z1=0, x2=a2, y2=0, z2=0, speed=60, tello=values[drones[num]])
time.sleep(hold)
elif dir == 'bl': # A semi-circle going back from left to right
fly.curve(x1=-a1, y1=b1, z1=0, x2=-a2, y2=0, z2=0, speed=60, tello=values[drones[num]])
time.sleep(hold)
elif dir == 'br': # A semi-circle going back from left to right
fly.curve(x1=-a1, y1=-b1, z1=0, x2=-a2, y2=0, z2=0, speed=60, tello=values[drones[num]])
time.sleep(hold)
elif dir == 'leftl': # A semi-circle going back from left to right
fly.curve(x1=-a1, y1=b1, z1=0, x2=0, y2=b2, z2=0, speed=60, tello=values[drones[num]])
time.sleep(hold)
elif dir == 'leftr': # A semi-circle going back from left to right
fly.curve(x1=a1, y1=b1, z1=0, x2=0, y2=b2, z2=0, speed=60, tello=values[drones[num]])
time.sleep(hold)
elif dir == 'rightl': # A semi-circle going back from left to right
fly.curve(x1=a1, y1=-b1, z1=0, x2=0, y2=-b2, z2=0, speed=60, tello=values[drones[num]])
time.sleep(hold)
elif dir == 'rightr': # A semi-circle going back from left to right
fly.curve(x1=-a1, y1=-b1, z1=0, x2=0, y2=-b2, z2=0, speed=60, tello=values[drones[num]])
time.sleep(hold)
else:
print("Unsupported values entered")
except:
print("SemiCircle function error for Drone %s" %values[drones[num]])
def circle(type: str): # Command Format: abcdefghij circle ac s
#Draw a circle of size S,m,l,xl,xxl
try:
if parameters[3]=='s':
a1=55
b1=55
c1=55
a2=a1*2
b2=b1*2
c2=c1*2
elif parameters[3]=='m':
a1=70
b1=70
c1=70
a2=a1*2
b2=b1*2
c2=c1*2
elif parameters[3]=='l':
a1=90
b1=90
c1=90
a2=a1*2
b2=b1*2
c2=c1*2
elif parameters[3]=='xl':
a1=110
b1=110
c1=110
a2=a1*2
b2=b1*2
c2=c1*2
elif parameters[3]=='xxl':
a=130
b=130
c=130
a2=a1*2
b2=b1*2
c2=c1*2
else:
a1=50
b1=50
c1=50
a2=a1*2
b2=b1*2
c2=c1*2
except:
print("Size of circle not entered")
if numofdrones==1:
try:
if type == 'ac':
fly.curve(x1=a1, y1=-b1, z1=0, x2=a2, y2=0, z2=0, speed=60, tello=int(values[drones[0]]))
fly.curve(x1=-a1, y1=b1, z1=0, x2=-a2, y2=0, z2=0, speed=60, tello=int(values[drones[0]]))
time.sleep(hold)
elif type == 'c': # Clockwise circle parallel to ground
fly.curve(x1=a1, y1=b1, z1=0, x2=a2, y2=0, z2=0, speed=60, tello=int(values[drones[0]]))
fly.curve(x1=-a1, y1=-b1, z1=0, x2=-a2, y2=0, z2=0, speed=60, tello=int(values[drones[0]]))
time.sleep(hold)
elif type == 'du': # Circle that goes first down then up and motion parallel to wall
fly.curve(x1=a1, y1=0, z1=-c1, x2=a2, y2=0, z2=0, speed=60, tello=int(values[drones[0]]))
fly.curve(x1=-a1, y1=0, z1=c1, x2=-a2, y2=0, z2=0, speed=60, tello=int(values[drones[0]]))
time.sleep(hold)
elif type == 'ud': # Circle that goes first up and then down and motion parallel to wall
fly.curve(x1=a1, y1=0, z1=c1, x2=a2, y2=0, z2=0, speed=60, tello=int(values[drones[0]]))
fly.curve(x1=-a1, y1=0, z1=-c1, x2=-a2, y2=0, z2=0, speed=60, tello=int(values[drones[0]]))
time.sleep(hold)
elif type == 'lr': # Circle that goes first up and then down and motion parallel to wall
fly.curve(x1=0, y1=-b1, z1=c1, x2=0, y2=-b2, z2=0, speed=60, tello=int(values[drones[0]]))
fly.curve(x1=0, y1=b1, z1=-c1, x2=0, y2=b2, z2=0, speed=60, tello=int(values[drones[0]]))
time.sleep(hold)
elif type == 'rl': # Circle that goes first up and then down and motion parallel to wall
fly.curve(x1=0, y1=b1, z1=c1, x2=0, y2=b2, z2=0, speed=60, tello=int(values[drones[0]]))
fly.curve(x1=0, y1=-b1, z1=-c1, x2=0, y2=-b2, z2=0, speed=60, tello=int(values[drones[0]]))
time.sleep(hold)
else:
print("Unsupported values entered")
except:
print("Circle exception for Single Drone %s" %values[drones[0]])
else:
for num in range(0, numofdrones):
try:
if type == 'ac':
fly.curve(x1=a1, y1=-b1, z1=0, x2=a2, y2=0, z2=0, speed=60, tello=int(values[drones[num]]))
fly.curve(x1=-a1, y1=b1, z1=0, x2=-a2, y2=0, z2=0, speed=60, tello=int(values[drones[num]]))
time.sleep(hold)
elif type == 'c': # Clockwise circle parallel to ground
fly.curve(x1=a1, y1=b1, z1=0, x2=a2, y2=0, z2=0, speed=60, tello=int(values[drones[num]]))
fly.curve(x1=-a1, y1=-b1, z1=0, x2=-a2, y2=0, z2=0, speed=60, tello=int(values[drones[num]]))
time.sleep(hold)
elif type == 'du': # Circle that goes first down then up and motion parallel to wall
fly.curve(x1=a1, y1=0, z1=-c1, x2=a2, y2=0, z2=0, speed=60, tello=int(values[drones[num]]))
fly.curve(x1=-a1, y1=0, z1=c1, x2=-a2, y2=0, z2=0, speed=60, tello=int(values[drones[num]]))
time.sleep(hold)
elif type == 'ud': # Circle that goes first up and then down and motion parallel to wall
fly.curve(x1=a1, y1=0, z1=c1, x2=a2, y2=0, z2=0, speed=60, tello=int(values[drones[num]]))
fly.curve(x1=-a1, y1=0, z1=-c1, x2=-a2, y2=0, z2=0, speed=60, tello=int(values[drones[num]]))
time.sleep(hold)
elif type == 'lr': # Circle that goes first up and then down and motion parallel to wall
fly.curve(x1=0, y1=-b1, z1=c1, x2=0, y2=-b2, z2=0, speed=60, tello=int(values[drones[num]]))
fly.curve(x1=0, y1=b1, z1=-c1, x2=0, y2=b2, z2=0, speed=60, tello=int(values[drones[num]]))
time.sleep(hold)
elif type == 'rl': # Circle that goes first up and then down and motion parallel to wall
fly.curve(x1=0, y1=b1, z1=c1, x2=0, y2=b2, z2=0, speed=60, tello=int(values[drones[num]]))
fly.curve(x1=0, y1=-b1, z1=-c1, x2=0, y2=-b2, z2=0, speed=60, tello=int(values[drones[num]]))
time.sleep(hold)
else:
print("Unsupported values entered")
except:
print("Circle exception for Drone %s" %values[drones[num]])
#Draw an eight of different sizes s,m,lxl,xxl()
def eight(direction: str):# Command Format: abcdefghij eight vu s
try:
if parameters[3]=='s':
a1=52
b1=52
c1=52
a2=a1*2
b2=b1*2
c2=c1*2
elif parameters[3]=='m':
a1=52
b1=52
c1=52
a2=a1*2
b2=b1*2
c2=c1*2
elif parameters[3]=='l':
a1=90
b1=90
c1=90
a2=a1*2
b2=b1*2
c2=c1*2
elif parameters[3]=='xl':
a1=110
b1=110
c1=110
a2=a1*2
b2=b1*2
c2=c1*2
elif parameters[3]=='xxl':
a=130
b=130
c=130
a2=a1*2
b2=b1*2
c2=c1*2
else:
a1=50
b1=50
c1=50
a2=a1*2
b2=b1*2
c2=c1*2
except:
print("Size of circle not entered")
if numofdrones==1:
try:
if direction == 'vu': # vertical up to down: does circle up then does circle down
# ledblink()
fly.curve(x1=0, y1=-b1, z1=c1, x2=0, y2=0, z2=c2, speed=60, tello=int(values[drones[0]]))
fly.curve(x1=0, y1=b1, z1=-c1, x2=0, y2=0, z2=-c2, speed=60, tello=int(values[drones[0]]))
fly.curve(x1=0, y1=-b1, z1=-c1, x2=0, y2=0, z2=-c2, speed=60, tello=int(values[drones[0]]))
fly.curve(x1=0, y1=b1, z1=c1, x2=0, y2=0, z2=c2, speed=60, tello=int(values[drones[0]]))
time.sleep(hold)
elif direction == 'vd': # Vertical down then goes up
fly.curve(x1=0, y1=-b1, z1=-c1, x2=0, y2=0, z2=-c2, speed=60, tello=values[drones[0]])
fly.curve(x1=0, y1=b1, z1=c1, x2=0, y2=0, z2=c2, speed=60, tello=values[drones[0]])
fly.curve(x1=0, y1=-b1, z1=c1, x2=0, y2=0, z2=c2, speed=60, tello=values[drones[0]])
fly.curve(x1=0, y1=b1, z1=-c1, x2=0, y2=0, z2=-c2, speed=60, tello=values[drones[0]])
time.sleep(hold)
elif direction == 'hr': # horizontal right to left : does a circle in front starting from right and then back
fly.curve(x1=0, y1=-b1, z1=-c1, x2=0, y2=-b2, z2=0, speed=60, tello=values[drones[0]])
fly.curve(x1=0, y1=b1, z1=c1, x2=0, y2=b2, z2=0, speed=60, tello=values[drones[0]])
fly.curve(x1=0, y1=b1, z1=-c1, x2=0, y2=b2, z2=0, speed=60, tello=values[drones[0]])
fly.curve(x1=0, y1=-b1, z1=c1, x2=0, y2=-b2, z2=0, speed=60, tello=values[drones[0]])
time.sleep(hold)
elif direction == 'hl': # horizontal left to right: does a circle in front starting from right and then back
fly.curve(x1=0, y1=b1, z1=-c1, x2=0, y2=b2, z2=0, speed=60, tello=values[drones[0]])
fly.curve(x1=0, y1=-b1, z1=c1, x2=0, y2=-b2, z2=0, speed=60, tello=values[drones[0]])
fly.curve(x1=0, y1=-b1, z1=-c1, x2=0, y2=-b2, z2=0, speed=60, tello=values[drones[0]])
fly.curve(x1=0, y1=b1, z1=c1, x2=0, y2=b2, z2=0, speed=60, tello=values[drones[0]])
time.sleep(hold)
elif direction == 'criscross': # Makes an eight diagonally from its original position
fly.curve(x1=a1, y1=-b1, z1=-c1, x2=a2, y2=-b2, z2=0, speed=60, tello=values[drones[0]])
fly.curve(x1=-a1, y1=b1, z1=c1, x2=-a2, y2=b2, z2=-0, speed=60, tello=values[drones[0]])
fly.curve(x1=-a1, y1=b1, z1=-c1, x2=-a2, y2=b2, z2=0, speed=60, tello=values[drones[0]])
fly.curve(x1=a1, y1=-b1, z1=c1, x2=a2, y2=-b2, z2=0, speed=60, tello=values[drones[0]])
time.sleep(hold)
except:
print("Figure 8 exception for Single Drone %s" %values[drones[0]])
else:# Same function which go for multiple drones
for num in range(0, numofdrones):
try:
if direction == 'vu': # vertical up to down
# ledblink()
fly.curve(x1=0, y1=-b1, z1=c1, x2=0, y2=0, z2=c2, speed=60, tello=int(values[drones[num]]))
fly.curve(x1=0, y1=b1, z1=-c1, x2=0, y2=0, z2=-c2, speed=60, tello=int(values[drones[num]]))
fly.curve(x1=0, y1=-b1, z1=-c1, x2=0, y2=0, z2=-c2, speed=60, tello=int(values[drones[num]]))
fly.curve(x1=0, y1=b1, z1=c1, x2=0, y2=0, z2=c2, speed=60, tello=int(values[drones[num]]))
time.sleep(hold)
elif direction == 'vd': # Vertical down then goes up
fly.curve(x1=0, y1=-b1, z1=-c1, x2=0, y2=0, z2=-c2, speed=60, tello=values[drones[num]])
fly.curve(x1=0, y1=b1, z1=c1, x2=0, y2=0, z2=c2, speed=60, tello=values[drones[num]])
fly.curve(x1=0, y1=-b1, z1=c1, x2=0, y2=0, z2=c2, speed=60, tello=values[drones[num]])
fly.curve(x1=0, y1=b1, z1=-c1, x2=0, y2=0, z2=-c2, speed=60, tello=values[drones[num]])
time.sleep(hold)
elif direction == 'hr': # horizontal right to left
fly.curve(x1=0, y1=-b1, z1=-c1, x2=0, y2=-b2, z2=0, speed=60, tello=values[drones[num]])
fly.curve(x1=0, y1=b1, z1=c1, x2=0, y2=b2, z2=0, speed=60, tello=values[drones[num]])
fly.curve(x1=0, y1=b1, z1=-c1, x2=0, y2=b2, z2=0, speed=60, tello=values[drones[num]])
fly.curve(x1=0, y1=-b1, z1=c1, x2=0, y2=-b2, z2=0, speed=60, tello=values[drones[num]])
time.sleep(hold)
elif direction == 'hl': # horizontal left to right
fly.curve(x1=0, y1=b1, z1=-c1, x2=0, y2=b2, z2=0, speed=60, tello=values[drones[num]])
fly.curve(x1=0, y1=-b1, z1=c1, x2=0, y2=-b2, z2=0, speed=60, tello=values[drones[num]])
fly.curve(x1=0, y1=-b1, z1=-c1, x2=0, y2=-b2, z2=0, speed=60, tello=values[drones[num]])
fly.curve(x1=0, y1=b1, z1=c1, x2=0, y2=b2, z2=0, speed=60, tello=values[drones[num]])
time.sleep(hold)
elif direction == 'criscross': # Makes an eight diagonally from its original position
fly.curve(x1=a1, y1=-b1, z1=-c1, x2=a2, y2=-b2, z2=0, speed=60, tello=values[drones[num]])
fly.curve(x1=-a1, y1=b1, z1=c1, x2=-a2, y2=b2, z2=-0, speed=60, tello=values[drones[num]])
fly.curve(x1=-a1, y1=b1, z1=-c1, x2=-a2, y2=b2, z2=0, speed=60, tello=values[drones[num]])
fly.curve(x1=a1, y1=-b1, z1=c1, x2=a2, y2=-b2, z2=0, speed=60, tello=values[drones[num]])
time.sleep(hold)
except:
print("Figure 8 exception for Drone %s" %values[drones[num]])
# MAIN FLIGHT CONTROL LOGIC
# Define the Tello's we're using, in the order we want them numbered
### my_tellos.append('Serial No. of drone') . This function appends the drone to my_tellos list.
# Here the order of append matters. The one appended first has tello number 1 and so on.
# my_tellos.append('0TQDG2KEDB4D6B') #1
# #my_tellos.append('0TQDG3REDB6D33') #2 not working
# my_tellos.append('0TQDG4VEDB7G9V') #2
# my_tellos.append('0TQDFATEDBUP8P') #3
# my_tellos.append('0TQDFBNEDBN2N3') #4
# my_tellos.append('0TQDFBNEDB2EPS') #5
# my_tellos.append('0TQDFBNEDBR92E') #6
# my_tellos.append('0TQDFBNEDBGKHB') #7
# my_tellos.append('0TQDFB7EDB1374') #8
# my_tellos.append('0TQDFCDEDBXSWP') #9
# my_tellos.append('0TQDFBNEDB13D0') #10
# my_tellos.append('0TQDFATEDBGC9L') #11
# my_tellos.append('0TQDFATEDBV212') #12
my_tellos=ID['Serial No'].tolist()
global timestamp
timestamp= time.time()
# Control the flight
with FlyTello(my_tellos) as fly: # Creates an object of FlyTello named fly and My_tellos list is passed as argument
while True: # To make the program run continously
print('waiting for a connection')
connection, client_address = sock.accept()
try:
print('connection from', client_address)
# Receive the data in small chunks
if True:
#Data variable contains the string received over network.
data = connection.recv(buffer_Size).decode().strip()
print('received DATA "%s"' % data)
String_Modified(data) # Calling the function string modifies on the data received from client side
act_height=[]
for i in range(1,len(my_tellos)+1):
try:
print("Drone %s : H=%s Temp= %s %s Battery=%s"%(i,fly.get_status(key='h',tello=int(i)),fly.get_status(key='templ',tello=int(i)),fly.get_status(key='temph',tello=int(i)),fly.get_status(key='bat',tello=int(i))))
act_height.insert(i,fly.get_status(key='h',tello=int(i)))
logging.debug("%s ------>>>>> Drone %s : H=%s Temp= %s %s Battery=%s"%(datetime.datetime.now(),i,fly.get_status(key='h',tello=int(i)),fly.get_status(key='templ',tello=int(i)),fly.get_status(key='temph',tello=int(i)),fly.get_status(key='bat',tello=int(i))))
except AttributeError as e:
print("Could not get height for Drone: %d"% i)
act_height.insert(i,0)
# Clears the data everytime it loops
data = ''
nameofdrones(drones) # Convert the name of drones as a list
# Hold is variable to delay the function by x seconds
hold=0
hold=float(hold)
if parameters[0]=='LED': # If the first argument is LED then it suggests a command for LEDS.
abc= parameters[2:]#It takes all the variables from 3rd paramter
led_comm=' '.join(abc)
led.led_com(str(parameters[1]),str(led_comm)) # Takes the name of drones and led command as input
#print(led_comm)
print(" %s Led Command called" %led_comm)
elif move=='wave': #Command Format: abcdefghij wave up(comand) 100(distance) .5(time gap between each drone)
move = parameters[3]
if move is None: #default wave command as up
move='up'
hold = float(parameters[2])
if hold is None:
hold=0.5
parameters[2] = parameters[4]
if parameters[2] is None:
parameters[2]=100
for i in range(3,len(parameters)):
if i+2>=len(parameters):
break
parameters[i]=parameters[i+2]
print("In wave command")
if move=='bird': #Create a bird like formation(Currently not working)
Bird()
if move == 'height': # Command Format: 'abcdefghij height 100'(distance from ground in cm/s)
data = ''
with fly.individual_behaviours():
for num in range(0,numofdrones):
try:
fly.straight(x=0,y=0,z=int(parameters[2])-int(fly.get_status(key='h',tello=int(values[drones[num]]))),speed=70,tello=int(values[drones[num]]))
print("The actual height now %s" %act_height[num])
except :
print("Height Error for drone %s " % values[drones[num]])
if move == 'takeoff': # The most important command. Drone cannot accept other commands unles it takes off
# Clears the buffer
data = ''
with fly.individual_behaviours():
if numofdrones==1:
try:
fly.run_individual(fly.takeoff(tello=values[drones[0]]))
time.sleep(hold)
print("Takeoff")
except AttributeError as ae:
print("Exception in takeof for Single Drone %s "% values[drones[0]] )
else:
for num in range(0, numofdrones):
try:
fly.run_individual(fly.takeoff(tello=values[drones[num]]))
time.sleep(hold)
print("Takeoff")
except AttributeError as ae:
print("Exception in takeof for Drone %s "% values[drones[num]] )
elif move == 'hover': #Command Format:- 'abcdefghij hover'
data = ''
hover() # Calls the hover function defined above
elif move == 'emergency': #If there is and emergency stop required in case of accident,it will stop all the drones immediately
data = ''
try:
fly.emergency(tello="All")
print("Emergency landing")
except:
print("Emergency landing failed")
elif move == 'rotate': #command Format: 'abc rotate c 30' c-direction of rotattion; 130-degrees
#Calls the rotate function defined above
with fly.individual_behaviours():
try:
fly.run_individual(rotate(r_dir=parameters[2], degree=int(parameters[3])))
except:
print("Rotate error")
elif move == 'straight': # Command format: 'abcdef x y z speed'
# eg: abcdef -100 -100 0 70 MaxSpeed = 70 otherwise gives error
#Goes straught to a point in xyz co-ordinate plane
with fly.individual_behaviours():
fly.run_individual(go_to_point(front_back=int(parameters[2]), left_right=int(parameters[3]),
up_down=int(parameters[4]), dronespeed=int(parameters[5])))
elif move == 'up': #Command format: 'abc up 130'
# abc = drones; up = command; 130= distance in cm/s
data = ''
with fly.individual_behaviours():
if numofdrones==1:
try:
fly.run_individual(fly.up(dist=int(parameters[2]), tello=values[drones[0]]))
time.sleep(hold)
except:
print("Up command exception for SIngle Drone %s" %values[drones[0]])
else:
for num in range(0, numofdrones):
try:
fly.run_individual(fly.up(dist=int(parameters[2]), tello=values[drones[num]]))
time.sleep(hold)
except:
print("Up command exception for Drone %s" %values[drones[num]])
elif move == 'down': #Command format: 'abcde down 100'
data = ''
with fly.individual_behaviours():
if numofdrones==1:
try:
fly.run_individual(fly.down(dist=int(parameters[2]), tello=values[drones[0]]))
time.sleep(hold)
except:
print("Down command exception for Single Drone %s" %values[drones[0]])
else:
for num in range(0, numofdrones):
try:
fly.run_individual(fly.down(dist=int(parameters[2]), tello=values[drones[num]]))
time.sleep(hold)
except:
print("Down command exception for Drone %s" %values[drones[num]])
elif move == 'right':#Command Format: 'abcd right 50'
data = ''
with fly.individual_behaviours():
if numofdrones==1:
try:
fly.run_individual(fly.right(dist=int(parameters[2]), tello=values[drones[0]]))
time.sleep(hold)
print("Going Right")
except:
print("Right command exception for Single Drone %s" %values[drones[0]])
else:
for num in range(0, numofdrones):
try:
fly.run_individual(fly.right(dist=int(parameters[2]), tello=values[drones[num]]))
time.sleep(hold)
print("Going Right")
except:
print("Right command exception for Drone %s" %values[drones[num]])
elif move == 'left': #Command Format: 'abcd left 50'
data = ''
with fly.individual_behaviours():
if numofdrones==1:
try:
fly.run_individual(fly.left(dist=int(parameters[2]), tello=values[drones[0]]))
time.sleep(hold)
print("Going Left")
except:
print("Left command exception for Single Drone %s" %values[drones[0]])
else:
for num in range(0, numofdrones):
try:
fly.run_individual(fly.left(dist=int(parameters[2]), tello=values[drones[num]]))
time.sleep(hold)
print("Going Left")
except:
print("Left command exception for Drone %s" %values[drones[num]])
elif move == 'forward': #Command Format: 'abcd forward 50'
#Moves the drone in forward direction
data = ''
with fly.individual_behaviours():
if numofdrones==1:
try:
fly.run_individual(fly.forward(dist=int(parameters[2]), tello=values[drones[0]]))
time.sleep(hold)
print("Going forward")
except:
print("Forward command exception for Single Drone %s" %values[drones[0]])
else:
for num in range(0, numofdrones):
try:
fly.run_individual(fly.forward(dist=int(parameters[2]), tello=values[drones[num]]))
time.sleep(hold)
print("Going forward")
except:
print("Forward command exception for Drone %s" %values[drones[num]])
elif move == 'flip': #Command Format: 'abcd flip l'
#flips the drone in forward,back,left right direction
data = ''
with fly.individual_behaviours():
if numofdrones==1:
try:
if parameters[2] == 'r': #right flip
fly.run_individual(fly.flip(direction='right', tello=int(values[drones[0]])))
time.sleep(hold)
elif parameters[2] == 'l': #left flip
fly.run_individual(fly.flip(direction='left', tello=int(values[drones[0]])))
time.sleep(hold)
elif parameters[2] == 'f': #forward flip
fly.run_individual(fly.flip(direction='forward', tello=int(values[drones[0]])))
time.sleep(hold)
elif parameters[2] == 'b': #backward flip
fly.run_individual(fly.flip(direction='back', tello=int(values[drones[0]])))
time.sleep(hold)
except:
print("Flip command exception for Single Drone %s" %values[drones[0]])
else:
for num in range(0, numofdrones):
try:
if parameters[2] == 'r': #right flip
fly.run_individual(fly.flip(direction='right', tello=int(values[drones[num]])))
time.sleep(hold)
elif parameters[2] == 'l': #left flip
fly.run_individual(fly.flip(direction='left', tello=int(values[drones[num]])))
time.sleep(hold)
elif parameters[2] == 'f': #forward flip
fly.run_individual(fly.flip(direction='forward', tello=int(values[drones[num]])))
time.sleep(hold)
elif parameters[2] == 'b': #backward flip
fly.run_individual(fly.flip(direction='back', tello=int(values[drones[num]])))
time.sleep(hold)
except:
print("Flip command exception for Drone %s" %values[drones[num]])
elif move == 'back': #Command Format: 'abcdefghij back 50'
#Moves the drone backwards
data = ''
with fly.individual_behaviours():
if numofdrones==1:
try:
fly.run_individual(fly.back(dist=int(parameters[2]), tello=int(values[drones[0]])))
time.sleep(hold)
print("back multiple")
except:
print("Back command exception for Single Drone %s" %values[drones[0]])
else:
for num in range(0, numofdrones):
try:
fly.run_individual(fly.back(dist=int(parameters[2]), tello=int(values[drones[num]])))
time.sleep(hold)
print("back multiple")
except:
print("Back command exception for Drone %s" %values[drones[num]])
elif move == 'motion': #Calls the motion function defined above
with fly.individual_behaviours():
fly.run_individual(Motion(mot=parameters[2]))
elif move == 'circle': # Command Format: 'abcd circle ac s'
data = ''
with fly.individual_behaviours():
fly.run_individual(circle(str(parameters[2])))