-
Notifications
You must be signed in to change notification settings - Fork 0
/
drive.py
53 lines (39 loc) · 1.12 KB
/
drive.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
from sshkeyboard import listen_keyboard_manual
import asyncio
from self_drive.client import distance_gen
from SelfCorrectingRobot import SelfCorrectingRobot
# from SelfCorrectingRobot import SelfCorrectingRobot
# bot = SelfCorrectingRobot()
from SafeDrive import SafeDrive
motors = SelfCorrectingRobot()
bot = SafeDrive(motors,distance_gen)
async def start_listening():
#do i need to put a sleep in here, how often does it poll input may use up resources?
await listen_keyboard_manual(
on_press=press,
)
async def main():
listen = asyncio.create_task(start_listening())
runRobot = asyncio.create_task(bot.start())
runMotors = asyncio.create_task(motors.start())
await listen
async def press(key):
print(f"'{key}' pressed")
if(key=='up'):
bot.forward(50)
elif(key=='down'):
bot.backward(50)
elif(key=='left'):
bot.pivot_left(40)
elif(key=='right'):
bot.pivot_right(40)
elif(key=='space'):
bot.stop()
def release(key):
print(f"'{key}' released")
try:
asyncio.run(main())
except KeyboardInterrupt:
bot.stop
finally:
bot.stop