Skip to content

Commit

Permalink
pybricks.robotics.DriveBase: Add basic example.
Browse files Browse the repository at this point in the history
  • Loading branch information
Barry-Williams authored and laurensvalk committed Oct 28, 2022
1 parent be35581 commit 492d6cd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
9 changes: 9 additions & 0 deletions doc/main/robotics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,12 @@

.. autoattribute:: pybricks.robotics.DriveBase.heading_control
:annotation:

Examples
-------------------

Driving straight and turning in place
**********************************************

.. literalinclude::
../../examples/pup/robotics/drivebase_basics.py
24 changes: 24 additions & 0 deletions examples/pup/robotics/drivebase_basics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from pybricks.pupdevices import Motor
from pybricks.parameters import Port, Direction
from pybricks.robotics import DriveBase

# Initialize both motors. In this example, the motor on the
# left must turn counterclockwise to make the robot go forward.
left_motor = Motor(Port.A, Direction.COUNTERCLOCKWISE)
right_motor = Motor(Port.B)

# Initialize the drive base. In this example, the wheel diameter is 56mm.
# The distance between the two wheel-ground contact points is 112mm.
drive_base = DriveBase(left_motor, right_motor, wheel_diameter=56, axle_track=112)

# Drive forward by 500mm (half a meter).
drive_base.straight(500)

# Turn around clockwise (180 degrees)
drive_base.turn(180)

# Drive forward again to drive back.
drive_base.straight(500)

# Turn around counterclockwise.
drive_base.turn(-180)

0 comments on commit 492d6cd

Please sign in to comment.