Skip to content

Commit 68df42c

Browse files
committed
Implemented defer=True on ExecuteTrajectory.
1 parent 1cd5f37 commit 68df42c

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/prpy/base/robot.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,9 @@ def do_execute(path, simplify, smooth, timeout, **kwargs):
184184
return do_execute(path, simplify=simplify, smooth=smooth,
185185
timeout=timeout, **kwargs)
186186

187-
def ExecuteTrajectory(self, traj, defer=False, timeout=None, **kw_args):
187+
def ExecuteTrajectory(self, traj, defer=False, timeout=None, period=0.01, **kw_args):
188188
# TODO: Verify that the trajectory is timed.
189189
# TODO: Check if this trajectory contains the base.
190-
# TODO: Implement defer=True
191190

192191
needs_base = False
193192

@@ -204,7 +203,28 @@ def ExecuteTrajectory(self, traj, defer=False, timeout=None, **kw_args):
204203
if hasattr(self, 'base') and hasattr(self.base, 'controller'):
205204
active_controllers.append(self.base.controller)
206205

207-
util.WaitForControllers(active_controllers, timeout=timeout)
206+
if defer:
207+
import time
208+
import trollius
209+
210+
@trollius.coroutine
211+
def do_poll():
212+
time_stop = time.time() + (timeout if timeout else numpy.inf)
213+
214+
while time.time() <= time_stop:
215+
is_done = all(controller.IsDone()
216+
for controller in active_controllers)
217+
if is_done:
218+
raise trollius.Return(traj)
219+
220+
yield trollius.From(trollius.sleep(period))
221+
222+
raise trollius.Return(None)
223+
224+
return trollius.async(do_poll())
225+
else:
226+
util.WaitForControllers(active_controllers, timeout=timeout)
227+
208228
return traj
209229

210230
def ViolatesVelocityLimits(self, traj):

0 commit comments

Comments
 (0)