Skip to content

Commit c77b17d

Browse files
committed
Merge branch 'feature/SmoothingRefactor' of https://github.com/personalrobotics/prpy into feature/SmoothingRefactor
2 parents 58a8cef + 4dbe4a9 commit c77b17d

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,38 @@ resolve multiple objects in one statement:
303303
```
304304

305305

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+
306338
## Method Binding
307339

308340
Finally, PrPy offers helper functions for binding custom methods on (i.e.

0 commit comments

Comments
 (0)