Skip to content

Commit a3e6404

Browse files
authored
Merge pull request #376 from compas-dev/fix-spherical-wrist
Backwards-compatible fix for tangent_points_to_circle_xy
2 parents f5a4d7c + 3b152ef commit a3e6404

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Unreleased
2727
* Fixed DH params for analytical IK solver of UR3e and UR10e.
2828
* Fixed Kinetic support on IK, FK, and motion planning calls.
2929
* Fixed ``Publish to topic`` Grasshopper component when the ``ros_client`` has been replaced (eg. disconnected and reconnected).
30+
* Fixed usage of ``tangent_points_to_circle_xy`` in Spherica Wrist solver to work with COMPAS v1.16 and older.
3031

3132
**Deprecated**
3233

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,19 @@ def inverse_kinematics_spherical_wrist(target_frame, points):
145145
axis1_angle -= 2 * math.pi
146146
axis1_angles += [axis1_angle] * 4
147147
else:
148-
circle = (0, 0, 0), pln_offset
148+
circle = ((0, 0, 0), (0, 0, 1)), pln_offset
149149
point = (wrist.x, wrist.y, 0)
150-
t1, t2 = tangent_points_to_circle_xy(circle, point)
150+
# On COMPAS v1.17+, this function correctly expects a circle to be
151+
# defined as a plane and float (in which plane needs to be a point and vector)
152+
# however, in version v1.16 and older, the function expected only a point
153+
# we default to the correct behavior for v1.17+ but if we get a TypeError
154+
# it means an older COMPAS core is installed so we revert to defining the
155+
# circle in the old, incorrect way of using just a point and float
156+
try:
157+
t1, t2 = tangent_points_to_circle_xy(circle, point)
158+
except TypeError:
159+
circle = (0, 0, 0), pln_offset
160+
t1, t2 = tangent_points_to_circle_xy(circle, point)
151161
a1 = Vector(0, 1, 0).angle_signed(t1, (0, 0, -1))
152162
a2 = Vector(0, 1, 0).angle_signed(t2, (0, 0, -1))
153163
axis1_angles += [a1] * 4
@@ -185,9 +195,9 @@ def inverse_kinematics_spherical_wrist(target_frame, points):
185195
for k in range(2):
186196
axis2_angles.append(-axis2_angle)
187197
axis3_angle_wrapped = -axis3_angle + math.pi
188-
while (axis3_angle_wrapped >= math.pi):
198+
while axis3_angle_wrapped >= math.pi:
189199
axis3_angle_wrapped -= 2 * math.pi
190-
while (axis3_angle_wrapped < -math.pi):
200+
while axis3_angle_wrapped < -math.pi:
191201
axis3_angle_wrapped += 2 * math.pi
192202
axis3_angles.append(axis3_angle_wrapped)
193203

@@ -208,9 +218,9 @@ def inverse_kinematics_spherical_wrist(target_frame, points):
208218
axis4_angle -= 2 * math.pi
209219

210220
axis4_angle_wrapped = axis4_angle + math.pi / 2
211-
while (axis4_angle_wrapped >= math.pi):
221+
while axis4_angle_wrapped >= math.pi:
212222
axis4_angle_wrapped -= 2 * math.pi
213-
while (axis4_angle_wrapped < -math.pi):
223+
while axis4_angle_wrapped < -math.pi:
214224
axis4_angle_wrapped += 2 * math.pi
215225
axis4_angles.append(axis4_angle_wrapped)
216226

0 commit comments

Comments
 (0)