Skip to content

Commit ecceaf4

Browse files
committed
Added defer=True support to ExecutePath.
1 parent ada068a commit ecceaf4

File tree

1 file changed

+14
-35
lines changed

1 file changed

+14
-35
lines changed

src/prpy/base/robot.py

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -160,49 +160,28 @@ def GetTrajectoryManipulators(self, traj):
160160

161161
def ExecutePath(self, path, simplify=True, smooth=True, defer=False,
162162
timeout=1., **kwargs):
163-
retimer = self.smoother if smooth else self.retimer
163+
def do_execute(path, simplify, smooth, timeout, **kwargs):
164+
if simplify:
165+
path = self.simplifier.ShortcutPath(self, path, defer=False,
166+
timeout=timeout, **kwargs)
164167

165-
# TODO: Verify that the path is untimed.
168+
retimer = self.smoother if smooth else self.retimer
169+
timed_traj = retimer.RetimeTrajectory(self, path, defer=False, **kwargs)
170+
return self.ExecuteTrajectory(timed_traj, defer=False, **kwargs)
166171

167172
if defer:
168-
from trollius import async, coroutine, From, Return, Task
169173
from trollius.executor import get_default_executor
170174
from trollius.futures import wrap_future
171175

172-
@coroutine
173-
def do_execute(path, simplify, smooth, timeout, **kwargs):
174-
if simplify:
175-
print 'SIMPLYFING TRAJECTORY'
176-
path = yield From(
177-
self.simplifier.ShortcutPath(self, path, defer=True,
178-
timeout=timeout, **kwargs)
179-
)
180-
181-
print 'TIMING TRAJECTORY'
182-
timed_traj = yield From(
183-
retimer.RetimeTrajectory(self, path, defer=True, **kwargs)
184-
)
185-
print 'EXECUTING TRAJECTORY'
186-
executed_traj = yield From(
187-
self.ExecuteTrajectory(timed_traj, defer=True, **kwargs)
188-
)
189-
raise Return(executed_traj)
190-
191-
print 'RETURNING TASK'
192-
193176
executor = kwargs.get('executor', get_default_executor())
194-
return do_execute(
195-
path, simplify=simplify, smooth=smooth, timeout=timeout,
196-
**kwargs
197-
)
177+
return \
178+
executor.submit(do_execute,
179+
path, simplify=simplify, smooth=smooth, timeout=timeout,
180+
**kwargs
181+
)
198182
else:
199-
if simplify:
200-
path = self.simplifier.ShortcutPath(
201-
self, path, timeout=timeout, **kwargs)
202-
203-
traj = retimer.RetimeTrajectory(self, path, **kwargs)
204-
205-
return self.ExecuteTrajectory(traj, **kwargs)
183+
return do_execute(path, simplify=simplify, smooth=smooth,
184+
timeout=timeout, **kwargs)
206185

207186
def ExecuteTrajectory(self, traj, defer=False, timeout=None, **kw_args):
208187
# TODO: Verify that the trajectory is timed.

0 commit comments

Comments
 (0)