File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -303,6 +303,38 @@ resolve multiple objects in one statement:
303
303
```
304
304
305
305
306
+ ## Concurrent Execution
307
+
308
+ PrPy has native support for [ futures] ( http://en.wikipedia.org/wiki/Futures_and_promises ) and
309
+ [ coroutines] ( http://en.wikipedia.org/wiki/Coroutine ) to simplify concurrent programming. A
310
+ _ future_ encapsulates the execution of a long-running task. We use the concurrency primitives
311
+ provided by the [ ` trollius ` module] ( http://trollius.readthedocs.org/en/latest/using.html ) ,
312
+ which is a Python 2 backport of the [ ` asyncio ` module] ( https://docs.python.org/3/library/asyncio.html )
313
+ from Python 3.
314
+
315
+ We can use these primitives to parallelize planning and execution:
316
+
317
+ ``` python
318
+ @coroutine
319
+ def do_plan (robot ):
320
+ # Plan to goal1 and start executing the trajectory.
321
+ path1 = yield From(robot.PlanToEndEffectorPose(goal1, execute = False ))
322
+ exec1_future = robot.ExecutePath(path1)
323
+
324
+ # Plan from goal1 to goal2.
325
+ robot.SetDOFValues(GetLastWaypoint(path1))
326
+ path2 = yield From(robot.PlanToEndEffectorPope(goal2, execute = False ))
327
+
328
+ # Wait for path1 to finish executing, then execute path2.
329
+ exec1 = yield From(exec1_future)
330
+ exec2 = yield From(robot.ExecutePath(path2))
331
+
332
+ raise Return(path1, path2)
333
+
334
+ loop = trollius.get_event_loop()
335
+ path = loop.run_until_complete(do_plan(robot))
336
+ ```
337
+
306
338
## Method Binding
307
339
308
340
Finally, PrPy offers helper functions for binding custom methods on (i.e.
You can’t perform that action at this time.
0 commit comments