ODrive Module
ODrive is a high-performance servo motor drive module launched by M5Stack, based on the open source motion control solution ODrive.
Support the following products:
Micropython Example:
import os, sys, io
import M5
from M5 import *
from module import ODriveModule
drive = ODriveModule(port=(13,5))
drive.get_vbus_voltage()
drive.set_velocity(10)
drive.set_current(5)
drive.set_control_mode(ODriveModule.CONTROL_MODE_POSITION_CONTROL)
drive.set_position(1000)
UIFLOW2 Example:
class ODriveModule
Constructors
Methods
- ODriveModule.set_position(position, velocity_feedforward, current_feedforward)
Set the target position with optional feedforward values.
- Parameters:
UIFLOW2:
- ODriveModule.set_velocity(velocity, current_feedforward)
Set the target velocity with optional current feedforward.
- Parameters:
velocity – The target velocity in counts/s or radians/s.
current_feedforward (float) – The feedforward current in amperes to assist the controller.
UIFLOW2:
- ODriveModule.set_current(current)
Set the target current.
- Parameters:
current – The target current in amperes for torque control.
UIFLOW2:
- ODriveModule.set_gain(pos_gain, vel_gain, vel_integrator_gain)
- Parameters:
pos_gain
vel_gain
vel_integrator_gain
UIFLOW2:
- ODriveModule.set_control_mode(mode)
Set the control mode of the controller.
- Parameters:
mode – The control mode.
UIFLOW2:
- ODriveModule.set_control_input_pos(pos)
Set the control input position for the controller.
- Parameters:
pos – The desired input position in counts or radians for position control.
UIFLOW2:
- ODriveModule.trapezoidal_move(position)
Perform a trapezoidal move to the given position.
- Parameters:
position – The target position in counts or radians to move to using a trapezoidal velocity profile.
UIFLOW2:
- ODriveModule.run_state(requested_state, timeout)
Run the axis to the requested state within a timeout period.
- Parameters:
requested_state – The desired axis state to transition to, using the AXIS_STATE_* constants.
timeout – Timeout in milliseconds to wait for the axis to reach the requested state.
UIFLOW2:
- ODriveModule.get_velocity()
Get the estimated velocity of the motor.
- Return (float):
The estimated velocity in counts/s or radians/s.
UIFLOW2:
- ODriveModule.get_vbus_voltage()
Get the measured bus voltage.
- Return (float):
The bus voltage in volts.
UIFLOW2:
- ODriveModule.get_phase_current()
Get the measured phase current of the motor.
- Return (float):
The phase current in amperes.
UIFLOW2:
- ODriveModule.get_bus_current()
Get the bus current drawn by the motor.
- Return (float):
The bus current in amperes.
UIFLOW2:
- ODriveModule.get_encoder_shadow_count()
Get the encoder's shadow count, which is an internal counter.
- Return (int):
The shadow count as an integer value.
UIFLOW2:
- ODriveModule.get_encoder_pos_estimate()
Get the estimated position from the encoder.
- Return (float):
The estimated position in counts or radians.
UIFLOW2:
- ODriveModule.get_motor_temp()
Get the temperature of the motor thermistor.
- Return (float):
The motor temperature in degrees Celsius.
UIFLOW2:
- ODriveModule.erase_config()
Erase the current configuration settings.
UIFLOW2:
- ODriveModule.save_config()
Save the current configuration to non-volatile memory.
UIFLOW2:
- ODriveModule.reboot()
Reboot the ODrive device.
UIFLOW2:
- ODriveModule.set_default_config()
Set the default configuration parameters.
UIFLOW2:
- ODriveModule.check_error()
Check for any errors in the system components.
UIFLOW2:
- ODriveModule.read_flush()
Flush the UART read buffer to clear any residual data.
UIFLOW2:
- ODriveModule.read_string()
Read a string terminated by a newline character from the device.
- Return (str):
The string read from the device, excluding the newline character.
UIFLOW2:
- ODriveModule.read_float()
Read a floating-point value from the device.
- Return (float):
The float value read from the device; returns 0.0 if parsing fails.
UIFLOW2:
- ODriveModule.read_int()
Read an integer value from the device.
- Return (int):
The integer value read from the device; returns 0 if parsing fails.
UIFLOW2:
- ODriveModule.write_to_device(data)
Write a command string to the device via UART.
- Parameters:
data – The command string to send to the device, ending with a newline character.
UIFLOW2:
- ODriveModule.write_config(config, value)
Write a configuration parameter to the device.
- Parameters:
config – The configuration key as a string, e.g., 'axis0.controller.config.pos_gain'.
value – The value to set for the configuration parameter; can be a float or integer.
UIFLOW2:
- ODriveModule.read_config_int(config)
Read an integer configuration parameter from the device.
- Return (int):
The integer value of the specified configuration parameter; returns 0 if parsing fails.
- Parameters:
config – The configuration key as a string, e.g., 'axis0.encoder.error'.
UIFLOW2:
- ODriveModule.read_config_float(config)
Read a floating-point configuration parameter from the device.
- Return (float):
The float value of the specified configuration parameter; returns 0.0 if parsing fails.
- Parameters:
config – The configuration key as a string, e.g., 'axis0.motor_thermistor.temperature'.
UIFLOW2:
Constants
- ODriveModule.AXIS_STATE_UNDEFINED
- ODriveModule.AXIS_STATE_IDLE
- ODriveModule.AXIS_STATE_STARTUP_SEQUENCE
- ODriveModule.AXIS_STATE_FULL_CALIBRATION_SEQUENCE
- ODriveModule.AXIS_STATE_MOTOR_CALIBRATION
- ODriveModule.AXIS_STATE_SENSORLESS_CONTROL
- ODriveModule.AXIS_STATE_ENCODER_INDEX_SEARCH
- ODriveModule.AXIS_STATE_ENCODER_OFFSET_CALIBRATION
- ODriveModule.AXIS_STATE_CLOSED_LOOP_CONTROL
Axis states
- ODriveModule.CONTROL_MODE_VOLTAGE_CONTROL
- ODriveModule.CONTROL_MODE_TORQUE_CONTROL
- ODriveModule.CONTROL_MODE_VELOCITY_CONTROL
- ODriveModule.CONTROL_MODE_POSITION_CONTROL
Control modes