跳转至

Motor

robodyno.components.can_bus.motor

This module provides a class for controlling Robodyno motors.

The Motor class provided by this module is used to control Robodyno motors through the CAN bus. It provides methods for setting motor parameters, reading motor states, and controlling the motor to run in different modes.

Examples:

>>> from robodyno.components import Motor
>>> from robodyno.interfaces import CanBus
>>> can_bus = CanBus()
>>> motor = Motor(can_bus)
>>> print(motor)
Motor(id=0x10, type=ROBODYNO_PRO_P44, state=DISABLED, error=NONE)
>>> can_bus.disconnect()

Motor

Bases: CanBusDevice

Controls Robodyno motors through the CAN bus.

Attributes:

Name Type Description
id int

The ID of the motor device on the CAN bus.

type Model

The model type of the motor.

fw_ver float

The firmware version of the motor.

reduction float

The reduction ratio of the motor.

available_velocity float

The maximum velocity of the motor.

available_torque float

The maximum torque of the motor.

available_current float

The maximum phase current of the motor.

torque_constant float

The torque constant of the motor in Nm/A. This is the torque provided by the motor when the current is 1A.

with_brake bool

Whether the motor has a brake.

state Motor.MotorState

The working state of the motor.

error Dict

The error information of the motor.

mode Motor.MotorControlMode

The control mode of the motor.

sync_time int

The synchronization time of the motor in milliseconds.

__init__(can, id_=16, type_=None)

Initializes the Robodyno motor based on the device id and type.

Parameters:

Name Type Description Default
can CanBus

The CAN bus interface.

required
id_ int

The device id. The default factory id of the motor is 0x10.

16
type_ string

Forcing the motor type. The default is None.

None

Raises:

Type Description
ValueError

If the motor type is invalid.

enable()

Enables the motor.

After enabled, the motor can be controlled.

disable()

Disables the motor.

This is the default state after power on. After disabled, the motor will stop working and loose torque.

unlock()

Unlocks the motor.

This command only works on motors with brake. After unlocked, the motor can be rotated freely.

Raises:

Type Description
NotImplementedError

If the motor does not support brake.

init_pos(initial_pos=0)

Sets the current position of the motor as the initial position.

Parameters:

Name Type Description Default
initial_pos float

The initial position in rad.

0

Raises:

Type Description
NotImplementedError

If the firmware version is < 1.0.

init_abs_pos(initial_pos=0)

Sets the current absolute position of the motor as the initial position.

Parameters:

Name Type Description Default
initial_pos float

The initial absolute position in rad.

0

Raises:

Type Description
NotImplementedError

If the firmware version is < 1.0.

calibrate()

Calibrates the motor.

Save the configurations after calibration manually by calling save_configuration() if needed.

config_can_bus(new_id=None, heartbeat=1000, bitrate=1000000)

Configures the CAN bus settings of the motor.

Parameters:

Name Type Description Default
new_id int

The new device id.

None
heartbeat int

The heartbeat period in milliseconds.

1000
bitrate int

The bitrate of the CAN bus. Choose from 250000, 500000, 1000000.

1000000

Raises:

Type Description
ValueError

If the new CAN id is not in the range of 0x01-0x3f.

ValueError

If the bitrate is not one of 250000, 500000, 1000000.

save()

Saves the motor configurations.

If the motor is in a running state, the motor will stop and save the configurations.

save_configuration()

Saves the motor configurations.

This method will be deprecated. Use save instead.

clear_errors()

Clears the motor errors.

Most errors are cleared automatically if the cause is resolved.

estop()

Requests an emergency stop.

The motor will loose torque immediately and report an ESTOP error.

reboot()

Reboots the motor.

reset()

Resets the motor.

This command will reset the motor to the factory settings. All configurations will be lost and the id will be reset to 0x10. The motor must be calibrated again after reset.

position_mode()

Sets the motor to position mode.

position_filter_mode(bandwidth)

Sets the motor to position filter mode.

Parameters:

Name Type Description Default
bandwidth float

The bandwidth of the filter in Hz. The value is suggested to be the control loop frequency in Hz.

required

position_track_mode(vel, acc, dec)

Sets the motor to position track mode.

Parameters:

Name Type Description Default
vel float

