feathersdk.robot.actuators.damiao.utils Module

feathersdk.robot.actuators.damiao.utils.write_json_file(data, file_path, *, perms=None, indent=2)

Atomically serialize data as JSON to file_path.

Uses feathersdk.utils.files.thread_safe_file_writer() so the file is written to a temporary location and renamed in place, avoiding partial writes if the process is interrupted.

Parameters:
  • data (Any) – Any JSON-serializable object.

  • file_path (str | Path) – Destination path.

  • perms (int | None) – Optional final file permissions (octal, e.g. 0o644).

  • indent (int) – Pretty-print indent width passed to json.dumps().

Return type:

None

feathersdk.robot.actuators.damiao.utils.read_json_file(file_path)

Read and parse a JSON file at file_path.

Parameters:

file_path (str | Path)

Return type:

Any

feathersdk.robot.actuators.damiao.utils.uint_to_float(x_int, x_min, x_max, bits)

Converts unsigned int to float, given range and number of bits.

Parameters:
Return type:

float

feathersdk.robot.actuators.damiao.utils.float_to_uint(x, x_min, x_max, bits)

Converts a float to an unsigned int, given range and number of bits.

Parameters:
Return type:

int

class feathersdk.robot.actuators.damiao.utils.MotorConstants(POSITION_MAX: float = 12.5, POSITION_MIN: float = -12.5, VELOCITY_MAX: float = 45, VELOCITY_MIN: float = -45, TORQUE_MAX: float = 54, TORQUE_MIN: float = -54, CURRENT_MAX: float = 1.0, CURRENT_MIN: float = -1.0, KT: float = 1.0, KP_MAX: float = 500.0, KP_MIN: float = 0.0, KD_MAX: float = 5.0, KD_MIN: float = 0.0)

Bases: object

Parameters:
POSITION_MAX: float = 12.5
POSITION_MIN: float = -12.5
VELOCITY_MAX: float = 45
VELOCITY_MIN: float = -45
TORQUE_MAX: float = 54
TORQUE_MIN: float = -54
CURRENT_MAX: float = 1.0
CURRENT_MIN: float = -1.0
KT: float = 1.0
KP_MAX: float = 500.0
KP_MIN: float = 0.0
KD_MAX: float = 5.0
KD_MIN: float = 0.0
class feathersdk.robot.actuators.damiao.utils.MotorInfo(id, error_code, target_torque=0, vel=0.0, eff=0, pos=0, voltage=-1, temp_mos=-1, temp_rotor=-1)

Bases: object

Class to represent motor information.

Variables:
  • id (int) – Motor ID.

  • target_torque (int) – Target torque value.

  • vel (float) – Motor speed.

  • eff (float) – Motor current.

  • pos (float) – Encoder value.

  • voltage (float) – Motor voltage.

  • temperature (float) – Motor temperature.

Parameters:
id: int
error_code: int
target_torque: int = 0
vel: float = 0.0
eff: float = 0
pos: float = 0
voltage: float = -1
temp_mos: float = -1
temp_rotor: float = -1
class feathersdk.robot.actuators.damiao.utils.FeedbackFrameInfo(id: int, error_code: int, error_message: str, position: float, velocity: float, torque: float, temperature_mos: float, temperature_rotor: float)

Bases: object

Parameters:
id: int
error_code: int
error_message: str
position: float
velocity: float
torque: float
temperature_mos: float
temperature_rotor: float
class feathersdk.robot.actuators.damiao.utils.EncoderInfo

Bases: object

encoder = -1
encoder_raw = -1
encoder_offset = -1
class feathersdk.robot.actuators.damiao.utils.MotorErrorCode

Bases: object

disabled = 0
normal = 1
over_voltage = 8
under_voltage = 9
over_current = 10
mosfet_over_temperature = 11
motor_over_temperature = 12
loss_communication = 13
overload = 14
motor_error_code_dict = {0: 'disabled', 1: 'normal', 8: 'over voltage', 9: 'under voltage', 10: 'over current', 11: 'mosfet over temperature', 12: 'motor over temperature', 13: 'loss communication', 14: 'overload'}
classmethod get_error_message(error_code)
Parameters:

