Skip to content

Commit 1cd5f37

Browse files
committed
Cleaned up ExecutePath.
1 parent c77b17d commit 1cd5f37

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

src/prpy/base/robot.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,13 @@ def do_execute(path, simplify, smooth, timeout, **kwargs):
173173
from trollius.executor import get_default_executor
174174
from trollius.futures import wrap_future
175175

176-
executor = kwargs.get('executor', get_default_executor())
177-
return \
176+
executor = kwargs.get('executor') or get_default_executor()
177+
return wrap_future(
178178
executor.submit(do_execute,
179179
path, simplify=simplify, smooth=smooth, timeout=timeout,
180180
**kwargs
181181
)
182+
)
182183
else:
183184
return do_execute(path, simplify=simplify, smooth=smooth,
184185
timeout=timeout, **kwargs)
@@ -262,28 +263,19 @@ def ViolatesVelocityLimits(self, traj):
262263
return False
263264

264265
def _PlanWrapper(self, planning_method, args, kw_args):
266+
config_spec = self.GetActiveConfigurationSpecification('linear')
265267

266268
# Call the planner.
267-
config_spec = self.GetActiveConfigurationSpecification('linear')
268269
result = planning_method(self, *args, **kw_args)
269270

270-
# Define the post processing steps for the trajectory.
271-
def postprocess_trajectory(traj, kw_args):
272-
271+
def postprocess_trajectory(traj):
273272
# Strip inactive DOFs from the trajectory.
274273
openravepy.planningutils.ConvertTrajectorySpecification(
275274
traj, config_spec
276275
)
277276

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-
285277
# 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):
287279
import trollius
288280

289281
# Perform postprocessing on a future trajectory.
@@ -292,16 +284,24 @@ def defer_trajectory(traj_future, kw_args):
292284
# Wait for the planner to complete.
293285
traj = yield trollius.From(traj_future)
294286

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+
)
299296

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)
304298

305299
return trollius.Task(defer_trajectory(result, kw_args))
306300
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

Comments
 (0)