DaMiaoMotor¶
damiao_motor.core.motor.DaMiaoMotor ¶
DaMiaoMotor(motor_id: int, feedback_id: int, bus: can.Bus, *, motor_type: str, p_min: Optional[float] = None, p_max: Optional[float] = None, v_min: Optional[float] = None, v_max: Optional[float] = None, t_min: Optional[float] = None, t_max: Optional[float] = None)
Lightweight DaMiao motor wrapper over a CAN bus.
Source code in damiao_motor/core/motor.py
clear_error ¶
encode_clear_error_msg
staticmethod
¶
encode_cmd_msg ¶
Encode a command to CAN frame for sending to the motor. Uses this motor's P/V/T limits (from motor_type preset) and fixed kp (KP_MIN/KP_MAX), kd (KD_MIN/KD_MAX).
Source code in damiao_motor/core/motor.py
encode_save_position_zero_msg
staticmethod
¶
ensure_control_mode ¶
Ensure control mode (register 10) matches the desired mode. Reads register 10; if it differs, writes and verifies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
control_mode |
str
|
"MIT", "POS_VEL", "VEL", or "FORCE_POS" |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If control_mode is invalid or register value is invalid |
TimeoutError
|
If reading/writing register times out |
RuntimeError
|
Other errors during register operations, or if verification after write fails |
Source code in damiao_motor/core/motor.py
get_register ¶
Read a register value from the motor.
If the value is not already cached, sends a read request and waits for the controller's background polling to receive the reply. The motor never reads from the bus; only the controller's poll_feedback does, avoiding multiple consumers.
Requires the motor to be managed by a DaMiaoController (added via controller.add_motor). Standalone motors can only return cached values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rid |
int
|
Register ID (0-81) |
required |
timeout |
float
|
Timeout in seconds to wait for response |
1.0
|
Returns:
| Type | Description |
|---|---|
float | int
|
Register value as float or int depending on register data type |
Raises:
| Type | Description |
|---|---|
KeyError
|
If register ID is not in the register table |
RuntimeError
|
If the motor is not managed by a controller (no background polling) |
TimeoutError
|
If the register reply was not received within timeout |
Source code in damiao_motor/core/motor.py
get_register_info ¶
Get information about a register.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rid |
int
|
Register ID |
required |
Returns:
| Type | Description |
|---|---|
RegisterInfo
|
RegisterInfo object with register details |
Raises:
| Type | Description |
|---|---|
KeyError
|
If register ID is not in the register table |
Source code in damiao_motor/core/motor.py
get_states ¶
Get the current motor state dictionary.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary containing current motor state information: |
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Source code in damiao_motor/core/motor.py
read_all_registers ¶
Read all registers from the motor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout |
float
|
Timeout in seconds per register read |
0.05
|
Returns:
| Type | Description |
|---|---|
Dict[int, float | int]
|
Dictionary mapping register ID to value |
Source code in damiao_motor/core/motor.py
request_motor_feedback ¶
Request motor feedback/status information. After successful transmission, the motor driver will return current status information.
Source code in damiao_motor/core/motor.py
request_register_reading ¶
Request a register reading from the motor.
Source code in damiao_motor/core/motor.py
send_cmd ¶
send_cmd(target_position: float = 0.0, target_velocity: float = 0.0, stiffness: float = 0.0, damping: float = 0.0, feedforward_torque: float = 0.0, control_mode: str = 'MIT', velocity_limit: float = 0.0, current_limit: float = 0.0) -> None
Send command to motor with specified control mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_position |
float
|
Desired position (radians) |
0.0
|
target_velocity |
float
|
Desired velocity (rad/s) |
0.0
|
stiffness |
float
|
Stiffness (kp) for MIT mode |
0.0
|
damping |
float
|
Damping (kd) for MIT mode |
0.0
|
feedforward_torque |
float
|
Feedforward torque for MIT mode |
0.0
|
control_mode |
str
|
Control mode - "MIT" (default), "POS_VEL", "VEL", or "FORCE_POS" |
'MIT'
|
velocity_limit |
float
|
Velocity limit (rad/s, 0-100) for FORCE_POS mode |
0.0
|
current_limit |
float
|
Current limit normalized (0.0-1.0) for FORCE_POS mode |
0.0
|
Note
Before using this method to send commands, ensure that the motor's control mode register (register 10) is set to match the desired control_mode argument ("MIT", "POS_VEL", "VEL", or "FORCE_POS"). If the register does not match, the motor will not respond to commands and will not move.
Source code in damiao_motor/core/motor.py
send_raw ¶
Send raw CAN message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data |
bytes
|
CAN message data bytes (must be 8 bytes) |
required |
arbitration_id |
int | None
|
CAN arbitration ID (defaults to motor_id if not specified) |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If data is not 8 bytes or arbitration_id is invalid |
OSError
|
If CAN bus error occurs (e.g., Error Code 105 - No buffer space) |
CanError
|
If CAN-specific error occurs |
AttributeError
|
If bus is not initialized |
Source code in damiao_motor/core/motor.py
set_acceleration ¶
set_can_baud_rate ¶
Set CAN baud rate using register 35 (can_br).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
baud_rate_code |
int
|
Baud rate code (0=125K, 1=200K, 2=250K, 3=500K, 4=1M) |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If baud_rate_code is not in valid range [0, 4] |
Source code in damiao_motor/core/motor.py
set_can_timeout ¶
Set CAN timeout alarm time (register 9).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout_ms |
int
|
Timeout in milliseconds |
required |
Note
Register 9 stores timeout in units of 50 microseconds: 1 register unit = 50 microseconds.
Conversion formula: register_value = timeout_ms × 20
Examples: - 1000 ms = 1,000,000 microseconds = 20,000 register units - 50 ms = 50,000 microseconds = 1,000 register units
Source code in damiao_motor/core/motor.py
set_control_mode ¶
set_current_loop_bandwidth ¶
set_current_loop_enhancement ¶
set_deceleration ¶
set_feedback_id ¶
set_gear_efficiency ¶
set_limits ¶
set_limits(*, p_min: Optional[float] = None, p_max: Optional[float] = None, v_min: Optional[float] = None, v_max: Optional[float] = None, t_min: Optional[float] = None, t_max: Optional[float] = None) -> None
Update only the specified P/V/T limits. Omitted keys are left unchanged. kp and kd are fixed (KP_MIN/KP_MAX, KD_MIN/KD_MAX).
Source code in damiao_motor/core/motor.py
set_maximum_speed ¶
set_motor_type ¶
Update motor type and P/V/T limits from a preset. Validates against MOTOR_TYPE_PRESETS.
Source code in damiao_motor/core/motor.py
set_over_current_protection ¶
set_over_temperature_protection ¶
set_overvoltage_protection ¶
set_p_limits ¶
set_position_loop_ki ¶
set_position_loop_kp ¶
set_position_mapping_range ¶
set_receive_id ¶
set_speed_loop_damping ¶
set_speed_loop_enhancement ¶
set_speed_loop_filter_bandwidth ¶
set_speed_loop_ki ¶
set_speed_loop_kp ¶
set_speed_mapping_range ¶
set_t_limits ¶
set_timeout_alarm ¶
Set timeout alarm time (register 9).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value |
int
|
Timeout value in register units (1 unit = 50 microseconds) |
required |
Note
This method writes the raw register value. For convenience, use set_can_timeout()
which accepts milliseconds and handles the conversion automatically.
Conversion: 1 register unit = 50 microseconds To convert from milliseconds: register_value = timeout_ms × 20
Source code in damiao_motor/core/motor.py
set_torque_coefficient ¶
set_torque_mapping_range ¶
set_under_voltage_protection ¶
set_v_limits ¶
set_zero_command ¶
Send zero command (pos=0, vel=0, torq=0, kp=0, kd=0).
set_zero_position ¶
store_parameters ¶
Store all parameters to flash memory. After successful write, all parameters will be written to the chip.
write_register ¶
Write a value to a register.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rid |
int
|
Register ID (0-81) |
required |
value |
float | int
|
Value to write (float or int) |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
If register ID is not in the register table |
ValueError
|
If register is read-only or value is out of range |