-
Notifications
You must be signed in to change notification settings - Fork 0
/
zServer.py
69 lines (63 loc) · 1.6 KB
/
zServer.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
from multiprocessing.connection import Listener
from threading import Thread
import time
from codrone_edu.drone import *
from codrone_edu.protocol import *
from numpy import clip
import keyboard
# Setup
drone = Drone()
drone.pair()
inAir = False
landingVal = 0.5
takeoffVal = 2
scalingVal = 50
normFactor = 5.0
# Client
def child(conn):
global old_time
global blinkCounter
global inAir
global landingVal
global takeoffVal
global scalingVal
while True:
val = conn.recv()
# Takeoff and Land
# Drone up
if inAir == True:
# Moving the drone
if val >= landingVal:
# Add more functions here
if val >= 0.75:
# Move forward
print("Moving Forward")
pitch = clip((val/upperThresh) * scalingVal, 0, scalingVal)
pitch = int(pitch)
print(pitch)
drone.go(0, pitch, 0, 0, 0.5)
# Land
elif val < landingVal:
if inAir == True:
print("Landing")
drone.land()
inAir = False
# Drone down
elif inAir == False:
# Takeoff
if val >= takeoffVal:
print("Taking Off")
drone.takeoff()
inAir = True
# Server
def mother(address):
serv = Listener(address)
while True:
client = serv.accept()
child(client)
try:
mother(("", 5001))
# Emergency landing
except KeyboardInterrupt:
drone.land()
drone.close()