Skip to content

Commit a211219

Browse files
committed
Merge pull request #247 from personalrobotics/bugfix/GreedyIK
PlanWorkspacePath detects collision error only on failure.
2 parents 23057b3 + 52d3388 commit a211219

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

src/prpy/planning/workspace.py

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,11 @@ def PlanWorkspacePath(self, robot, traj, timelimit=5.0,
184184

185185

186186
try:
187-
collision_error = None
188187
while t < traj.GetDuration() + epsilon:
189188
# Check for a timeout.
190189
current_time = time.time()
191190
if (timelimit is not None and
192191
current_time - start_time > timelimit):
193-
if collision_error is not None:
194-
raise collision_error
195192
raise TimeoutPlanningError(timelimit)
196193

197194
# Hypothesize new configuration as closest IK to current
@@ -203,34 +200,12 @@ def PlanWorkspacePath(self, robot, traj, timelimit=5.0,
203200
releasegil=True
204201
)
205202

206-
# FindIKSolutions is slower than FindIKSolution,
207-
# so call this only to identify error when there is no solution
208-
if qnew is None:
209-
ik_solutions = manip.FindIKSolutions(
210-
openravepy.matrixFromPose(traj.Sample(t+dt)[0:7]),
211-
openravepy.IkFilterOptions.IgnoreSelfCollisions,
212-
ikreturn=False,
213-
releasegil=True
214-
)
215-
216-
# update collision_error to contain collision info.
217-
with robot.CreateRobotStateSaver(p.LinkTransformation):
218-
for q in ik_solutions:
219-
robot.SetActiveDOFValues(q)
220-
report = CollisionReport()
221-
if self.env.CheckCollision(robot, report=report):
222-
collision_error = CollisionPlanningError.FromReport(report)
223-
elif robot.CheckSelfCollision(report=report):
224-
collision_error = SelfCollisionPlanningError.FromReport(report)
225-
226203
# Check if the step was within joint DOF resolution.
227204
infeasible_step = True
228205
if qnew is not None:
229206
# Found an IK
230207
step = abs(qnew - qcurr)
231208
if (max(step) < min_step) and qtraj:
232-
if collision_error is not None:
233-
raise collision_error
234209
raise PlanningError('Not making progress.')
235210
infeasible_step = any(step > robot.GetActiveDOFResolutions())
236211
if infeasible_step:
@@ -254,7 +229,31 @@ def PlanWorkspacePath(self, robot, traj, timelimit=5.0,
254229

255230
# Throw an error if we haven't reached the minimum waypoint.
256231
if t < min_time:
257-
raise
232+
# FindIKSolutions is slower than FindIKSolution,
233+
# so call this only to identify error when there is no solution
234+
ik_solutions = manip.FindIKSolutions(
235+
openravepy.matrixFromPose(traj.Sample(t+dt*2.0)[0:7]),
236+
openravepy.IkFilterOptions.IgnoreSelfCollisions,
237+
ikreturn=False, releasegil=True
238+
)
239+
240+
collision_error = None
241+
# update collision_error to contain collision info.
242+
with robot.CreateRobotStateSaver(p.LinkTransformation):
243+
for q in ik_solutions:
244+
robot.SetActiveDOFValues(q)
245+
report = CollisionReport()
246+
if self.env.CheckCollision(robot, report=report):
247+
collision_error = CollisionPlanningError.FromReport(report)
248+
elif robot.CheckSelfCollision(report=report):
249+
collision_error = SelfCollisionPlanningError.FromReport(report)
250+
else:
251+
collision_error = None
252+
if collision_error is not None:
253+
raise collision_error
254+
else:
255+
raise
256+
258257
# Otherwise we'll gracefully terminate.
259258
else:
260259
logger.warning('Terminated early at time %f < %f: %s',

0 commit comments

Comments
 (0)