Skip to content

hardware

Bms

Bms(**kwargs)

Bases: Module, ABC

The BMS module communicates with a simple battery management system over a serial connection.

The BMS module provides measured voltages as an event.

is_above_percent

is_above_percent(value: float) -> bool

Returns whether the battery is charged above the given percentage.

is_above_voltage

is_above_voltage(value: float) -> bool

Returns whether the battery voltage is above the given value.

is_below_percent

is_below_percent(value: float) -> bool

Returns whether the battery is charged below the given percentage.

is_below_voltage

is_below_voltage(value: float) -> bool

Returns whether the battery voltage is below the given value.

BmsHardware

BmsHardware(
    robot_brain: RobotBrain,
    *,
    expander: Optional[ExpanderHardware] = None,
    name: str = "bms",
    rx_pin: int = 26,
    tx_pin: int = 27,
    baud: int = 9600,
    num: int = 1,
    charge_detect_threshold: float = -0.4
)

Bases: Bms, ModuleHardware

This module implements the hardware interface for the BMS module.

BmsSimulation

BmsSimulation(
    is_charging: Optional[Callable[[], bool]] = None,
    fixed_voltage: Optional[float] = None,
)

Bases: Bms, ModuleSimulation

This module simulates a BMS module.

Bumper

Bumper(estop: Optional[EStop], **kwargs)

Bases: Module, ABC

A module that detects when a bumper is triggered.

Events

Name Description
BUMPER_TRIGGERED a bumper was triggered (argument: the bumper name)

BumperHardware

BumperHardware(
    robot_brain: RobotBrain,
    *,
    expander: Optional[ExpanderHardware] = None,
    name: str = "bumper",
    pins: dict[str, int],
    estop: Optional[EStop] = None
)

Bases: Bumper, ModuleHardware

Hardware implementation of the bumper module.

The module expects a dictionary of pin names and pin numbers. If an e-stop is provided, the module will not trigger bumpers if the e-stop is active.

Events

Name Description
BUMPER_TRIGGERED a bumper was triggered (argument: the bumper name)

BumperSimulation

BumperSimulation(estop: Optional[EStop], **kwargs)

Bases: Bumper, ModuleSimulation

Simulation of the bumper module.

Events

Name Description
BUMPER_TRIGGERED a bumper was triggered (argument: the bumper name)

Communication

Communication()

Bases: ABC

This abstract module defines an interface for communicating with a microcontroller.

Besides sending and receiving messages a communication module provides a property whether communication is possible. It can also provide a piece of debug UI.

SerialCommunication

SerialCommunication(baud_rate: int = 115200)

Bases: Communication

This module implements a communication via a serial device with a given baud rate.

It contains a list of search paths for finding the serial device.

WebCommunication

WebCommunication()

Bases: Communication

Remote connection to the Robot Brain's ESP.

This makes it possible to keep developing on your fast computer while communicating with the hardware components connected to a physical Robot Brain.

EStop

EStop(**kwargs)

Bases: Module, ABC

A module that detects when the e-stop is triggered.

The module has a boolean field active that is true when the e-stop is triggered.

There is also a boolean field is_soft_estop_active that is true when the soft e-stop is active. It can be set to true or false by calling set_soft_estop(active: bool).

Events

Name Description
ESTOP_TRIGGERED the e-stop was triggered

EStopHardware

EStopHardware(
    robot_brain: RobotBrain,
    *,
    name: str = "estop",
    pins: dict[str, int]
)

Bases: EStop, ModuleHardware

Hardware implementation of the e-stop module.

The module expects a dictionary of pin names and pin numbers.

Events

Name Description
ESTOP_TRIGGERED the e-stop was triggered

EStopSimulation

EStopSimulation(**kwargs)

Bases: EStop, ModuleSimulation

Simulation of the e-stop module.

Events

Name Description
ESTOP_TRIGGERED the e-stop was triggered

ExpanderHardware

ExpanderHardware(
    robot_brain: RobotBrain,
    *,
    name: str = "p0",
    serial: SerialHardware,
    boot: int = 25,
    enable: int = 14
)

Bases: ModuleHardware

The expander module represents a second ESP microcontroller connected to the core ESP via serial.

Robot

Robot(modules: list[Module])

Bases: ABC

A robot that consists of a number of modules.

It can be either a hardware robot or a simulation.

RobotHardware

RobotHardware(
    modules: list[Module], robot_brain: RobotBrain
)

Bases: Robot

A robot that consists of hardware modules.

It generates Lizard code, forwards output to the hardware modules and sends commands to the robot brain.

RobotSimulation

RobotSimulation(modules: list[Module])

Bases: Robot

A robot that consists of simulated modules.

It regularly calls the step method of all modules to allow them to update their internal state.

RobotBrain

RobotBrain(communication: Communication)

This module manages the communication with a Zauberzeug Robot Brain.

It expects a communication object, which is used for the actual read and write operations. Besides providing some basic methods like configuring or restarting the microcontroller, it augments and verifies checksums for each message.

It also keeps track of the clock offset between the microcontroller and the host system, which is used to synchronize the hardware time with the system time. The clock offset is calculated by comparing the hardware time with the system time and averaging the differences over a number of samples. If the offset changes significantly, a notification is sent and the offset history is cleared.

Events

Name Description
LINE_RECEIVED a line has been received from the microcontroller (argument: line as string)

SerialHardware

SerialHardware(
    robot_brain: RobotBrain,
    *,
    name: str = "serial",
    rx_pin: int = 26,
    tx_pin: int = 27,
    baud: int = 115200,
    num: int = 1
)

Bases: ModuleHardware

The serial module represents a serial connection with another device.

Wheels

Wheels(**kwargs)

Bases: Module, ABC

This module represents wheels for a two-wheel differential drive.

Wheels can be moved using the drive methods and provide measured velocities as an event.

Events

Name Description
VELOCITY_MEASURED new velocity measurements are available for processing (argument: list of velocities)

WheelsHardware

WheelsHardware(
    robot_brain: RobotBrain,
    *,
    can: CanHardware,
    name: str = "wheels",
    left_can_address: int = 0,
    right_can_address: int = 256,
    m_per_tick: float = 0.01,
    width: float = 0.5,
    is_left_reversed: bool = False,
    is_right_reversed: bool = False
)

Bases: Wheels, ModuleHardware

This module implements wheels hardware.

Drive and stop commands are forwarded to a given Robot Brain. Velocities are read and emitted regularly.

Events

Name Description
VELOCITY_MEASURED new velocity measurements are available for processing (argument: list of velocities)

WheelsSimulation

WheelsSimulation()

Bases: Wheels, ModuleSimulation

This module simulates two wheels.

Drive and stop commands impact internal velocities (linear and angular). A simulated pose is regularly updated with these velocities, while the velocities are emitted as an event.

Events

Name Description
VELOCITY_MEASURED new velocity measurements are available for processing (argument: list of velocities)