robotics – Robotics module

Robotics module for the Pybricks API.

class robotics.DriveBase(left_motor, right_motor, wheel_diameter, axle_track)

Class representing a robotic vehicle with two powered wheels and optional wheel caster(s).

Parameters
  • left_motor (Motor) – The motor that drives the left wheel.

  • right_motor (Motor) – The motor that drives the right wheel.

  • wheel_diameter (dimension: mm) – Diameter of the wheels.

  • axle_track (dimension: mm) – Distance between the midpoints of the two wheels.

Example:

# Initialize two motors and a drive base
left = Motor(Port.B)
right = Motor(Port.C)
robot = DriveBase(left, right, 56, 114)
drive(speed, steering)

Start driving at the specified speed and turnrate, both measured at the center point between the wheels of the robot.

Parameters

Example:

# Initialize two motors and a drive base
left = Motor(Port.B)
right = Motor(Port.C)
robot = DriveBase(left, right, 56, 114)

# Initialize a sensor
sensor = UltrasonicSensor(Port.S4)

# Drive forward until an object is detected
robot.drive(100, 0)
while sensor.distance() > 500:
    wait(10)
robot.stop()
drive_time(speed, steering, time)

Drive at the specified speed and turnrate for a given amount of time, and then stop.

Parameters

Example:

# Drive forward at 100 mm/s for two seconds
robot.drive(100, 0, 2000)

# Turn at 45 deg/s for three seconds
robot.drive(0, 45, 3000)
stop(stop_type=<Stop.COAST: 0>)

Stop the robot.

Parameters

stop_type (Stop) – Whether to coast, brake, or hold (Default: COAST).