Skip to content

Commit f2a651d

Browse files
author
Siddhartha Srinivasa
committed
Added exception handling for min distance
1 parent 9489e4e commit f2a651d

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

src/prpy/planning/vectorfield.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ def PlanToEndEffectorOffset(self, robot, direction, distance,
118118

119119
manip = robot.GetActiveManipulator()
120120
Tstart = manip.GetEndEffectorTransform()
121+
# This is a list simply because of Python scoping madness
122+
distance_moved = [0.0]
121123

122124
def vf_straightline():
123125
twist = prpy.util.GeodesicTwist(manip.GetEndEffectorTransform(),
@@ -136,18 +138,32 @@ def TerminateMove():
136138
error = prpy.util.GeodesicError(Tstart, Tnow)
137139
if numpy.fabs(error[3]) > angular_tolerance:
138140
raise PlanningError('Deviated from orientation constraint.')
139-
distance_moved = numpy.dot(error[0:3], direction)
141+
distance_moved[0] = numpy.dot(error[0:3], direction)
140142
position_deviation = numpy.linalg.norm(error[0:3] -
141-
distance_moved*direction)
143+
distance_moved[0]*direction)
142144
if position_deviation > position_tolerance:
143145
raise PlanningError('Deviated from straight line constraint.')
144146

145-
if distance_moved > max_distance:
147+
print distance_moved[0], max_distance, position_deviation
148+
149+
if distance_moved[0] > max_distance:
146150
return True
147151
return False
148152

149-
return self.FollowVectorField(robot, vf_straightline,
150-
TerminateMove, timelimit)
153+
try:
154+
traj = self.FollowVectorField(robot, vf_straightline,
155+
TerminateMove, timelimit)
156+
except PlanningError as e:
157+
# Throw an error if we haven't reached the minimum distance.
158+
print distance_moved[0]
159+
if distance_moved[0] < distance:
160+
raise
161+
# Otherwise we'll gracefully terminate.
162+
else:
163+
logger.warning('Terminated early at distance %f < %f: %s',
164+
distance_moved[0], max_distance, e.message)
165+
166+
return traj
151167

152168
@PlanningMethod
153169
def FollowVectorField(self, robot, fn_vectorfield, fn_terminate,

0 commit comments

Comments
 (0)