The velocity limit in rad/s.

required
acc float

The acceleration in rad/s^2. The value must be positive.

required
dec float

The deceleration in rad/s^2. The value must be positive.

required

velocity_mode()

Sets the motor to velocity mode.

velocity_ramp_mode(ramp)

Sets the motor to velocity ramp mode.

Parameters:

Name Type Description Default
ramp float

The velocity ramp in rad/s^2. The value must be positive.

required

torque_mode()

Sets the motor to torque mode.

set_pos(pos, vel_ff=0, torque_ff=0)

Sets the target position of the motor.

Parameters:

Name Type Description Default
pos float

The target position in rad.

required
vel_ff float

The velocity feedforward in rad/s.

0
torque_ff float

The torque feedforward in Nm.

0

set_abs_pos(pos, vel_ff=0, torque_ff=0)

Sets the target absolute position of the motor.

Parameters:

Name Type Description Default
pos float

The target absolute position in rad.

required
vel_ff float

The velocity feedforward in rad/s.

0
torque_ff float

The torque feedforward in Nm.

0

Raises:

Type Description
NotImplementedError

If the firmware version is < 1.0.

set_vel(vel, torque_ff=0)

Sets the target velocity of the motor.

Parameters:

Name Type Description Default
vel float

The target velocity in rad/s.

required
torque_ff float

The torque feedforward in Nm.

0

set_torque(torque)

Sets the target torque of the motor.

Parameters:

Name Type Description Default
torque float

The target torque in Nm.

required

set_pid(pos_kp, vel_kp, vel_ki)

Sets the PID parameters of the motor.

Parameters:

Name Type Description Default
pos_kp float

The Kp of the position control loop.

required
vel_kp float

The Kp of the velocity control loop.

required
vel_ki float

The Ki of the velocity control loop.

required

set_vel_limit(vel_lim)

Sets the velocity limit of the motor.

Parameters:

Name Type Description Default
vel_lim float

The velocity limit in rad/s. The value must be positive.

required

Raises:

Type Description
ValueError

If the velocity limit is out of range.

set_current_limit(current_lim)

Sets the current limit of the motor.

Parameters:

Name Type Description Default
current_lim float

The current limit in amps. The value must be positive.

required

Raises:

Type Description
ValueError

If the current limit is out of range.

get_state(timeout=None)

Reads the motor state and error.

Parameters:

Name Type Description Default
timeout float

The timeout in seconds.

None

Returns:

Type Description
tuple | None

The motor state, error, and control mode. Returns None if the read times out.

Raises:

Type Description
NotImplementedError

If the firmware version is < 1.0.

get_voltage(timeout=None)

Reads the DC bus voltage of the motor.

Parameters:

Name Type Description Default
timeout float

The timeout in seconds.

None

Returns:

Type Description
float | None

The DC bus voltage in volts. Returns None if the read times out.

get_temperature(timeout=None)

Reads the temperature of the motor.

Parameters:

Name Type Description Default
timeout float

The timeout in seconds.

None

Returns:

Type Description
float | None

The temperature in degrees Celsius. Returns None if the read times out.

get_mode(timeout=None)

Reads the control mode and the mode parameters of the motor.

Parameters:

Name Type Description Default
timeout float

The timeout in seconds.

None

Returns:

Type Description
tuple | None

The control mode and the mode parameters. Returns None if the read times out.

get_feedback(timeout=None)

Reads the feedbacks of the motor.

Parameters:

Name Type Description Default
timeout float

The timeout in seconds.

None

Returns:

Type Description
tuple | None

The position, velocity, and torque. Returns None if the read times out.

get_pos(timeout=None)

Reads the position of the motor.

Parameters:

Name Type Description Default
timeout float

The timeout in seconds.

None

Returns:

Type Description
float | None

The position in rad. Returns None if the read times out.

get_abs_pos(timeout=None)

Reads the absolute position of the motor.

Parameters:

Name Type Description Default
timeout float

The timeout in seconds.

None

Returns:

Type Description
float | None

The absolute position in rad. Returns None if the read times out.

Raises:

Type Description
NotImplementedError

If the firmware version is < 1.0.

get_vel(timeout=None)

Reads the velocity of the motor.

Parameters:

Name Type Description Default
timeout float