error_code (int)

Return type:

str

class feathersdk.robot.actuators.damiao.utils.MotorType

Bases: object

DM4310 = 'DM4310'
classmethod get_motor_constants(motor_type=None)

Get motor constants for DM4310.

Parameters:

motor_type (str) – Optional motor type (ignored, kept for compatibility).

Returns:

MotorConstants for DM4310.

Return type:

MotorConstants

class feathersdk.robot.actuators.damiao.utils.AutoNameEnum(value)

Bases: Enum

class feathersdk.robot.actuators.damiao.utils.ReceiveMode(value)

Bases: AutoNameEnum

p16 = 'p16'
same = 'same'
zero = 'zero'
plus_one = 'plus_one'
get_receive_id(motor_id)
Parameters:

motor_id (int)

Return type:

int

to_motor_id(receive_id)
Parameters:

receive_id (int)

Return type:

int

class feathersdk.robot.actuators.damiao.utils.RawCanInterface(channel='PCAN_USBBUS1', bustype='pcan', bitrate=1000000, name='default_can_interface')

Bases: object

Parameters:
close()

Shut down the CAN bus.

Return type:

None

try_receive_message(motor_id=None, timeout=0.009)

Try to receive a message from the CAN bus.

Parameters:
  • timeout (float) – The time to wait for a message (in seconds).

  • motor_id (int | None)

Returns:

The received message, or None if no message is received.

Return type:

can.Message

feathersdk.robot.actuators.damiao.utils.bytes_to_uint32(data)

Convert the last 4 bytes (data[4:8]) in a bytearray to uint32 (little-endian).

Parameters:

data (bytearray)

Return type:

int

feathersdk.robot.actuators.damiao.utils.bytes_to_float32(data)

Convert the last 4 bytes (data[4:8]) in a bytearray to float32 (little-endian).

Parameters:

data (bytearray)

Return type:

float

feathersdk.robot.actuators.damiao.utils.uint32_to_bytes(value)

Convert a uint32 value to a 4-byte bytearray (little-endian).

Parameters:

value (int) – A uint32 value to be converted to bytes.

Returns:

The corresponding 4-byte representation in little-endian order.

Return type:

bytearray

feathersdk.robot.actuators.damiao.utils.float32_to_bytes(value)

Convert a float32 value to a 4-byte bytearray (little-endian).

Parameters:

value (float) – A float32 value to be converted to bytes.

Returns:

The corresponding 4-byte representation in little-endian order.

Return type:

bytearray

feathersdk.robot.actuators.damiao.utils.get_special_message_response(can_interface, motor_id, reg_name)

Get the current value of a register from a motor.

Parameters:
  • can_interface (RawCanInterface) – The CAN interface to use.

  • motor_id (int) – The ID of the motor to read the register value from.

  • reg_name (str) – The name of the register to read.

Returns:

The value read from the register.

Return type:

Any

feathersdk.robot.actuators.damiao.utils.write_special_message(can_interface, motor_id, reg_name, data)

Write a value to a register of a motor.

Parameters:
  • can_interface (RawCanInterface) – The CAN interface to use.

  • motor_id (int) – The ID of the motor to write the register value for.

  • reg_name (str) – The name of the register to write.

  • data (Any) – The value to write to the register.

Returns:

The value read from the register after writing.

Return type:

Any

feathersdk.robot.actuators.damiao.utils.save_to_memory(can_interface, motor_id, reg_name)

Save the current value of a register to the motor’s memory.

Parameters:
  • can_interface (RawCanInterface) – The CAN interface to use.

  • motor_id (int) – The ID of the motor to save the register value for.

  • reg_name (str) – The name of the register to save.

Returns:

The response message from the motor.

Return type:

can.Message