Parameters

Enumerated options — the Pybricks pybricks.parameters pattern. Every API argument that selects one of a fixed set of behaviours takes one of these members, never a string:

from openbricks.parameters import Stop, DriveMode, LineMode

db.straight(300, then=Stop.BRAKE)
db = DriveBase(left, right, 88, 136, drive=DriveMode.WHEEL)
qtr.set_mode(LineMode.CENTER)

A string is rejected at the call with a TypeError that names the members, so a typo or a drifted spelling can never silently select a different behaviour.

Enumerated parameters — the Pybricks pybricks.parameters pattern.

Every API argument that selects one of a fixed set of behaviours takes a member of one of these classes, never a string. A string compares equal to nothing here, so a typo (then="cost") or a drifted spelling ("continue" vs "none") fails at the call with a message naming the members, instead of silently selecting a default somewhere downstream. Members print as Stop.COAST like Pybricks’ _PybricksEnum, and Stop carries the Pybricks numbering (COAST=0, BRAKE=1, HOLD=2, NONE=3), which the native drivebase stop codes share.

Members compare by (enum name, member name) rather than by object identity: the simulator drops the firmware modules from sys.modules between runs and re-imports them, so a Stop.COAST bound before the reload must still equal the one created after it. A string compares equal to no member either way.

MicroPython ships no enum module, so this is the smallest class that gives the same surface: .name, .value, repr, and a class-level member list.

Example:

from openbricks.parameters import Stop, LineMode
db.straight(300, then=Stop.BRAKE)
qtr.set_mode(LineMode.CENTER)
class openbricks.parameters.Stop(name, value)[source]

Bases: _Enum

What a motor or drivebase does when a move ends — Pybricks Stop.

  • COAST — cut torque; the wheel free-wheels.

  • BRAKE — actively hold zero speed (passively resist on open-loop motors).

  • HOLD — keep controlling the motor to hold the reached position.

  • NONE — do not decelerate; the move hands its end speed to the next command (concatenate maneuvers without stopping).

BRAKE = Stop.BRAKE
COAST = Stop.COAST
HOLD = Stop.HOLD
NONE = Stop.NONE
class openbricks.parameters.DriveMode(name, value)[source]

Bases: _Enum

How a serial-bus wheel servo is driven by the drivebase engine.

  • DUTY — the servo runs open-loop and the engine’s FF+PI loop is the speed controller (the default since 1.89.0).

  • WHEEL — the servo’s own wheel-mode velocity loop closes the speed; the engine commands speed setpoints.

DUTY = DriveMode.DUTY
WHEEL = DriveMode.WHEEL
class openbricks.parameters.LineMode(name, value)[source]

Bases: _Enum

Which feature of the line a QTR array follows.

  • LEFT — the line’s left edge, under the left setpoint element.

  • RIGHT — the line’s right edge, under the right setpoint element.

  • CENTER — the line’s centre, the weighted centroid over every element.

CENTER = LineMode.CENTER
LEFT = LineMode.LEFT
RIGHT = LineMode.RIGHT
openbricks.parameters.check(enum_cls, value, param, allowed=None)[source]

Raise TypeError unless value is a member of enum_cls (and of allowed, when the call accepts only a subset). The message names the accepted members; a string argument is called out explicitly, since that is the mistake this module exists to catch.