The timeout in seconds.

None

Returns:

Type Description
float | None

The velocity in rad/s. Returns None if the read times out.

get_torque(timeout=None)

Reads the torque of the motor.

Parameters:

Name Type Description Default
timeout float

The timeout in seconds.

None

Returns:

Type Description
float | None

The torque in Nm. Returns None if the read times out.

get_pid(timeout=None)

Reads the PID parameters of the motor.

Parameters:

Name Type Description Default
timeout float

The timeout in seconds.

None

Returns:

Type Description
tuple | None

The position KP, velocity KP, and velocity KI. Returns None if the read times out.

get_vel_limit(timeout=None)

Reads the velocity limit of the motor.

Parameters:

Name Type Description Default
timeout float

The timeout in seconds.

None

Returns:

Type Description
float | None

The velocity limit in rad/s. Returns None if the read times out.

get_current_limit(timeout=None)

Reads the current limit of the motor.

Parameters:

Name Type Description Default
timeout float

The timeout in seconds.

None

Returns:

Type Description
float | None

The current limit in A. Returns None if the read times out.

MotorState

Bases: Enum

Enumerates motor working states.

UNKNOWN = -1 class-attribute instance-attribute

The state of the motor is unknown.

DISABLED = 1 class-attribute instance-attribute

The motor is disabled.

CALIBRATE = 3 class-attribute instance-attribute

The motor is preparing for calibration.

MOTOR_CALIBRATING = 4 class-attribute instance-attribute

The motor is calibrating.

OFFSET_CALIBRATING = 7 class-attribute instance-attribute

The motor is calibrating the encoder.

ENABLED = 8 class-attribute instance-attribute

The motor is enabled.

HOMING = 11 class-attribute instance-attribute

The motor is aligning the encoders.

MotorError

Bases: Enum

Enumerates motor errors.

NONE = 0 class-attribute instance-attribute

No error.

INVALID_STATE = 1 class-attribute instance-attribute

The motor is in an invalid state.

UNDER_VOLTAGE = 2 class-attribute instance-attribute

The motor is under voltage.

OVER_VOLTAGE = 3 class-attribute instance-attribute

The motor is over voltage.

CURRENT_MEASUREMENT_TIMEOUT = 4 class-attribute instance-attribute

The motor current measurement timed out.

BRAKE_RESISTOR_DISARMED = 5 class-attribute instance-attribute

The brake resistor is disarmed.

MOTOR_DISARMED = 6 class-attribute instance-attribute

The motor is disarmed.

MOTOR_FAILED = 7 class-attribute instance-attribute

The driver of the motor failed.

SENSORLESS_ESTIMATOR_FAILED = 8 class-attribute instance-attribute

The sensorless estimator of the motor failed.

ENCODER_FAILED = 9 class-attribute instance-attribute

The encoder of the motor failed.

CONTROLLER_FAILED = 10 class-attribute instance-attribute

The controller of the motor failed.

POS_CTRL_DURING_SENSORLESS = 11 class-attribute instance-attribute

The position controller of the motor is running during sensorless mode.

WATCHDOG_TIMER_EXPIRED = 12 class-attribute instance-attribute

The watchdog timer of the motor expired.

MIN_ENDSTOP_PRESSED = 13 class-attribute instance-attribute

The minimum endstop of the motor is pressed.

MAX_ENDSTOP_PRESSED = 14 class-attribute instance-attribute

The maximum endstop of the motor is pressed.

ESTOP_REQUESTED = 15 class-attribute instance-attribute

The motor is requested to emergency stop.

HOMING_WITHOUT_ENDSTOP = 16 class-attribute instance-attribute

The motor is homing without endstop.

OVER_TEMP = 17 class-attribute instance-attribute

The motor is over temperature.

MotorMotorError

Bases: Enum

Enumerates motor driver errors.

NONE = 0 class-attribute instance-attribute

No error.

PHASE_RESISTANCE_OUT_OF_RANGE = 1 class-attribute instance-attribute

The phase resistance of the motor is out of range.

PHASE_INDUCTANCE_OUT_OF_RANGE = 2 class-attribute instance-attribute

The phase inductance of the motor is out of range.

ADC_FAILED = 3 class-attribute instance-attribute

