API: Controller
Import
Class Overview
Constructors
Controller(channel="can0")
Create a controller using standard SocketCAN transport.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
channel | str | "can0" | CAN interface name |
Controller instance
Raises: CallError if interface cannot be opened
Example:
Controller.from_socketcanfd(channel="can0") (classmethod)
Create a controller using CAN-FD transport. Required for Hexfellow motors.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
channel | str | "can0" | CAN-FD interface name |
Controller instance
Raises: CallError if interface cannot be opened
Example:
Controller.from_dm_serial(serial_port="/dev/ttyACM0", baud=921600) (classmethod)
Create a controller using Damiao serial bridge transport.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
serial_port | str | "/dev/ttyACM0" | Serial device path |
baud | int | 921600 | Baud rate (use 921600 for Damiao) |
Controller instance
Raises: CallError if serial port cannot be opened
Example:
Lifecycle Methods
close()
Release controller resources. Called automatically by context manager.
Parameters: None
Returns: None
Example:
shutdown()
Gracefully shutdown the controller and all associated motors.
Parameters: None
Returns: None
Raises: CallError on failure
Note: Called automatically by context manager __exit__.
close_bus()
Close the CAN bus connection while keeping controller instance alive.
Parameters: None
Returns: None
Raises: CallError on failure
Global Motor Operations
enable_all()
Enable all registered motors simultaneously.
Parameters: None
Returns: None
Raises: CallError on failure
Example:
disable_all()
Disable all registered motors simultaneously.
Parameters: None
Returns: None
Raises: CallError on failure
Example:
poll_feedback_once()
Manually poll for feedback frames from all motors. In v0.1.7+, this is optional as background polling is enabled by default.
Parameters: None
Returns: None
Raises: CallError on failure
Example:
Motor Registration Methods
add_damiao_motor(motor_id, feedback_id, model)
Register a Damiao motor and return its handle.
Parameters:
| Name | Type | Description |
|---|---|---|
motor_id | int | Command CAN ID (typically 0x01-0x20) |
feedback_id | int | Feedback CAN ID (typically motor_id + 0x10) |
model | str | Motor model: “4310”, “4340”, “4340P”, “6001”, etc. |
Motor instance
Raises: CallError if registration fails
Example:
add_robstride_motor(motor_id, feedback_id, model)
Register a RobStride motor and return its handle.
Parameters:
| Name | Type | Description |
|---|---|---|
motor_id | int | Device ID (typically 127) |
feedback_id | int | Feedback ID (typically 0xFE or 0xFF) |
model | str | Motor model: “rs-00”, etc. |
Motor instance
Example:
add_myactuator_motor(motor_id, feedback_id, model)
Register a MyActuator motor and return its handle.
Parameters:
| Name | Type | Description |
|---|---|---|
motor_id | int | Motor ID (1-32) |
feedback_id | int | Feedback ID (typically 0x240 + motor_id) |
model | str | Motor model: “X8”, etc. |
Motor instance
Example:
add_hightorque_motor(motor_id, feedback_id, model)
Register a HighTorque motor and return its handle.
Parameters:
| Name | Type | Description |
|---|---|---|
motor_id | int | Motor ID (1-127) |
feedback_id | int | Feedback ID (typically 0x01) |
model | str | Motor model: “hightorque” |
Motor instance
Example:
add_hexfellow_motor(motor_id, feedback_id, model)
Register a Hexfellow motor and return its handle. Requires CAN-FD transport.
Parameters:
| Name | Type | Description |
|---|---|---|
motor_id | int | Motor ID |
feedback_id | int | Feedback ID (typically 0x00) |
model | str | Motor model: “hexfellow” |
Motor instance
Raises: CallError if not using CAN-FD transport
Example:
Context Manager Support
TheController class supports Python’s context manager protocol for automatic resource cleanup:
Error Handling
All methods may raise exceptions frommotorbridge.errors:
See Also
- Motor API - Motor handle methods
- Mode and State - Enums and data classes
- Transports - Transport configuration guide