forked from payneio/md25_motor_controller_library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrive.py
37 lines (32 loc) · 743 Bytes
/
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
from MD25 import MD25
import tty, time, termios, fcntl, sys, os
controller = MD25(0x58,1,True)
class _GetchUnix:
def __init__(self):
import tty, sys
def __call__(self):
import sys, tty, termios
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
getch = _GetchUnix()
k = ''
while k != 'x':
k = getch()
if k == 's':
controller.forward(1)
elif k == 'w':
controller.forward(255)
elif k == 'd':
controller.turn(255,1)
elif k == 'a':
controller.turn(1,255)
else:
controller.stop()
time.sleep(0.1)
controller.stop()