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:

ODriveModule

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:

example.png

core_odrive_example.m5f2

class ODriveModule

Constructors

class ODriveModule(id, port)

Initialize the ODriveModule.

Parameters:
  • id (int)

  • port

UIFLOW2:

init.png

Methods

ODriveModule.set_position(position, velocity_feedforward, current_feedforward)

Set the target position with optional feedforward values.

Parameters:
  • position – The target position in counts or radians, depending on the configuration.

  • velocity_feedforward (float) – The feedforward velocity in counts/s or radians/s to assist the controller.

  • current_feedforward (float) – The feedforward current in amperes to assist the controller.

UIFLOW2:

set_position.png

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:

set_velocity.png

ODriveModule.set_current(current)

Set the target current.

Parameters:

current – The target current in amperes for torque control.

UIFLOW2:

set_current.png

ODriveModule.set_gain(pos_gain, vel_gain, vel_integrator_gain)
Parameters:
  • pos_gain

  • vel_gain

  • vel_integrator_gain

UIFLOW2:

set_gain.png

ODriveModule.set_control_mode(mode)

Set the control mode of the controller.

Parameters:

mode – The control mode.

UIFLOW2:

set_control_mode.png

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:

set_control_input_pos.png

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:

trapezoidal_move.png

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:

run_state.png

ODriveModule.get_velocity()

Get the estimated velocity of the motor.

Return (float):

The estimated velocity in counts/s or radians/s.

UIFLOW2:

get_velocity.png

ODriveModule.get_vbus_voltage()

Get the measured bus voltage.

Return (float):

The bus voltage in volts.

UIFLOW2:

get_vbus_voltage.png

ODriveModule.get_phase_current()

Get the measured phase current of the motor.

Return (float):

The phase current in amperes.

UIFLOW2:

get_phase_current.png

ODriveModule.get_bus_current()

Get the bus current drawn by the motor.

Return (float):

The bus current in amperes.

UIFLOW2:

get_bus_current.png

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:

get_encoder_shadow_count.png

ODriveModule.get_encoder_pos_estimate()

Get the estimated position from the encoder.

Return (float):

The estimated position in counts or radians.

UIFLOW2:

get_encoder_pos_estimate.png

ODriveModule.get_motor_temp()

Get the temperature of the motor thermistor.

Return (float):

The motor temperature in degrees Celsius.

UIFLOW2:

get_motor_temp.png

ODriveModule.erase_config()

Erase the current configuration settings.

UIFLOW2:

erase_config.png

ODriveModule.save_config()

Save the current configuration to non-volatile memory.

UIFLOW2:

save_config.png

ODriveModule.reboot()

Reboot the ODrive device.

UIFLOW2:

reboot.png

ODriveModule.set_default_config()

Set the default configuration parameters.

UIFLOW2:

set_default_config.png

ODriveModule.check_error()

Check for any errors in the system components.

UIFLOW2:

check_error.png

ODriveModule.read_flush()

Flush the UART read buffer to clear any residual data.

UIFLOW2:

read_flush.png

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:

read_string.png

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:

read_float.png

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:

read_int.png

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:

write_to_device.png

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:

write_config.png

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:

read_config_int.png

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:

read_config_float.png

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_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