|
| 1 | + |
| 2 | +ODriveModule |
| 3 | +============ |
| 4 | + |
| 5 | +.. include:: ../refs/module.odrive.ref |
| 6 | + |
| 7 | +ODrive is a high-performance servo motor drive module launched by M5Stack, based on the open source motion control solution ODrive. |
| 8 | + |
| 9 | +Support the following products: |
| 10 | + |
| 11 | +|ODriveModule| |
| 12 | + |
| 13 | +Micropython Example:: |
| 14 | + |
| 15 | + import os, sys, io |
| 16 | + import M5 |
| 17 | + from M5 import * |
| 18 | + from module import ODriveModule |
| 19 | + drive = ODriveModule(port=(13,5)) |
| 20 | + drive.get_vbus_voltage() |
| 21 | + drive.set_velocity(10) |
| 22 | + drive.set_current(5) |
| 23 | + drive.set_control_mode(ODriveModule.CONTROL_MODE_POSITION_CONTROL) |
| 24 | + drive.set_position(1000) |
| 25 | + |
| 26 | + |
| 27 | +UIFLOW2 Example: |
| 28 | + |
| 29 | + |example.png| |
| 30 | + |
| 31 | +.. only:: builder_html |
| 32 | + |
| 33 | + |core_odrive_example.m5f2| |
| 34 | + |
| 35 | + |
| 36 | +class ODriveModule |
| 37 | +------------------ |
| 38 | + |
| 39 | +Constructors |
| 40 | +------------ |
| 41 | + |
| 42 | +.. class:: ODriveModule(id, port) |
| 43 | + |
| 44 | + Initialize the ODriveModule. |
| 45 | + |
| 46 | + :param int id: |
| 47 | + :param port: |
| 48 | + |
| 49 | + UIFLOW2: |
| 50 | + |
| 51 | + |init.png| |
| 52 | + |
| 53 | + |
| 54 | +Methods |
| 55 | +------- |
| 56 | + |
| 57 | +.. method:: ODriveModule.set_position(position, velocity_feedforward, current_feedforward) |
| 58 | + |
| 59 | + Set the target position with optional feedforward values. |
| 60 | + |
| 61 | + :param position: The target position in counts or radians, depending on the configuration. |
| 62 | + :param float velocity_feedforward: The feedforward velocity in counts/s or radians/s to assist the controller. |
| 63 | + :param float current_feedforward: The feedforward current in amperes to assist the controller. |
| 64 | + |
| 65 | + UIFLOW2: |
| 66 | + |
| 67 | + |set_position.png| |
| 68 | + |
| 69 | +.. method:: ODriveModule.set_velocity(velocity, current_feedforward) |
| 70 | + |
| 71 | + Set the target velocity with optional current feedforward. |
| 72 | + |
| 73 | + :param velocity: The target velocity in counts/s or radians/s. |
| 74 | + :param float current_feedforward: The feedforward current in amperes to assist the controller. |
| 75 | + |
| 76 | + UIFLOW2: |
| 77 | + |
| 78 | + |set_velocity.png| |
| 79 | + |
| 80 | +.. method:: ODriveModule.set_current(current) |
| 81 | + |
| 82 | + Set the target current. |
| 83 | + |
| 84 | + :param current: The target current in amperes for torque control. |
| 85 | + |
| 86 | + UIFLOW2: |
| 87 | + |
| 88 | + |set_current.png| |
| 89 | + |
| 90 | +.. method:: ODriveModule.set_gain(pos_gain, vel_gain, vel_integrator_gain) |
| 91 | + |
| 92 | + |
| 93 | + :param pos_gain: |
| 94 | + :param vel_gain: |
| 95 | + :param vel_integrator_gain: |
| 96 | + |
| 97 | + UIFLOW2: |
| 98 | + |
| 99 | + |set_gain.png| |
| 100 | + |
| 101 | +.. method:: ODriveModule.set_control_mode(mode) |
| 102 | + |
| 103 | + Set the control mode of the controller. |
| 104 | + |
| 105 | + :param mode: The control mode. |
| 106 | + |
| 107 | + UIFLOW2: |
| 108 | + |
| 109 | + |set_control_mode.png| |
| 110 | + |
| 111 | +.. method:: ODriveModule.set_control_input_pos(pos) |
| 112 | + |
| 113 | + Set the control input position for the controller. |
| 114 | + |
| 115 | + :param pos: The desired input position in counts or radians for position control. |
| 116 | + |
| 117 | + UIFLOW2: |
| 118 | + |
| 119 | + |set_control_input_pos.png| |
| 120 | + |
| 121 | +.. method:: ODriveModule.trapezoidal_move(position) |
| 122 | + |
| 123 | + Perform a trapezoidal move to the given position. |
| 124 | + |
| 125 | + :param position: The target position in counts or radians to move to using a trapezoidal velocity profile. |
| 126 | + |
| 127 | + UIFLOW2: |
| 128 | + |
| 129 | + |trapezoidal_move.png| |
| 130 | + |
| 131 | +.. method:: ODriveModule.run_state(requested_state, timeout) |
| 132 | + |
| 133 | + Run the axis to the requested state within a timeout period. |
| 134 | + |
| 135 | + :param requested_state: The desired axis state to transition to, using the AXIS_STATE_* constants. |
| 136 | + :param timeout: Timeout in milliseconds to wait for the axis to reach the requested state. |
| 137 | + |
| 138 | + UIFLOW2: |
| 139 | + |
| 140 | + |run_state.png| |
| 141 | + |
| 142 | +.. method:: ODriveModule.get_velocity() |
| 143 | + |
| 144 | + Get the estimated velocity of the motor. |
| 145 | + |
| 146 | + :return (float): The estimated velocity in counts/s or radians/s. |
| 147 | + |
| 148 | + UIFLOW2: |
| 149 | + |
| 150 | + |get_velocity.png| |
| 151 | + |
| 152 | +.. method:: ODriveModule.get_vbus_voltage() |
| 153 | + |
| 154 | + Get the measured bus voltage. |
| 155 | + |
| 156 | + :return (float): The bus voltage in volts. |
| 157 | + |
| 158 | + UIFLOW2: |
| 159 | + |
| 160 | + |get_vbus_voltage.png| |
| 161 | + |
| 162 | +.. method:: ODriveModule.get_phase_current() |
| 163 | + |
| 164 | + Get the measured phase current of the motor. |
| 165 | + |
| 166 | + :return (float): The phase current in amperes. |
| 167 | + |
| 168 | + UIFLOW2: |
| 169 | + |
| 170 | + |get_phase_current.png| |
| 171 | + |
| 172 | +.. method:: ODriveModule.get_bus_current() |
| 173 | + |
| 174 | + Get the bus current drawn by the motor. |
| 175 | + |
| 176 | + :return (float): The bus current in amperes. |
| 177 | + |
| 178 | + UIFLOW2: |
| 179 | + |
| 180 | + |get_bus_current.png| |
| 181 | + |
| 182 | +.. method:: ODriveModule.get_encoder_shadow_count() |
| 183 | + |
| 184 | + Get the encoder's shadow count, which is an internal counter. |
| 185 | + |
| 186 | + :return (int): The shadow count as an integer value. |
| 187 | + |
| 188 | + UIFLOW2: |
| 189 | + |
| 190 | + |get_encoder_shadow_count.png| |
| 191 | + |
| 192 | +.. method:: ODriveModule.get_encoder_pos_estimate() |
| 193 | + |
| 194 | + Get the estimated position from the encoder. |
| 195 | + |
| 196 | + :return (float): The estimated position in counts or radians. |
| 197 | + |
| 198 | + UIFLOW2: |
| 199 | + |
| 200 | + |get_encoder_pos_estimate.png| |
| 201 | + |
| 202 | +.. method:: ODriveModule.get_motor_temp() |
| 203 | + |
| 204 | + Get the temperature of the motor thermistor. |
| 205 | + |
| 206 | + :return (float): The motor temperature in degrees Celsius. |
| 207 | + |
| 208 | + UIFLOW2: |
| 209 | + |
| 210 | + |get_motor_temp.png| |
| 211 | + |
| 212 | +.. method:: ODriveModule.erase_config() |
| 213 | + |
| 214 | + Erase the current configuration settings. |
| 215 | + |
| 216 | + |
| 217 | + UIFLOW2: |
| 218 | + |
| 219 | + |erase_config.png| |
| 220 | + |
| 221 | +.. method:: ODriveModule.save_config() |
| 222 | + |
| 223 | + Save the current configuration to non-volatile memory. |
| 224 | + |
| 225 | + |
| 226 | + UIFLOW2: |
| 227 | + |
| 228 | + |save_config.png| |
| 229 | + |
| 230 | +.. method:: ODriveModule.reboot() |
| 231 | + |
| 232 | + Reboot the ODrive device. |
| 233 | + |
| 234 | + |
| 235 | + UIFLOW2: |
| 236 | + |
| 237 | + |reboot.png| |
| 238 | + |
| 239 | +.. method:: ODriveModule.set_default_config() |
| 240 | + |
| 241 | + Set the default configuration parameters. |
| 242 | + |
| 243 | + |
| 244 | + UIFLOW2: |
| 245 | + |
| 246 | + |set_default_config.png| |
| 247 | + |
| 248 | +.. method:: ODriveModule.check_error() |
| 249 | + |
| 250 | + Check for any errors in the system components. |
| 251 | + |
| 252 | + |
| 253 | + UIFLOW2: |
| 254 | + |
| 255 | + |check_error.png| |
| 256 | + |
| 257 | +.. method:: ODriveModule.read_flush() |
| 258 | + |
| 259 | + Flush the UART read buffer to clear any residual data. |
| 260 | + |
| 261 | + |
| 262 | + UIFLOW2: |
| 263 | + |
| 264 | + |read_flush.png| |
| 265 | + |
| 266 | +.. method:: ODriveModule.read_string() |
| 267 | + |
| 268 | + Read a string terminated by a newline character from the device. |
| 269 | + |
| 270 | + :return (str): The string read from the device, excluding the newline character. |
| 271 | + |
| 272 | + UIFLOW2: |
| 273 | + |
| 274 | + |read_string.png| |
| 275 | + |
| 276 | +.. method:: ODriveModule.read_float() |
| 277 | + |
| 278 | + Read a floating-point value from the device. |
| 279 | + |
| 280 | + :return (float): The float value read from the device; returns 0.0 if parsing fails. |
| 281 | + |
| 282 | + UIFLOW2: |
| 283 | + |
| 284 | + |read_float.png| |
| 285 | + |
| 286 | +.. method:: ODriveModule.read_int() |
| 287 | + |
| 288 | + Read an integer value from the device. |
| 289 | + |
| 290 | + :return (int): The integer value read from the device; returns 0 if parsing fails. |
| 291 | + |
| 292 | + UIFLOW2: |
| 293 | + |
| 294 | + |read_int.png| |
| 295 | + |
| 296 | +.. method:: ODriveModule.write_to_device(data) |
| 297 | + |
| 298 | + Write a command string to the device via UART. |
| 299 | + |
| 300 | + :param data: The command string to send to the device, ending with a newline character. |
| 301 | + |
| 302 | + UIFLOW2: |
| 303 | + |
| 304 | + |write_to_device.png| |
| 305 | + |
| 306 | +.. method:: ODriveModule.write_config(config, value) |
| 307 | + |
| 308 | + Write a configuration parameter to the device. |
| 309 | + |
| 310 | + :param config: The configuration key as a string, e.g., 'axis0.controller.config.pos_gain'. |
| 311 | + :param value: The value to set for the configuration parameter; can be a float or integer. |
| 312 | + |
| 313 | + UIFLOW2: |
| 314 | + |
| 315 | + |write_config.png| |
| 316 | + |
| 317 | +.. method:: ODriveModule.read_config_int(config) |
| 318 | + |
| 319 | + Read an integer configuration parameter from the device. |
| 320 | + |
| 321 | + :return (int): The integer value of the specified configuration parameter; returns 0 if parsing fails. |
| 322 | + :param config: The configuration key as a string, e.g., 'axis0.encoder.error'. |
| 323 | + |
| 324 | + UIFLOW2: |
| 325 | + |
| 326 | + |read_config_int.png| |
| 327 | + |
| 328 | +.. method:: ODriveModule.read_config_float(config) |
| 329 | + |
| 330 | + Read a floating-point configuration parameter from the device. |
| 331 | + |
| 332 | + :return (float): The float value of the specified configuration parameter; returns 0.0 if parsing fails. |
| 333 | + :param config: The configuration key as a string, e.g., 'axis0.motor_thermistor.temperature'. |
| 334 | + |
| 335 | + UIFLOW2: |
| 336 | + |
| 337 | + |read_config_float.png| |
| 338 | + |
| 339 | + |
| 340 | + |
| 341 | +Constants |
| 342 | +--------- |
| 343 | + |
| 344 | +.. data:: ODriveModule.AXIS_STATE_UNDEFINED |
| 345 | +.. data:: ODriveModule.AXIS_STATE_IDLE |
| 346 | +.. data:: ODriveModule.AXIS_STATE_STARTUP_SEQUENCE |
| 347 | +.. data:: ODriveModule.AXIS_STATE_FULL_CALIBRATION_SEQUENCE |
| 348 | +.. data:: ODriveModule.AXIS_STATE_MOTOR_CALIBRATION |
| 349 | +.. data:: ODriveModule.AXIS_STATE_SENSORLESS_CONTROL |
| 350 | +.. data:: ODriveModule.AXIS_STATE_ENCODER_INDEX_SEARCH |
| 351 | +.. data:: ODriveModule.AXIS_STATE_ENCODER_OFFSET_CALIBRATION |
| 352 | +.. data:: ODriveModule.AXIS_STATE_CLOSED_LOOP_CONTROL |
| 353 | + |
| 354 | + Axis states |
| 355 | + |
| 356 | + |
| 357 | +.. data:: ODriveModule.CONTROL_MODE_VOLTAGE_CONTROL |
| 358 | +.. data:: ODriveModule.CONTROL_MODE_TORQUE_CONTROL |
| 359 | +.. data:: ODriveModule.CONTROL_MODE_VELOCITY_CONTROL |
| 360 | +.. data:: ODriveModule.CONTROL_MODE_POSITION_CONTROL |
| 361 | + |
| 362 | + Control modes |
| 363 | + |
| 364 | + |
0 commit comments