Skip to content

Commit f9937b6

Browse files
committed
fix to work with v1.0.0
1 parent cf4a60f commit f9937b6

File tree

1 file changed

+23
-27
lines changed

1 file changed

+23
-27
lines changed

roboticstoolbox/examples/fetch_vision.py

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def transform_between_vectors(a, b):
2323

2424
return sm.SE3.AngleAxis(angle, axis)
2525

26+
2627
# Launch the simulator Swift
2728
env = swift.Swift()
2829
env.launch()
@@ -43,7 +44,7 @@ def transform_between_vectors(a, b):
4344
centroid_sight = sg.Cylinder(
4445
radius=0.001,
4546
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,
4748
)
4849

4950
# Add the Fetch and other shapes to the simulator
@@ -55,7 +56,7 @@ def transform_between_vectors(a, b):
5556
# Set the desired end-effector pose to the location of target
5657
Tep = fetch.fkine(fetch.q)
5758
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]
5960

6061
env.step()
6162

@@ -68,9 +69,9 @@ def transform_between_vectors(a, b):
6869
def step():
6970

7071
# Find end-effector pose in world frame
71-
wTe = fetch.fkine(fetch.q, fast=True)
72+
wTe = fetch.fkine(fetch.q).A
7273
# 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
7475

7576
# Find transform between end-effector and goal
7677
eTep = np.linalg.inv(wTe) @ Tep.A
@@ -87,34 +88,27 @@ def w_lambda(et, alpha, gamma):
8788
# Quadratic component of objective function
8889
Q = np.eye(n + 10)
8990

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
9798

9899
# Calculate target velocities for end-effector to reach target
99100
v_manip, _ = rtb.p_servo(wTe, Tep, 1.5)
100101
v_manip[3:] *= 1.3
101102

102103
# 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])
106105
v_camera, _ = rtb.p_servo(sm.SE3(), head_rotation, 25)
107106

108107
# 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))]
115109
beq = v_manip.reshape((6,))
116110

117-
jacobe_cam = fetch_camera.jacobe(fetch_camera.q, fast=True)[3:, :]
111+
jacobe_cam = fetch_camera.jacobe(fetch_camera.q)[3:, :]
118112
Aeq_cam = np.c_[
119113
jacobe_cam[:, :3],
120114
np.zeros((3, 7)),
@@ -162,10 +156,12 @@ def w_lambda(et, alpha, gamma):
162156
xi=1.0,
163157
end=fetch.link_dict["gripper_link"],
164158
start=fetch.link_dict["shoulder_pan_link"],
165-
)
159+
)
166160

167161
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+
]
169165

170166
Ain = np.r_[Ain, c_Ain]
171167
bin = np.r_[bin, c_bin]
@@ -174,15 +170,16 @@ def w_lambda(et, alpha, gamma):
174170
c = np.concatenate(
175171
(
176172
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),
178175
np.zeros(n_camera),
179176
np.zeros(10),
180177
)
181178
)
182179

183180
# Get base to face end-effector
184181
= 0.5
185-
bTe = fetch.fkine(fetch.q, include_base=False, fast=True)
182+
bTe = fetch.fkine(fetch.q, include_base=False).A
186183
θε = math.atan2(bTe[1, -1], bTe[0, -1])
187184
ε = * θε
188185
c[0] = -ε
@@ -217,7 +214,7 @@ def w_lambda(et, alpha, gamma):
217214

218215
fetch.qd = qd
219216
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
221218

222219
return arrived
223220

@@ -226,4 +223,3 @@ def w_lambda(et, alpha, gamma):
226223
while not arrived:
227224
arrived = step()
228225
env.step(0.01)
229-

0 commit comments

Comments
 (0)