forked from HaoruiPeng/InfoCom-LP2-Lab1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathown_controller.py
50 lines (43 loc) · 1.32 KB
/
own_controller.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
import requests
import time
import random
import click
from sense_hat import SenseHat
sense = SenseHat()
def get_direction():
d_long = 0
d_la = 0
send_vel = False
for event in sense.stick.get_events():
if event.action == "pressed":
if event.direction == "up":
print('Up')
send_vel = True
d_long = 0
d_la = 1
elif event.direction == "down":
print('Down')
send_vel = True
d_long = 0
d_la = -1
elif event.direction == "left":
print('Left')
send_vel = True
d_long = -1
d_la = 0
elif event.direction == "right":
print('Right')
send_vel = True
d_long = 1
d_la = 0
return d_long, d_la, send_vel
if __name__ == "__main__":
SERVER_URL = "http://127.0.0.1:5000/drone"
while True:
d_long, d_la, send_vel = get_direction()
if send_vel:
with requests.Session() as session:
current_location = {'longitude': d_long,
'latitude': d_la
}
resp = session.post(SERVER_URL, json=current_location)