Skip to content

Commit 1d540c3

Browse files
committed
Merge branch 'main' into gh_package_name
2 parents 93fe365 + 97d6f49 commit 1d540c3

File tree

10 files changed

+193
-106
lines changed

10 files changed

+193
-106
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ Unreleased
1212

1313
**Added**
1414

15+
* Added support for attached and non-attached collision mesh visualization to the ``Robot Visualize`` GH component.
1516
* Added a prefix to all GH components.
1617

1718
**Changed**
1819

20+
* Changed behavior of ``Attach Tool`` GH component to only attach the tool but not add it to the planning scene state.
21+
1922
**Fixed**
2023

2124
* Fixed DH params for analytical IK solver of UR3e and UR10e.

docs/examples/03_backends_ros/02_robot_models.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Robots in ROS
55
.. note::
66

77
The following examples use the `ROS <https://www.ros.org/>`_ backend
8-
and the MoveI! planner for UR5 robots. Before running them, please
8+
and the MoveIt! planner for UR5 robots. Before running them, please
99
make sure you have the :ref:`ROS backend <ros_backend>` correctly
1010
configured and the :ref:`UR5 Demo <ros_bundles_list>` started.
1111

docs/examples/03_backends_ros/03_forward_and_inverse_kinematics.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Forward and inverse kinematics
99
.. note::
1010

1111
The following examples use the `ROS <https://www.ros.org/>`_ backend
12-
and the MoveI! planner for UR5 robots. Before running them, please
12+
and the MoveIt! planner for UR5 robots. Before running them, please
1313
make sure you have the :ref:`ROS backend <ros_backend>` correctly
1414
configured and the :ref:`UR5 Demo <ros_bundles_list>` started.
1515

docs/examples/03_backends_ros/04_plan_motion.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Plan motion
55
.. note::
66

77
The following examples use the `ROS <https://www.ros.org/>`_ backend
8-
and the MoveI! planner for UR5 robots. Before running them, please
8+
and the MoveIt! planner for UR5 robots. Before running them, please
99
make sure you have the :ref:`ROS backend <ros_backend>` correctly
1010
configured and the :ref:`UR5 Demo <ros_bundles_list>` started.
1111

docs/examples/03_backends_ros/05_collision_objects.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Planning scene and collision objects
55
.. note::
66

77
The following examples use the `ROS <https://www.ros.org/>`_ backend
8-
and the MoveI! planner for UR5 robots. Before running them, please
8+
and the MoveIt! planner for UR5 robots. Before running them, please
99
make sure you have the :ref:`ROS backend <ros_backend>` correctly
1010
configured and the :ref:`UR5 Demo <ros_bundles_list>` started.
1111

src/compas_fab/backends/kinematics/solvers/offset_wrist.py

Lines changed: 93 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -35,32 +35,47 @@ def forward_kinematics_offset_wrist(joint_values, params):
3535
s23, c23 = sin(q23), cos(q23)
3636
s234, c234 = sin(q234), cos(q234)
3737

38-
T = [0. for _ in range(4*4)]
39-
40-
T[0] = c234*c1*s5 - c5*s1
41-
T[1] = c6*(s1*s5 + c234*c1*c5) - s234*c1*s6
42-
T[2] = -s6*(s1*s5 + c234*c1*c5) - s234*c1*c6
43-
T[3] = d6*c234*c1*s5 - a3*c23*c1 - a2 * \
44-
c1*c2 - d6*c5*s1 - d5*s234*c1 - d4*s1
45-
T[4] = c1*c5 + c234*s1*s5
46-
T[5] = -c6*(c1*s5 - c234*c5*s1) - s234*s1*s6
47-
T[6] = s6*(c1*s5 - c234*c5*s1) - s234*c6*s1
48-
T[7] = d6*(c1*c5 + c234*s1*s5) + d4*c1 - \
49-
a3*c23*s1 - a2*c2*s1 - d5*s234*s1
50-
T[8] = -s234*s5
51-
T[9] = -c234*s6 - s234*c5*c6
52-
T[10] = s234*c5*s6 - c234*c6
53-
T[11] = d1 + a3*s23 + a2*s2 - d5 * \
54-
(c23*c4 - s23*s4) - d6*s5*(c23*s4 + s23*c4)
38+
T = [0.0 for _ in range(4 * 4)]
39+
40+
T[0] = c234 * c1 * s5 - c5 * s1
41+
T[1] = c6 * (s1 * s5 + c234 * c1 * c5) - s234 * c1 * s6
42+
T[2] = -s6 * (s1 * s5 + c234 * c1 * c5) - s234 * c1 * c6
43+
T[3] = (
44+
d6 * c234 * c1 * s5
45+
- a3 * c23 * c1
46+
- a2 * c1 * c2
47+
- d6 * c5 * s1
48+
- d5 * s234 * c1
49+
- d4 * s1
50+
)
51+
T[4] = c1 * c5 + c234 * s1 * s5
52+
T[5] = -c6 * (c1 * s5 - c234 * c5 * s1) - s234 * s1 * s6
53+
T[6] = s6 * (c1 * s5 - c234 * c5 * s1) - s234 * c6 * s1
54+
T[7] = (
55+
d6 * (c1 * c5 + c234 * s1 * s5)
56+
+ d4 * c1
57+
- a3 * c23 * s1
58+
- a2 * c2 * s1
59+
- d5 * s234 * s1
60+
)
61+
T[8] = -s234 * s5
62+
T[9] = -c234 * s6 - s234 * c5 * c6
63+
T[10] = s234 * c5 * s6 - c234 * c6
64+
T[11] = (
65+
d1
66+
+ a3 * s23
67+
+ a2 * s2
68+
- d5 * (c23 * c4 - s23 * s4)
69+
- d6 * s5 * (c23 * s4 + s23 * c4)
70+
)
5571
T[15] = 1.0
5672

