@@ -118,6 +118,8 @@ def PlanToEndEffectorOffset(self, robot, direction, distance,
118
118
119
119
manip = robot .GetActiveManipulator ()
120
120
Tstart = manip .GetEndEffectorTransform ()
121
+ # This is a list simply because of Python scoping madness
122
+ distance_moved = [0.0 ]
121
123
122
124
def vf_straightline ():
123
125
twist = prpy .util .GeodesicTwist (manip .GetEndEffectorTransform (),
@@ -136,18 +138,32 @@ def TerminateMove():
136
138
error = prpy .util .GeodesicError (Tstart , Tnow )
137
139
if numpy .fabs (error [3 ]) > angular_tolerance :
138
140
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 )
140
142
position_deviation = numpy .linalg .norm (error [0 :3 ] -
141
- distance_moved * direction )
143
+ distance_moved [ 0 ] * direction )
142
144
if position_deviation > position_tolerance :
143
145
raise PlanningError ('Deviated from straight line constraint.' )
144
146
145
- if distance_moved > max_distance :
147
+ print distance_moved [0 ], max_distance , position_deviation
148
+
149
+ if distance_moved [0 ] > max_distance :
146
150
return True
147
151
return False
148
152
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
151
167
152
168
@PlanningMethod
153
169
def FollowVectorField (self , robot , fn_vectorfield , fn_terminate ,
0 commit comments