Skip to content

Commit

Permalink
signaltypes: Bare minimal async docs.
Browse files Browse the repository at this point in the history
This is nowhere near complete, but provides handles to start documenting async for the relevant methods.
  • Loading branch information
laurensvalk committed Oct 23, 2023
1 parent 1a49d39 commit 578abab
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 27 deletions.
22 changes: 0 additions & 22 deletions .readthedocs.yaml

This file was deleted.

1 change: 0 additions & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ build:
# Build documentation in the doc/main/ directory with Sphinx
sphinx:
configuration: doc/main/conf.py
fail_on_warning: true

# Optionally build your docs in additional formats such as PDF
formats:
Expand Down
22 changes: 22 additions & 0 deletions doc/main/signaltypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,25 @@ though the *hub* accelerates backward.
and other creations, by noting which way the top and
front :class:`Side <Side>` of the hub are pointing. The example
on the left is the default configuration.

.. class:: await

Multitasking
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Pybricks supports cooperative multitasking using the ``async`` and ``await``
keywords. This allows operations that normally take some time to complete, to
run in parallel with other operations.

Whenever you see the word ``await`` in the documentation, this means that the
method or function supports multitasking.

The following example shows how to use multitasking to make a robot drive
forward, then turn and move a gripper at the same time, and then drive
backward.

.. literalinclude::
../../examples/pup/robotics/drivebase_async.py

If you don't use multitasking, you can ignore the ``await`` keyword and write
programs as usual.
27 changes: 27 additions & 0 deletions examples/pup/robotics/drivebase_async.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from pybricks.pupdevices import Motor
from pybricks.parameters import Direction, Port
from pybricks.robotics import DriveBase
from pybricks.tools import multitask, run_task

# Set up all devices.
left = Motor(Port.A, Direction.COUNTERCLOCKWISE)
right = Motor(Port.B)
gripper = Motor(Port.C)
drive_base = DriveBase(left, right, 56, 114)


# Move the gripper up and down.
async def move_gripper():
await gripper.run_angle(500, -90)
await gripper.run_angle(500, 90)


# Drive forward, turn move gripper at the same time, and drive backward.
async def main():
await drive_base.straight(250)
await multitask(drive_base.turn(90), move_gripper())
await drive_base.straight(-250)


# Runs the main program from start to finish.
run_task(main())
6 changes: 3 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ doc8 = "^0.8.1"
flake8 = "^4.0"

[tool.poetry.group.doc.dependencies]
Sphinx = { git = "https://github.com/pybricks/sphinx.git", rev = "b00124cb" }
Sphinx = { git = "https://github.com/pybricks/sphinx.git", rev = "cd277d09" }
sphinx-rtd-theme = "^1.0.0"
toml = "^0.10.0"

Expand Down

0 comments on commit 578abab

Please sign in to comment.