The ADC of the motor failed.

DRV_FAULT = 4 class-attribute instance-attribute

The driver of the motor failed.

CONTROL_DEADLINE_MISSED = 5 class-attribute instance-attribute

The control deadline of the motor is missed.

NOT_IMPLEMENTED_MOTOR_TYPE = 6 class-attribute instance-attribute

The motor type is not implemented.

BRAKE_CURRENT_OUT_OF_RANGE = 7 class-attribute instance-attribute

The brake current of the motor is out of range.

MODULATION_MAGNITUDE = 8 class-attribute instance-attribute

The low level modulation failed.

BRAKE_DEADTIME_VIOLATION = 9 class-attribute instance-attribute

The brake deadtime of the motor is violated.

UNEXPECTED_TIMER_CALLBACK = 10 class-attribute instance-attribute

The timer callback of the motor is unexpected.

CURRENT_SENSE_SATURATION = 11 class-attribute instance-attribute

The current sense of the motor is saturated.

CURRENT_LIMIT_VIOLATION = 13 class-attribute instance-attribute

The current limit of the motor is violated.

BRAKE_DUTY_CYCLE_NAN = 14 class-attribute instance-attribute

The brake duty cycle of the motor is NaN.

DC_BUS_OVER_REGEN_CURRENT = 15 class-attribute instance-attribute

The DC bus is over allowable regenerative current.

DC_BUS_OVER_CURRENT = 16 class-attribute instance-attribute

The DC bus is over current.

MotorEncoderError

Bases: Enum

Enumerates motor encoder errors.

NONE = 0 class-attribute instance-attribute

No error.

UNSTABLE_GAIN = 1 class-attribute instance-attribute

The PLL gain of the encoder is unstable.

CPR_POLEPAIRS_MISMATCH = 2 class-attribute instance-attribute

The CPR and pole pairs of the encoder mismatch.

NO_RESPONSE = 3 class-attribute instance-attribute

The encoder does not respond.

UNSUPPORTED_ENCODER_MODE = 4 class-attribute instance-attribute

The encoder mode is not supported.

ILLEGAL_HALL_STATE = 5 class-attribute instance-attribute

The hall state of the encoder is illegal.

INDEX_NOT_FOUND_YET = 6 class-attribute instance-attribute

The index of the encoder is not found yet.

ABS_SPI_TIMEOUT = 7 class-attribute instance-attribute

The SPI of the encoder timed out.

ABS_SPI_COM_FAIL = 8 class-attribute instance-attribute

The SPI of the encoder failed.

ABS_SPI_NOT_READY = 9 class-attribute instance-attribute

The SPI of the encoder is not ready.

MotorControllerError

Bases: Enum

Enumerates motor controller errors.

NONE = 0 class-attribute instance-attribute

No error.

OVERSPEED = 1 class-attribute instance-attribute

The motor is overspeed.

INVALID_INPUT_MODE = 2 class-attribute instance-attribute

The input mode of the motor is invalid.

UNSTABLE_GAIN = 3 class-attribute instance-attribute

The gain of the sensorless estimator is unstable.

INVALID_MIRROR_AXIS = 4 class-attribute instance-attribute

The mirror axis of the motor is invalid.

INVALID_LOAD_ENCODER = 5 class-attribute instance-attribute

The encoder of the motor is invalid.

INVALID_ESTIMATE = 6 class-attribute instance-attribute

The estimate feedbacks of the motor is invalid.

MotorControlMode

Bases: Enum

Enumerates motor control modes.

UNKNOWN = (0, 0) class-attribute instance-attribute

The motor control mode is unknown.

POSITION_MODE = (3, 1) class-attribute instance-attribute

Control the motor in position mode.

POSITION_FILTER_MODE = (3, 3) class-attribute instance-attribute

Control the motor in position filter mode.

POSITION_TRACK_MODE = (3, 5) class-attribute instance-attribute

Control the motor in position track mode.

VELOCITY_MODE = (2, 1) class-attribute instance-attribute

Control the motor in velocity mode.

VELOCITY_RAMP_MODE = (2, 2) class-attribute instance-attribute

Control the motor in velocity ramp mode.

TORQUE_MODE = (1, 1) class-attribute instance-attribute

Control the motor in torque mode.