Skip to content

Commit 43c8a04

Browse files
committed
make robust to unreachable point
1 parent 36e5038 commit 43c8a04

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

roboticstoolbox/models/DH/Puma560.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -282,20 +282,22 @@ def ik3(robot, T, config='lun'):
282282

283283
r = np.sqrt(V114**2 + Pz**2)
284284

285-
Psi = np.arccos(
286-
(a2**2 - d4**2 - a3**2 + V114**2 + Pz**2)
287-
/ (2.0 * a2 * r))
288-
289-
if np.isnan(Psi):
290-
theta = None # pragma nocover
291-
else:
292-
theta[1] = np.arctan2(Pz, V114) + n2 * Psi
293-
294-
# Solve for theta[2]
295-
# theta[2] uses equation 57, p. 40.
296-
num = np.cos(theta[1]) * V114 + np.sin(theta[1]) * Pz - a2
297-
den = np.cos(theta[1]) * Pz - np.sin(theta[1]) * V114
298-
theta[2] = np.arctan2(a3, d4) - np.arctan2(num, den)
285+
with np.errstate(invalid='raise'):
286+
try:
287+
Psi = np.arccos(
288+
(a2**2 - d4**2 - a3**2 + V114**2 + Pz**2)
289+
/ (2.0 * a2 * r))
290+
except FloatingPointError:
291+
return "Out of reach"
292+
293+
294+
theta[1] = np.arctan2(Pz, V114) + n2 * Psi
295+
296+
# Solve for theta[2]
297+
# theta[2] uses equation 57, p. 40.
298+
num = np.cos(theta[1]) * V114 + np.sin(theta[1]) * Pz - a2
299+
den = np.cos(theta[1]) * Pz - np.sin(theta[1]) * V114
300+
theta[2] = np.arctan2(a3, d4) - np.arctan2(num, den)
299301

300302
theta = base.angdiff(theta)
301303

0 commit comments

Comments
 (0)