@@ -173,12 +173,13 @@ def do_execute(path, simplify, smooth, timeout, **kwargs):
173
173
from trollius .executor import get_default_executor
174
174
from trollius .futures import wrap_future
175
175
176
- executor = kwargs .get ('executor' , get_default_executor () )
177
- return \
176
+ executor = kwargs .get ('executor' ) or get_default_executor ()
177
+ return wrap_future (
178
178
executor .submit (do_execute ,
179
179
path , simplify = simplify , smooth = smooth , timeout = timeout ,
180
180
** kwargs
181
181
)
182
+ )
182
183
else :
183
184
return do_execute (path , simplify = simplify , smooth = smooth ,
184
185
timeout = timeout , ** kwargs )
@@ -262,28 +263,19 @@ def ViolatesVelocityLimits(self, traj):
262
263
return False
263
264
264
265
def _PlanWrapper (self , planning_method , args , kw_args ):
266
+ config_spec = self .GetActiveConfigurationSpecification ('linear' )
265
267
266
268
# Call the planner.
267
- config_spec = self .GetActiveConfigurationSpecification ('linear' )
268
269
result = planning_method (self , * args , ** kw_args )
269
270
270
- # Define the post processing steps for the trajectory.
271
- def postprocess_trajectory (traj , kw_args ):
272
-
271
+ def postprocess_trajectory (traj ):
273
272
# Strip inactive DOFs from the trajectory.
274
273
openravepy .planningutils .ConvertTrajectorySpecification (
275
274
traj , config_spec
276
275
)
277
276
278
- # Optionally execute the trajectory.
279
- if 'execute' not in kw_args or kw_args ['execute' ]:
280
- kw_args ['defer' ] = False
281
- return self .ExecutePath (traj , ** kw_args )
282
- else :
283
- return traj
284
-
285
277
# Return either the trajectory result or a future to the result.
286
- if 'defer' in kw_args and kw_args [ 'defer' ] is True :
278
+ if kw_args . get ( 'defer' , False ) :
287
279
import trollius
288
280
289
281
# Perform postprocessing on a future trajectory.
@@ -292,16 +284,24 @@ def defer_trajectory(traj_future, kw_args):
292
284
# Wait for the planner to complete.
293
285
traj = yield trollius .From (traj_future )
294
286
295
- # Submit a new task to postprocess the trajectory.
296
- from trollius .executor import get_default_executor
297
- executor = kw_args .get ('executor' ) or get_default_executor ()
298
- f = executor .submit (postprocess_trajectory , traj , kw_args )
287
+ postprocess_trajectory (traj )
288
+
289
+ # Optionally execute the trajectory.
290
+ if kw_args .get ('execute' , True ):
291
+ # We know defer = True if we're in this function, so we
292
+ # don't have to set it explicitly.
293
+ traj = yield trollius .From (
294
+ self .ExecutePath (traj , ** kw_args )
295
+ )
299
296
300
- # Wait for the postprocessed trajectory to be completed.
301
- from trollius .futures import wrap_future
302
- processed_traj = yield trollius .From (wrap_future (f ))
303
- raise trollius .Return (processed_traj )
297
+ raise trollius .Return (traj )
304
298
305
299
return trollius .Task (defer_trajectory (result , kw_args ))
306
300
else :
307
- return postprocess_trajectory (result , kw_args )
301
+ postprocess_trajectory (result )
302
+
303
+ # Optionally execute the trajectory.
304
+ if kw_args .get ('execute' , True ):
305
+ result = self .ExecutePath (result , ** kw_args )
306
+
307
+ return result
0 commit comments