Skip to content

Commit 4dd9574

Browse files
committed
fixed ik base class
1 parent e141c5e commit 4dd9574

File tree

1 file changed

+21
-14
lines changed
  • roboticstoolbox/robot

1 file changed

+21
-14
lines changed

roboticstoolbox/robot/IK.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,6 @@ def __init__(
9090
mask: A 6 vector which assigns weights to Cartesian degrees-of-freedom
9191
problems: Total number of IK problems within the experiment
9292
joint_limits: Reject solutions with joint limit violations
93-
94-
λΣ: The gain for joint limit avoidance. Setting to 0.0 will remove this completely from the solution
95-
λm: The gain for maximisation. Setting to 0.0 will remove this completely from the solution
96-
ps: The minimum angle/distance (in radians or metres) in which the joint is allowed to approach to its limit
97-
pi: The influence angle/distance (in radians or metres) in null space motion becomes active
9893
"""
9994

10095
# Solver parameters
@@ -131,27 +126,32 @@ def solve(
131126
"""
132127

133128
if q0 is None:
134-
q0 = ets.random_q(self.slimit)
129+
q0 = self.random_q(ets, self.slimit)
135130
elif not isinstance(q0, np.ndarray):
136131
q0 = np.array(q0)
137132

138133
if q0.ndim == 1:
139-
q0_new = ets.random_q(self.slimit)
134+
q0_new = self.random_q(ets, self.slimit)
140135
q0_new[0] = q0
141136
q0 = q0_new
142137

143138
# Iteration count
144139
i = 0
145140
total_i = 0
146141

142+
# Error flags
143+
found_with_limits = False
144+
linalg_error = 0
145+
147146
# Initialise variables
148147
E = 0.0
149148
q = q0[0]
150149

151150
for search in range(self.slimit):
152151
q = q0[search].copy()
152+
i = 0
153153

154-
while i <= self.ilimit:
154+
while i < self.ilimit:
155155
i += 1
156156

157157
# Attempt a step
@@ -160,6 +160,7 @@ def solve(
160160

161161
except np.linalg.LinAlgError:
162162
# Abandon search and try again
163+
linalg_error += 1
163164
break
164165

165166
# Check if we have arrived
@@ -175,6 +176,7 @@ def solve(
175176

176177
if not jl_valid and self.joint_limits:
177178
# Abandon search and try again
179+
found_with_limits = True
178180
break
179181
else:
180182
return IKSolution(
@@ -185,17 +187,16 @@ def solve(
185187
residual=E,
186188
reason="Success",
187189
)
188-
189190
total_i += i
190-
i = 0
191191

192192
# If we make it here, then we have failed
193-
reason = "ilimit and slimit reached"
193+
reason = "iteration and search limit reached"
194194

195-
if E < self.tol:
195+
if linalg_error:
196+
reason += f", {linalg_error} np.LinAlgError encountered"
197+
198+
if found_with_limits:
196199
reason += ", solution found but violates joint limits"
197-
else:
198-
reason += ", no solution found"
199200

200201
return IKSolution(
201202
q=q,
@@ -358,6 +359,12 @@ def calc_qnull(
358359
return qnull.flatten()
359360

360361

362+
# λΣ: The gain for joint limit avoidance. Setting to 0.0 will remove this completely from the solution
363+
# λm: The gain for maximisation. Setting to 0.0 will remove this completely from the solution
364+
# ps: The minimum angle/distance (in radians or metres) in which the joint is allowed to approach to its limit
365+
# pi: The influence angle/distance (in radians or metres) in null space motion becomes active
366+
367+
361368
class IK_NR(IKSolver):
362369
def __init__(
363370
self,

0 commit comments

Comments
 (0)