57-
frame = Frame((T[3], T[7], T[11]),
58-
(T[0], T[4], T[8]), (T[1], T[5], T[9]))
73+
frame = Frame((T[3], T[7], T[11]), (T[0], T[4], T[8]), (T[1], T[5], T[9]))
5974

6075
return frame
6176

6277

63-
def inverse_kinematics_offset_wrist(frame, params, q6_des=0.):
78+
def inverse_kinematics_offset_wrist(frame, params, q6_des=0.0):
6479
"""Inverse kinematics function for offset wrist 6-axis robots.
6580
6681
Parameters
@@ -101,57 +116,57 @@ def inverse_kinematics_offset_wrist(frame, params, q6_des=0.):
101116
A = d6 * T12 - T13
102117
B = d6 * T02 - T03
103118
R = A * A + B * B
104-
if(fabs(A) < ZERO_THRESH):
119+
if fabs(A) < ZERO_THRESH:
105120
div = 0.0
106-
if(fabs(fabs(d4) - fabs(B)) < ZERO_THRESH):
121+
if fabs(fabs(d4) - fabs(B)) < ZERO_THRESH:
107122
div = -sign(d4) * sign(B)
108123
else:
109124
div = -d4 / B
110125
arcsin = asin(div)
111-
if(fabs(arcsin) < ZERO_THRESH):
126+
if fabs(arcsin) < ZERO_THRESH:
112127
arcsin = 0.0
113-
if(arcsin < 0.0):
128+
if arcsin < 0.0:
114129
q1[0] = arcsin + 2.0 * pi
115130
else:
116131
q1[0] = arcsin
117132
q1[1] = pi - arcsin
118133

119-
elif(fabs(B) < ZERO_THRESH):
134+
elif fabs(B) < ZERO_THRESH:
120135
div = 0.0
121-
if(fabs(fabs(d4) - fabs(A)) < ZERO_THRESH):
122-
div = sign(d4)*sign(A)
136+
if fabs(fabs(d4) - fabs(A)) < ZERO_THRESH:
137+
div = sign(d4) * sign(A)
123138
else:
124139
div = d4 / A
125140
arccos = acos(div)
126141
q1[0] = arccos
127142
q1[1] = 2.0 * pi - arccos
128143

129-
elif(d4 * d4 > R):
144+
elif d4 * d4 > R:
130145
raise ValueError("No solutions")
131146
else:
132147
arccos = acos(d4 / sqrt(R))
133148
arctan = atan2(-B, A)
134149
pos = arccos + arctan
135150
neg = -arccos + arctan
136-
if(fabs(pos) < ZERO_THRESH):
151+
if fabs(pos) < ZERO_THRESH:
137152
pos = 0.0
138-
if(fabs(neg) < ZERO_THRESH):
153+
if fabs(neg) < ZERO_THRESH:
139154
neg = 0.0
140-
if(pos >= 0.0):
155+
if pos >= 0.0:
141156
q1[0] = pos
142157
else:
143-
q1[0] = 2.0*pi + pos
144-
if(neg >= 0.0):
158+
q1[0] = 2.0 * pi + pos
159+
if neg >= 0.0:
145160
q1[1] = neg
146161
else:
147-
q1[1] = 2.0*pi + neg
162+
q1[1] = 2.0 * pi + neg
148163

149164
# wrist 2 joint (q5)
150165
q5 = [[0, 0], [0, 0]]
151166
for i in range(2):
152-
numer = (T03 * sin(q1[i]) - T13*cos(q1[i]) - d4)
167+
numer = T03 * sin(q1[i]) - T13 * cos(q1[i]) - d4
153168
div = 0.0
154-
if(fabs(fabs(numer) - fabs(d6)) < ZERO_THRESH):
169+
if fabs(fabs(numer) - fabs(d6)) < ZERO_THRESH:
155170
div = sign(numer) * sign(d6)
156171
else:
157172
div = numer / d6
@@ -168,62 +183,66 @@ def inverse_kinematics_offset_wrist(frame, params, q6_des=0.):
168183
q6 = 0.0
169184

170185
# wrist 3 joint (q6)
171-
if(fabs(s5) < ZERO_THRESH):
186+
if fabs(s5) < ZERO_THRESH:
172187
q6 = q6_des
173188
else:
174-
q6 = atan2(sign(s5)*-(T01*s1 - T11*c1),
175-
sign(s5)*(T00*s1 - T10*c1))
176-
if(fabs(q6) < ZERO_THRESH):
189+
q6 = atan2(
190+
sign(s5) * -(T01 * s1 - T11 * c1), sign(s5) * (T00 * s1 - T10 * c1)
191+
)
192+
if fabs(q6) < ZERO_THRESH:
177193
q6 = 0.0
178-
if(q6 < 0.0):
179-
q6 += 2.0*pi
194+
if q6 < 0.0:
195+
q6 += 2.0 * pi
180196

181197
# RRR joints (q2,q3,q4)
182198
q2, q3, q4 = [0, 0], [0, 0], [0, 0]
183199

184200
c6 = cos(q6)
185201
s6 = sin(q6)
186-
x04x = -s5*(T02*c1 + T12*s1) - c5 * \
187-
(s6*(T01*c1 + T11*s1) - c6*(T00*c1 + T10*s1))
188-
x04y = c5*(T20*c6 - T21*s6) - T22*s5
189-
p13x = d5*(s6*(T00*c1 + T10*s1) + c6*(T01*c1 + T11*s1)
190-
) - d6*(T02*c1 + T12*s1) + T03*c1 + T13*s1
191-
p13y = T23 - d1 - d6*T22 + d5*(T21*c6 + T20*s6)
192-
193-
c3 = (p13x*p13x + p13y*p13y - a2*a2 - a3*a3) / (2.0*a2*a3)
194-
if(fabs(fabs(c3) - 1.0) < ZERO_THRESH):
202+
x04x = -s5 * (T02 * c1 + T12 * s1) - c5 * (
203+
s6 * (T01 * c1 + T11 * s1) - c6 * (T00 * c1 + T10 * s1)
204+
)
205+
x04y = c5 * (T20 * c6 - T21 * s6) - T22 * s5
206+
p13x = (
207+
d5 * (s6 * (T00 * c1 + T10 * s1) + c6 * (T01 * c1 + T11 * s1))
208+
- d6 * (T02 * c1 + T12 * s1)
209+
+ T03 * c1
210+
+ T13 * s1
211+
)
212+
p13y = T23 - d1 - d6 * T22 + d5 * (T21 * c6 + T20 * s6)
213+
214+
c3 = (p13x * p13x + p13y * p13y - a2 * a2 - a3 * a3) / (2.0 * a2 * a3)
215+
if fabs(fabs(c3) - 1.0) < ZERO_THRESH:
195216
c3 = sign(c3)
196-
elif(fabs(c3) > 1.0):
217+
elif fabs(c3) > 1.0:
197218
solutions.extend([None, None])
198219
continue
199220

200221
arccos = acos(c3)
201222
q3[0] = arccos
202-
q3[1] = 2.0*pi - arccos
203-
denom = a2*a2 + a3*a3 + 2*a2*a3*c3
223+
q3[1] = 2.0 * pi - arccos
224+
denom = a2 * a2 + a3 * a3 + 2 * a2 * a3 * c3
204225
s3 = sin(arccos)
205-
A = (a2 + a3*c3)
206-
B = a3*s3
207-
q2[0] = atan2((A*p13y - B*p13x) / denom,
208-
(A*p13x + B*p13y) / denom)
209-
q2[1] = atan2((A*p13y + B*p13x) / denom,
210-
(A*p13x - B*p13y) / denom)
211-
c23_0 = cos(q2[0]+q3[0])
212-
s23_0 = sin(q2[0]+q3[0])
213-
c23_1 = cos(q2[1]+q3[1])
214-
s23_1 = sin(q2[1]+q3[1])
215-
q4[0] = atan2(c23_0*x04y - s23_0*x04x, x04x*c23_0 + x04y*s23_0)
216-
q4[1] = atan2(c23_1*x04y - s23_1*x04x, x04x*c23_1 + x04y*s23_1)
226+
A = a2 + a3 * c3
227+
B = a3 * s3
228+
q2[0] = atan2((A * p13y - B * p13x) / denom, (A * p13x + B * p13y) / denom)
229+
q2[1] = atan2((A * p13y + B * p13x) / denom, (A * p13x - B * p13y) / denom)
230+
c23_0 = cos(q2[0] + q3[0])
231+
s23_0 = sin(q2[0] + q3[0])
232+
c23_1 = cos(q2[1] + q3[1])
233+
s23_1 = sin(q2[1] + q3[1])
234+
q4[0] = atan2(c23_0 * x04y - s23_0 * x04x, x04x * c23_0 + x04y * s23_0)
235+
q4[1] = atan2(c23_1 * x04y - s23_1 * x04x, x04x * c23_1 + x04y * s23_1)
217236

218237
for k in range(2):
219-
if(fabs(q2[k]) < ZERO_THRESH):
238+
if fabs(q2[k]) < ZERO_THRESH:
220239
q2[k] = 0.0
221-
elif(q2[k] < 0.0):
222-
q2[k] += 2.0*pi
223-
if(fabs(q4[k]) < ZERO_THRESH):
240+
elif q2[k] < 0.0:
241+
q2[k] += 2.0 * pi
242+
if fabs(q4[k]) < ZERO_THRESH:
224243
q4[k] = 0.0
225-
elif(q4[k] < 0.0):
226-
q4[k] += 2.0*pi
244+
elif q4[k] < 0.0:
245+
q4[k] += 2.0 * pi
227246

228247
solutions.append([q1[i], q2[k], q3[k], q4[k], q5[i][j], q6])
229248

@@ -232,8 +251,9 @@ def inverse_kinematics_offset_wrist(frame, params, q6_des=0.):
232251

233252
if __name__ == "__main__":
234253
from compas.geometry import allclose
254+
235255
params = [0.089159, -0.42500, -0.39225, 0.10915, 0.09465, 0.0823] # ur5
236256
q = [0.2, 5.5, 1.4, 1.3, 2.6, 3.6]
237257
frame = forward_kinematics_offset_wrist(q, params)
238258
sol = inverse_kinematics_offset_wrist(frame, params)
239-
assert(allclose(sol[0], q))
259+
assert allclose(sol[0], q)

src/compas_fab/backends/kinematics/utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@ def fit_within_bounds(angle, lower, upper):
1717
angle += 2 * math.pi
1818
while angle > upper:
1919
angle -= 2 * math.pi
20-
assert(angle >= lower and angle <= upper), "Joint angle out of bounds."
20+
assert angle >= lower and angle <= upper, "Joint angle out of bounds."
2121
return angle
2222

2323

2424
def joint_angles_to_configurations(robot, solutions, group=None):
2525
joint_names = robot.get_configurable_joint_names(group=group)
26-
return [Configuration.from_revolute_values(q, joint_names=joint_names) if q else None for q in solutions]
26+
return [
27+
Configuration.from_revolute_values(q, joint_names=joint_names) if q else None
28+
for q in solutions
29+
]
2730

2831

2932
def try_to_fit_configurations_between_bounds(robot, configurations, group=None):

src/compas_fab/ghpython/components/Cf_AttachTool/code.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from compas_rhino.conversions import plane_to_compas_frame
99

1010
from compas.geometry import Frame
11-
from compas_fab.robots import PlanningScene
1211
from compas_fab.robots import Tool
1312

1413

@@ -27,8 +26,6 @@ def RunScript(self, robot, visual_mesh, collision_mesh, tcf_plane, group):
2726
frame = plane_to_compas_frame(tcf_plane)
2827
tool = Tool(c_visual_mesh, frame, c_collision_mesh)
2928

30-
scene = PlanningScene(robot)
3129
robot.attach_tool(tool, group)
32-
scene.add_attached_tool()
3330

3431
return robot

0 commit comments

Comments
 (0)