@@ -23,6 +23,7 @@ def transform_between_vectors(a, b):
23
23
24
24
return sm .SE3 .AngleAxis (angle , axis )
25
25
26
+
26
27
# Launch the simulator Swift
27
28
env = swift .Swift ()
28
29
env .launch ()
@@ -43,7 +44,7 @@ def transform_between_vectors(a, b):
43
44
centroid_sight = sg .Cylinder (
44
45
radius = 0.001 ,
45
46
length = 5.0 ,
46
- base = fetch_camera .fkine (fetch_camera .q , fast = True ) @ sight_base .A ,
47
+ base = fetch_camera .fkine (fetch_camera .q ). A @ sight_base .A ,
47
48
)
48
49
49
50
# Add the Fetch and other shapes to the simulator
@@ -55,7 +56,7 @@ def transform_between_vectors(a, b):
55
56
# Set the desired end-effector pose to the location of target
56
57
Tep = fetch .fkine (fetch .q )
57
58
Tep .A [:3 , :3 ] = sm .SE3 .Rz (np .pi ).R
58
- Tep .A [:3 , 3 ] = target .base . t
59
+ Tep .A [:3 , 3 ] = target .T [: 3 , - 1 ]
59
60
60
61
env .step ()
61
62
@@ -68,9 +69,9 @@ def transform_between_vectors(a, b):
68
69
def step ():
69
70
70
71
# Find end-effector pose in world frame
71
- wTe = fetch .fkine (fetch .q , fast = True )
72
+ wTe = fetch .fkine (fetch .q ). A
72
73
# Find camera pose in world frame
73
- wTc = fetch_camera .fkine (fetch_camera .q , fast = True )
74
+ wTc = fetch_camera .fkine (fetch_camera .q ). A
74
75
75
76
# Find transform between end-effector and goal
76
77
eTep = np .linalg .inv (wTe ) @ Tep .A
@@ -87,34 +88,27 @@ def w_lambda(et, alpha, gamma):
87
88
# Quadratic component of objective function
88
89
Q = np .eye (n + 10 )
89
90
90
- Q [: n_base + n_arm , : n_base + n_arm ] *= 0.01 # Robotic manipulator
91
- Q [:n_base , :n_base ] *= w_lambda (et , 1.0 , - 1.0 ) # Mobile base
92
- Q [n_base + n_arm : n , n_base + n_arm : n ] *= 0.01 # Camera
93
- Q [n : n + 3 , n : n + 3 ] *= w_lambda (et , 1000.0 , - 2.0 ) # Slack arm linear
94
- Q [n + 3 : n + 6 , n + 3 : n + 6 ] *= w_lambda (et , 0.01 , - 5.0 ) # Slack arm angular
95
- Q [n + 6 : - 1 , n + 6 : - 1 ] *= 100 # Slack camera
96
- Q [- 1 , - 1 ] *= w_lambda (et , 1000.0 , 3.0 ) # Slack self-occlusion
91
+ Q [: n_base + n_arm , : n_base + n_arm ] *= 0.01 # Robotic manipulator
92
+ Q [:n_base , :n_base ] *= w_lambda (et , 1.0 , - 1.0 ) # Mobile base
93
+ Q [n_base + n_arm : n , n_base + n_arm : n ] *= 0.01 # Camera
94
+ Q [n : n + 3 , n : n + 3 ] *= w_lambda (et , 1000.0 , - 2.0 ) # Slack arm linear
95
+ Q [n + 3 : n + 6 , n + 3 : n + 6 ] *= w_lambda (et , 0.01 , - 5.0 ) # Slack arm angular
96
+ Q [n + 6 : - 1 , n + 6 : - 1 ] *= 100 # Slack camera
97
+ Q [- 1 , - 1 ] *= w_lambda (et , 1000.0 , 3.0 ) # Slack self-occlusion
97
98
98
99
# Calculate target velocities for end-effector to reach target
99
100
v_manip , _ = rtb .p_servo (wTe , Tep , 1.5 )
100
101
v_manip [3 :] *= 1.3
101
102
102
103
# Calculate target angular velocity for camera to rotate towards target
103
- head_rotation = transform_between_vectors (
104
- np .array ([1 , 0 , 0 ]), cTep [:3 , 3 ]
105
- )
104
+ head_rotation = transform_between_vectors (np .array ([1 , 0 , 0 ]), cTep [:3 , 3 ])
106
105
v_camera , _ = rtb .p_servo (sm .SE3 (), head_rotation , 25 )
107
106
108
107
# The equality contraints to achieve velocity targets
109
- Aeq = np .c_ [
110
- fetch .jacobe (fetch .q , fast = True ),
111
- np .zeros ((6 , 2 )),
112
- np .eye (6 ),
113
- np .zeros ((6 , 4 ))
114
- ]
108
+ Aeq = np .c_ [fetch .jacobe (fetch .q ), np .zeros ((6 , 2 )), np .eye (6 ), np .zeros ((6 , 4 ))]
115
109
beq = v_manip .reshape ((6 ,))
116
110
117
- jacobe_cam = fetch_camera .jacobe (fetch_camera .q , fast = True )[3 :, :]
111
+ jacobe_cam = fetch_camera .jacobe (fetch_camera .q )[3 :, :]
118
112
Aeq_cam = np .c_ [
119
113
jacobe_cam [:, :3 ],
120
114
np .zeros ((3 , 7 )),
@@ -162,10 +156,12 @@ def w_lambda(et, alpha, gamma):
162
156
xi = 1.0 ,
163
157
end = fetch .link_dict ["gripper_link" ],
164
158
start = fetch .link_dict ["shoulder_pan_link" ],
165
- )
159
+ )
166
160
167
161
if c_Ain is not None and c_bin is not None :
168
- c_Ain = np .c_ [c_Ain , np .zeros ((c_Ain .shape [0 ], 9 )), - np .ones ((c_Ain .shape [0 ], 1 ))]
162
+ c_Ain = np .c_ [
163
+ c_Ain , np .zeros ((c_Ain .shape [0 ], 9 )), - np .ones ((c_Ain .shape [0 ], 1 ))
164
+ ]
169
165
170
166
Ain = np .r_ [Ain , c_Ain ]
171
167
bin = np .r_ [bin , c_bin ]
@@ -174,15 +170,16 @@ def w_lambda(et, alpha, gamma):
174
170
c = np .concatenate (
175
171
(
176
172
np .zeros (n_base ),
177
- - fetch .jacobm (start = fetch .links [3 ]).reshape ((n_arm ,)),
173
+ # -fetch.jacobm(start=fetch.links[3]).reshape((n_arm,)),
174
+ np .zeros (n_arm ),
178
175
np .zeros (n_camera ),
179
176
np .zeros (10 ),
180
177
)
181
178
)
182
179
183
180
# Get base to face end-effector
184
181
kε = 0.5
185
- bTe = fetch .fkine (fetch .q , include_base = False , fast = True )
182
+ bTe = fetch .fkine (fetch .q , include_base = False ). A
186
183
θε = math .atan2 (bTe [1 , - 1 ], bTe [0 , - 1 ])
187
184
ε = kε * θε
188
185
c [0 ] = - ε
@@ -217,7 +214,7 @@ def w_lambda(et, alpha, gamma):
217
214
218
215
fetch .qd = qd
219
216
fetch_camera .qd = qd_cam
220
- centroid_sight ._base = fetch_camera .fkine (fetch_camera .q , fast = True ) @ sight_base .A
217
+ centroid_sight .T = fetch_camera .fkine (fetch_camera .q ). A @ sight_base .A
221
218
222
219
return arrived
223
220
@@ -226,4 +223,3 @@ def w_lambda(et, alpha, gamma):
226
223
while not arrived :
227
224
arrived = step ()
228
225
env .step (0.01 )
229
-
0 commit comments