-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpose_example.py
82 lines (62 loc) · 2.26 KB
/
pose_example.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
73
74
75
76
77
78
79
80
81
82
from arduino_alvik import ArduinoAlvik
from time import sleep_ms
import sys
alvik = ArduinoAlvik()
alvik.begin()
while True:
try:
alvik.move(100.0, 'mm')
print("on target after move")
alvik.move(50.0, 'mm')
print("on target after move")
alvik.rotate(90.0, 'deg')
print("on target after rotation")
alvik.rotate(-45.00, 'deg')
print("on target after rotation")
x, y, theta = alvik.get_pose()
print(f'Current pose is x(cm)={x}, y(cm)={y}, theta(deg)={theta}')
alvik.reset_pose(0, 0, 0)
x, y, theta = alvik.get_pose()
print(f'Updated pose is x(cm)={x}, y(cm)={y}, theta(deg)={theta}')
sleep_ms(500)
print("___________NON-BLOCKING__________________")
alvik.move(50.0, 'mm', blocking=False)
while not alvik.is_target_reached():
alvik.left_led.set_color(1, 0, 0)
sleep_ms(500)
alvik.left_led.set_color(0, 0, 0)
sleep_ms(500)
print("on target after move")
alvik.rotate(45.0, 'deg', blocking=False)
while not alvik.is_target_reached():
alvik.left_led.set_color(1, 0, 0)
sleep_ms(500)
alvik.left_led.set_color(0, 0, 0)
sleep_ms(500)
print("on target after rotation")
alvik.move(100.0, 'mm', blocking=False)
while not alvik.is_target_reached():
alvik.left_led.set_color(1, 0, 0)
sleep_ms(500)
alvik.left_led.set_color(0, 0, 0)
sleep_ms(500)
print("on target after move")
alvik.rotate(-90.00, 'deg', blocking=False)
while not alvik.is_target_reached():
alvik.left_led.set_color(1, 0, 0)
sleep_ms(500)
alvik.left_led.set_color(0, 0, 0)
sleep_ms(500)
print("on target after rotation")
x, y, theta = alvik.get_pose()
print(f'Current pose is x(cm)={x}, y(cm)={y}, theta(deg)={theta}')
alvik.reset_pose(0, 0, 0)
x, y, theta = alvik.get_pose()
print(f'Updated pose is x={x}, y={y}, theta(deg)={theta}')
sleep_ms(500)
alvik.stop()
sys.exit()
except KeyboardInterrupt as e:
print('over')
alvik.stop()
sys.exit()