-
Notifications
You must be signed in to change notification settings - Fork 0
/
roomba-ui.py
44 lines (39 loc) · 1.28 KB
/
roomba-ui.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
#!/usr/bin/env python3
import curses
from curses import wrapper
from math import floor
from time import time, sleep
from pycreate2 import Create2
class RoombaController:
def __init__(self, port='/dev/ttyUSB0', baud=115200):
self.bot = Create2(port, baud=baud)
self.bot.start()
self.bot.full()
self.bot.drive_stop()
def __del__(self):
del self.bot
def main(port='/dev/ttyUSB0', baud=115200):
try:
controller = RoombaController(port, baud)
def curses_main(stdscr):
stdscr.nodelay(True)
while True:
try:
key = stdscr.getkey()
if key == 'KEY_UP':
controller.bot.drive_straight(500)
elif key == 'KEY_DOWN':
controller.bot.drive_straight(-100)
elif key == 'KEY_LEFT':
controller.bot.drive_rotate(100, 1)
elif key == 'KEY_RIGHT':
controller.bot.drive_rotate(100, -1)
elif key == ' ':
controller.bot.drive_stop()
except curses.error:
pass
wrapper(curses_main)
finally:
pass
if __name__ == '__main__':
main()