-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpid_move_test.py
58 lines (48 loc) · 1.34 KB
/
pid_move_test.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
from sw.hal import *
from sw.mapping import Mapper
from sw.gui import Window
from trollius import From
import trollius as asyncio
import numpy as np
from tamproxy import TAMProxy
@asyncio.coroutine
def main_task():
t = None
while True:
c = w.get_key()
new_t = None
if c == 'q':
break
elif c == 'm':
new_t = drive.turn_speed(np.radians(5))
elif c == 'w':
new_t = drive.turn_to(0)
elif c == 'e':
new_t = drive.go_to([24,0])
elif c == 'd':
new_t = drive.turn_to(np.pi)
elif c == 's':
new_t = drive.go_to([0,0])
elif c == ' ' and t:
t.cancel()
try:
yield From(t)
except asyncio.CancelledError:
pass
if new_t:
if t:
t.cancel()
try:
yield From(t)
except asyncio.CancelledError:
pass
t = asyncio.ensure_future(new_t)
yield From(asyncio.sleep(0.05))
if __name__ == "__main__":
with TAMProxy() as tamproxy:
drive = RegulatedDrive(tamproxy)
m = Mapper(drive.odometer)
w = Window(500, [m])
loop = asyncio.get_event_loop()
loop.run_until_complete(main_task())
loop.close()