-
Notifications
You must be signed in to change notification settings - Fork 0
/
control_projection.py
72 lines (65 loc) · 1.98 KB
/
control_projection.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
# https://websockets.readthedocs.io/en/3.0/intro.html
import asyncio
import websockets
import keyboard
import time
server_address = 'ws://172.31.83.56:8765'
async def setStartingValues():
async with websockets.connect(server_address) as websocket:
await websocket.send('setx 0')
await websocket.recv()
await websocket.send('sety 0')
await websocket.recv()
await websocket.send('setz 0')
await websocket.recv()
await websocket.send('setxr 0')
await websocket.recv()
await websocket.send('setyr 0')
await websocket.recv()
async def getAndIncrease(label, inc):
# print("Function call")
async with websockets.connect(server_address) as websocket:
send = 'get' + label
# print("Sending: " + send)
await websocket.send(send)
value = await websocket.recv()
# print("Recieved: " + value)
value = float(value) + inc
send = 'set' + label + " " + str(value)
# print("Sending: " + send)
await websocket.send(send)
value = await websocket.recv()
# print("Recieved: " + value)
def main():
asyncio.get_event_loop().run_until_complete(setStartingValues())
while True:
try:
if keyboard.is_pressed('w'):
asyncio.get_event_loop().run_until_complete(getAndIncrease('x', 0.05))
time.sleep(0.5)
# break
elif keyboard.is_pressed('s'):
asyncio.get_event_loop().run_until_complete(getAndIncrease('x', -0.05))
time.sleep(0.5)
# break
elif keyboard.is_pressed('a'):
asyncio.get_event_loop().run_until_complete(getAndIncrease('y', 0.05))
time.sleep(0.5)
# break
elif keyboard.is_pressed('d'):
asyncio.get_event_loop().run_until_complete(getAndIncrease('y', -0.05))
time.sleep(0.5)
# break
elif keyboard.is_pressed('q'):
asyncio.get_event_loop().run_until_complete(getAndIncrease('z', 0.05))
time.sleep(0.5)
# break
elif keyboard.is_pressed('e'):
asyncio.get_event_loop().run_until_complete(getAndIncrease('z', -0.05))
time.sleep(0.5)
# break
except:
# break
continue
if __name__ == '__main__':
main()