Skip to content

Commit 32ab8a2

Browse files
author
Michael Koval
committed
Simplified PostProcessPath with defer=True.
1 parent a601b49 commit 32ab8a2

File tree

1 file changed

+38
-37
lines changed

1 file changed

+38
-37
lines changed

src/prpy/base/robot.py

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,10 @@ def GetTrajectoryManipulators(self, traj):
181181

182182
return active_manipulators
183183

184-
def PostProcessPath(self, path, defer=False, executor=None, **kwargs):
184+
def PostProcessPath(self, path, defer=False, executor=None,
185+
constrained=None, smooth=None, default_timelimit=0.5,
186+
shortcut_options=None, smoothing_options=None,
187+
retiming_options=None):
185188
""" Post-process a geometric path to prepare it for execution.
186189
187190
This method post-processes a geometric path by (optionally) optimizing
@@ -218,38 +221,35 @@ def PostProcessPath(self, path, defer=False, executor=None, **kwargs):
218221
@param retiming_options kwargs to RetimeTrajectory for timing
219222
@return trajectory ready for execution
220223
"""
221-
222-
def do_postprocess(path, constrained=None, smooth=None,
223-
default_timelimit=0.5, shortcut_options=None,
224-
smoothing_options=None, retiming_options=None):
225-
from ..planning.base import Tags
226-
from ..util import GetTrajectoryTags, CopyTrajectory
227-
228-
# Default parameters.
229-
if shortcut_options is None:
230-
shortcut_options = dict()
231-
if smoothing_options is None:
232-
smoothing_options = dict()
233-
if retiming_options is None:
234-
retiming_options = dict()
235-
236-
shortcut_options.setdefault('timelimit', default_timelimit)
237-
smoothing_options.setdefault('timelimit', default_timelimit)
238-
retiming_options.setdefault('timelimit', default_timelimit)
239-
240-
# Read default parameters from the trajectory's tags.
241-
tags = GetTrajectoryTags(path)
242-
243-
if constrained is None:
244-
constrained = tags.get(Tags.CONSTRAINED, False)
245-
logger.debug('Detected "%s" tag on trajectory: Setting'
246-
' constrained = True.', Tags.CONSTRAINED)
247-
248-
if smooth is None:
249-
smooth = tags.get(Tags.SMOOTH, False)
250-
logger.debug('Detected "%s" tag on trajectory: Setting smooth'
251-
' = True', Tags.SMOOTH)
252-
224+
from ..planning.base import Tags
225+
from ..util import GetTrajectoryTags, CopyTrajectory
226+
227+
# Default parameters.
228+
if shortcut_options is None:
229+
shortcut_options = dict()
230+
if smoothing_options is None:
231+
smoothing_options = dict()
232+
if retiming_options is None:
233+
retiming_options = dict()
234+
235+
shortcut_options.setdefault('timelimit', default_timelimit)
236+
smoothing_options.setdefault('timelimit', default_timelimit)
237+
retiming_options.setdefault('timelimit', default_timelimit)
238+
239+
# Read default parameters from the trajectory's tags.
240+
tags = GetTrajectoryTags(path)
241+
242+
if constrained is None:
243+
constrained = tags.get(Tags.CONSTRAINED, False)
244+
logger.debug('Detected "%s" tag on trajectory: Setting'
245+
' constrained = True.', Tags.CONSTRAINED)
246+
247+
if smooth is None:
248+
smooth = tags.get(Tags.SMOOTH, False)
249+
logger.debug('Detected "%s" tag on trajectory: Setting smooth'
250+
' = True', Tags.SMOOTH)
251+
252+
def do_postprocess():
253253
with Clone(self.GetEnv()) as cloned_env:
254254
cloned_robot = cloned_env.Cloned(self)
255255

@@ -288,12 +288,13 @@ def do_postprocess(path, constrained=None, smooth=None,
288288
# The trajectory is not constrained, so we can shortcut it
289289
# before execution.
290290
logger.debug('Shortcutting an unconstrained path.')
291-
path = self.simplifier.ShortcutPath(
291+
shortcut_path = self.simplifier.ShortcutPath(
292292
cloned_robot, path, defer=False, **shortcut_options)
293293

294294
logger.debug('Smoothing an unconstrained path.')
295295
traj = self.smoother.RetimeTrajectory(
296-
cloned_robot, path, defer=False, **smoothing_options)
296+
cloned_robot, shortcut_path, defer=False,
297+
**smoothing_options)
297298

298299
return CopyTrajectory(traj, env=self.GetEnv())
299300

@@ -304,9 +305,9 @@ def do_postprocess(path, constrained=None, smooth=None,
304305
if executor is None:
305306
executor = get_default_executor()
306307

307-
return wrap_future(executor.submit(do_postprocess, path, **kwargs))
308+
return wrap_future(executor.submit(do_postprocess))
308309
else:
309-
return do_postprocess(path, **kwargs)
310+
return do_postprocess()
310311

311312
def ExecutePath(self, path, simplify=True, smooth=True, defer=False,
312313
timeout=1., **kwargs):

0 commit comments

Comments
 (0)