API: Controller
Import
Class Overview
Constructors
Controller(channel="can0")
Create a controller using standard SocketCAN transport.
Parameters:
Returns:
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:
Returns:
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:
Returns:
Controller instance
Raises: CallError if serial port cannot be opened
Example:
Controller.from_dm_device(dm_device_type="usb2canfd-dual", dm_channel="0") (classmethod)
Create a controller using the Damiao DM_Device SDK transport (USB2CANFD,
USB2CANFD_DUAL, LINKX4C). The adapter must be in USB mode; this transport
is currently Damiao-only.
Parameters:
Returns:
Controller instance
Raises: CallError if the DM_Device runtime is missing or the adapter cannot be opened. When the runtime is absent, MotorBridge prints the required runtime file, its GitHub download URL, and platform ABI requirements.
Example:
Python wheels do not embed the vendor runtime. Install it on demand with
motorbridge-install-dm-device. Windows runtime selection is restricted to x86_64; long-running processes reuse the already-open adapter.ABI Metadata Helpers
Module-level helpers discover the loaded ABI version and capabilities:motor_abi_version() / motor_abi_capabilities_json()
and the C++ motorbridge::abi_version() / motorbridge::abi_capabilities_json().
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. This remains useful for deterministic one-shot reads, scans, and Damiao feedback refreshes inside command loops.
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:
Damiao also accepts the
4340_v20 alias (displayed as 4340X) for the v2.0
hardware revision.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:
For RobStride,
feedback_id is the host_id used by the controller, not the motor device_id.Motor instance
Example:
add_myactuator_motor(motor_id, feedback_id, model)
Register a MyActuator motor and return its handle.
Parameters:
Returns:
Motor instance
Example:
add_hightorque_motor(motor_id, feedback_id, model)
Register a HighTorque motor and return its handle.
Parameters:
Returns:
Motor instance
Example:
add_hexfellow_motor(motor_id, feedback_id, model)
Register a Hexfellow motor and return its handle. Requires CAN-FD transport.
Parameters:
Returns:
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