/
ryzeDefRectangle.py
63 lines (50 loc) · 1.83 KB
/
ryzeDefRectangle.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
#3python3
import socket
import time
host = ''
port = 9000
myAddr = host,port
def rectangle():
socket.sendto('forward 50'.encode('utf-8'), ryze_addr)
response, ip = socket.recvfrom(1024)
if response == b'ok':
socket.sendto('ccw 90'.encode('utf-8'), ryze_addr)
response, ip = socket.recvfrom(1024)
if response == b'ok':
time.sleep(1)
socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
socket.bind((myAddr))
ryze_ip = '192.168.10.1'
ryze_port = 8889
ryze_addr = (ryze_ip, ryze_port)
socket.sendto('command'.encode('utf-8'), ryze_addr)
repeat = 0
try:
while True:
response, ip = socket.recvfrom(1024)
if response != b'ok':
print ("no command - sorry we dont fly")
break
socket.sendto('battery?'.encode('utf-8'), ryze_addr)
response, ip = socket.recvfrom(1024)
response = int(response)
print("battery power: " , response , "%")
if response < 10:
print ("It is a pity that we will not fly, the state of the battery is: " , response , "%")
break
socket.sendto('takeoff'.encode('utf-8'), ryze_addr)
response, ip = socket.recvfrom(1024)
print("takeOff: " , response)
if response == b'ok':
socket.sendto('speed 99'.encode('utf-8'), ryze_addr)
response, ip = socket.recvfrom(1024)
print("speed: " , response)
if response == b'ok':
while repeat<=3:
rectangle()
repeat=repeat+1
socket.sendto('land'.encode('utf-8'), ryze_addr)
print("land")
break
except KeyboardInterrupt:
print("main_end")