forked from gouravsiddesh/NodeMCU-FlightController-MPU6050
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UDPsocket.py
65 lines (60 loc) · 1.68 KB
/
UDPsocket.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
import socket,keyboard
serverAddressPort = ("192.168.137.224", 9999)
UDPClientSocket = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)
thr = 0
kp = 175
ki = 15
kd = 121
data = ""
DATA = ""
while True:
prevDATA = DATA
prevdata = data
roll = 50
pitch = 50
yaw = 50
key = keyboard.get_hotkey_name()
if key == "7":
roll = 20
if key == "9":
roll = 70
if key == "/":
pitch = 70
if key == "8":
pitch = 20
if key == "q":
if thr < 100:
thr = thr + 0.001
if key == "a":
if thr > 0:
thr = thr - 0.001
if key == "4":
if kp < 600:
kp += 0.001
if key == "1":
if kp > 0:
kp -= 0.001
if key == "5":
if ki < 600:
ki += 0.001
if key == "2":
if ki > 0:
ki -= 0.001
if key == "6":
if kd < 600:
kd += 0.001
if key == "3":
if kd > 0:
kd -= 0.001
if key == "enter":
kp = 175
ki = 15
kd = 121
data = str(roll) + str(pitch) + str(round(thr)) + str(yaw)
datachar = chr(roll) + chr(pitch) + chr(int(round(thr))) + chr(yaw)
if data != prevdata:
UDPClientSocket.sendto(datachar.encode(),serverAddressPort)
print("trans: ", data)
print("trans_c: ", datachar)
recvdata = UDPClientSocket.recv(10)
# print("recv: ", recvdata)