This repository has been archived by the owner on Feb 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
pointing_objects.py
82 lines (59 loc) · 2.06 KB
/
pointing_objects.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
import time
from reachy import Leachy
leachy = Leachy()
screen_size = (520, 320) # in mm
joints = { # in degrees
'cat': [-40.02, 10.04, 27.56, -80.75, -3.67, -12.2, -12.76],
'tomato': [-34.48, 11.45, 9.1, -91.38, -1.32, 0.44, -12.46],
'chocolatine': [-34.66, -6.0, -0.4, -94.99, -1.32, 3.67, -12.46],
'wall_e': [-35.1, -12.37, -15.16, -86.29, -1.32, -6.89, -12.46],
'kangoo': [-24.64, 12.15, 24.4, -70.55, -0.44, -17.74, -10.12],
'cow': [-21.12, 2.57, 12.18, -78.29, -0.44, -18.62, -10.12],
'snes': [-19.8, -4.81, -4.18, -81.45, -0.44, -19.21, -10.12],
'coffee': [-23.23, -11.32, -18.77, -74.42, -0.44, -24.19, -10.12],
'center': [-14.26, -0.07, 2.07, -87.34, -0.15, -17.16, -7.18],
'outside_fov': [9.12, 6.79, 21.67, -123.47, 15.4, 23.02, -22.14],
}
pos_2d = { # in mm (origin top left)
'cat': (40, 70),
'tomato': (205, 70),
'chocolatine': (370, 70),
'wall_e': (525, 70),
'kangoo': (50, 230),
'cow': (210, 220),
'snes': (370, 230),
'coffee': (520, 230),
}
def find_nearest_object(x, y):
dist = {
corner: (xc - x) ** 2 + (yc - y) ** 2
for (corner, (xc, yc)) in pos_2d.items()
}
return min(dist, key=dist.get)
def goto_object(obj, t):
print('Goto obj:', obj)
q = joints[obj]
for m, p in zip(leachy.motors, q):
m.goto_position(p, t, control='minjerk')
time.sleep(t + 0.5)
def goto_2d(x2, y2, t):
x2 = min(max(x2, 0), 1)
y2 = min(max(y2, 0), 1)
x2 *= screen_size[0]
y2 *= screen_size[1]
obj = find_nearest_object(x2, y2)
goto_object(obj, t)
def goto_rest(t):
for m, p in zip(leachy.motors, joints['center']):
m.goto_position(p, t, control='minjerk')
time.sleep(t)
if __name__ == '__main__':
""" Example: python pointing_objects.py snes cow cat """
import sys
for m in leachy.motors:
m.compliant = False
m.moving_speed = 0
goto_rest(2)
for obj in sys.argv[1:]:
goto_object(obj, 1)
goto_rest(2)