Analog Input
Overview
Analog inputs can be used to measure voltages between 0 and 3.3V.
This voltage can either be read manually using <odrv>.get_adc_voltage(N) or can be mapped to an endpoint such as input_pos, input_vel, or input_torque.
To see which GPIO pins support analog inputs, look for analog input in the pinout (Pro, S1).
To set a GPIO pin to analog input mode, set <odrv>.config.gpio(N)_mode to GpioMode.ANALOG_IN.
A reboot (<odrv>.save_configuration()) is required for this to take effect.
Endpoint Mapping
Mapping an analog input to an endpoint (such as input_pos, input_vel or input_torque) works in the same way as PWM input mapping, except that the configuration is done under <odrv>.config.gpio(N)_analog_mapping instead of <odrv>.config.gpio(N)_pwm_mapping.
Refer to RC PWM Configuration for details.
Velocity Control Example
As an example, we’ll configure the axis with a velocity setpoint from 0 to 5 turn/s, controlled by the analog input voltage. This assumes your ODrive is connected to odrivetool as odrv0. In the GUI, this can be set up graphically in the configurator, so this guide is only relevant for when using odrivetool.
Make sure you’re able to control the axis0 velocity by writing to
odrv0.axis0.controller.input_vel, and that the velocity controller is properly tund. If you need help with this follow the getting started guide.If you want to control your ODrive with the analog input without using anything else to activate the ODrive, you can configure the ODrive such that it automatically enters closed loop at startup. See here for more information.
Select an analog-capable pin (see the Pro, S1 pinout pages for details).
In
odrivetool, configure the analog input mapping, where N is the GPIO pin number selected (e.g. if pin G15 on ODrive Pro is used for analog input,gpio(N)would be replaced withgpio15)odrv0.config.gpio(N)_mode = GpioMode.ANALOG_IN odrv0.config.gpio(N)_analog_mapping.min = 0 odrv0.config.gpio(N)_analog_mapping.max = 5 odrv0.config.gpio(N)_analog_mapping.endpoint = odrv0.axis0.controller._input_vel_property
Note
you can disable the input by setting
odrv0.config.gpio(N)_analog_mapping.endpoint = NoneSave the configuration and reboot
odrv0.save_configuration()
Now, once the ODrive is powered and running in closed loop control (whether manually commanded in the GUI/
odrivetoolor set to enter closed loop control on startup), the velocity setpoint will be set by the analog input.