@@ -184,10 +184,9 @@ def do_execute(path, simplify, smooth, timeout, **kwargs):
184
184
return do_execute (path , simplify = simplify , smooth = smooth ,
185
185
timeout = timeout , ** kwargs )
186
186
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 ):
188
188
# TODO: Verify that the trajectory is timed.
189
189
# TODO: Check if this trajectory contains the base.
190
- # TODO: Implement defer=True
191
190
192
191
needs_base = False
193
192
@@ -204,7 +203,28 @@ def ExecuteTrajectory(self, traj, defer=False, timeout=None, **kw_args):
204
203
if hasattr (self , 'base' ) and hasattr (self .base , 'controller' ):
205
204
active_controllers .append (self .base .controller )
206
205
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
+
208
228
return traj
209
229
210
230
def ViolatesVelocityLimits (self , traj ):
0 commit comments