Encoders
Overview
All encoders supported by ODrive require that you do some sort of encoder calibration. This requires the following:
Selecting an encoder and mounting it to your motor, refer to Known and Supported Encoders to make sure your hardware is compatible.
Connecting the pins to the ODrive
Each encoder types will require different connections, please refer to the relevent section below for instructions specific to your encoder type.
Information about the ODrive’s GPIO can be found on the pinout page.
Configure the ODrive
Set
<axis>.config.load_encoder
and<axis>.config.commutation_encoder
to the appropriateEncoderId
.Additional configuration may be necessary, please refer to the relevent section below.
Encoder calibration
The calibration procedure may vary depending on the type of encoder, please refer to the relevent section below.
During calibration the rotor must be allowed to rotate without any biased load during startup. That means mass and weak friction loads are fine, but gravity or spring loads are not okay.
The current limit during encoder calibration is set with
<axis>.config.calibration_lockin.current
. The default value is enough for most applications, but can be increased for larger motors or loads.
Save the settings in the odrive for correct bootup by running
<odrv>.save_configuration()
.
Verify Calibration
After the calibration procedure has completed, verify that procedure_result
is equal to ProcedureResult.SUCCESS
.
This can be done easily from odrivetool
by running dump_errors(odrv)
, or from the GUI by inspecting the ODrive icon in the bottom left corner.
If instead, you see ProcedureResult.BUSY
then the calibration has not yet completed, check again after a couple more seconds.
Onboard Encoder
ODrive Pro and ODrive S1 both come with an integrated magnetic encoder. To use this encoder, a diametric neodymium magnet must be mounted to the end of the motor shaft. For general purpose use we recommend the 8996 by Radial Magnets, if there is a chance that the magnet could get hot we suggest using the 9049 variant. If neither of these are suitable, any diametric neodymium magnet with a diameter ≥ 4mm and thickness ≥ 2.5mm will work.
When mounting, a 1mm gap between the onboard encoder and the magnet is ideal.
All parameters pertaining to the onboard encoder can be found at
<odrv>.onboard_encoder0
.Both
<axis>.config.load_encoder
and<axis>.config.commutation_encoder
should be set toEncoderId.ONBOARD_ENCODER0
.Calibrate by running
Incremental Encoders
Incremental encoders have two signal connections A, B, an optional index signal Z, and will require power and ground from the ODrive.
Encoder
ODrive
Vcc
5V
A
ENC0_A
B
ENC0_B
Z (optional)
ENC0_Z
GND
GND
Refer to the pinout page for more details.
All parameters pertaining to an incremental encoder can be found at
<odrv>.inc_encoder0
.Proper configuration requires the Count Per Revolution (CPR), this should be found in the encoder datasheet.
<odrv>.inc_encoder0.config.cpr
= <CPR><odrv>.inc_encoder0.config.enabled
= TrueBoth
<axis>.config.load_encoder
and<axis>.config.commutation_encoder
should be set toEncoderId.INC_ENCODER0
.Calibrate by running
Note
If the index (Z) signal is not used, ENCODER_OFFSET_CALIBRATION
must be run after every reboot before CLOSED_LOOP_CONTROL
can be used.
If you would like to automate this process at startup, set <axis>.config.startup_encoder_offset_calibration
to True.
Index Search
If you have an encoder with an index (Z) signal, you can avoid running ENCODER_OFFSET_CALIBRATION
on every startup, and instead use the index signal to re-sync the encoder to a stored calibration.
This process is only required once, it is recommended that you mechanically disengage the motor from anything other than the encoder, so that it can spin freely.
Identify the index signal pin number N on the ODrive, for Pro this is 7 (G07) and for S1 this is 10 (G10).
Configure the
commutation_mapper
:<odrv>.config.gpio<N>_mode = GpioMode.DIGITAL
<axis>.commutation_mapper.config.index_gpio
= <N><axis>.commutation_mapper.config.use_index_gpio
= TrueConfigure the
pos_vel_mapper
: (optional, only required for absolute position setpoints)Run
<axis>.requested_state
=AxisState.ENCODER_INDEX_SEARCH
. This will make the motor turn in one direction until it finds the encoder index.
Note
If you are using the index (Z) signal, ENCODER_INDEX_SEARCH
must be run after every reboot before CLOSED_LOOP_CONTROL
can be used.
If you would like to automate this process at startup, set <axis>.config.startup_encoder_index_search
to True.
Save the configuration with
<odrv>.save_configuration()
.
Reversing Index Search
Sometimes you would like the index search to only happen in a particular direction (the reverse of the default). Instead of swapping the motor leads, you can ensure that the following three values are negative:
Important
Your motor should find the same rotational position when the ODrive performs an index search if the index signal is working properly.
This means that the motor should spin, and stop at the same position if you have set <axis>.config.startup_encoder_index_search
so the search starts on reboot,
or if you request ENCODER_INDEX_SEARCH
after reboot.
You can test this. Send the <odrv>.reboot()
command, and while it’s rebooting turn your motor, then make sure the motor returns back to the correct position each time when it comes out of reboot.
Try this procedure a couple of times to be sure.
Experiencing problems?
Noise on the index signal (Z) can have unexpected consequences, watch out for the common warning signs:
difficulty requesting
ENCODER_OFFSET_CALIBRATION
, where your calibration sequence may not completestrange behavior after performing
<odrv>.save_configuration()
and<odrv>.reboot()
when performing an index_search, the motor does not return to the same position each time.
One easy step that might fix this is to attach a 22nF-47nF capacitor between the ENC1_Z pin and GND.
RS-485 Encoders
RS-485 encoder signals use a differential pair A, B and will require power and ground from the ODrive.
Encoder
ODrive
Vcc
5V
A
RS485_A
B
RS485_B
GND
GND
Important
At this time, only the CUI AMT21 series of encoders is support by the RS-485 interface
All parameters pertaining to an AMT21 encoder can be found at
<odrv>.amt21_encoder_group0
.To enable, set
...config.enable
to TrueBoth
<axis>.config.load_encoder
and<axis>.config.commutation_encoder
should be set toEncoderId.INC_ENCODER0
.Calibrate by running
Hall Effect Encoders
Hall effect encoders have three signal connections A, B, and C, and will require power and ground from the ODrive.
Encoder
ODrive
Vcc
5V
A
HALL_A
B
HALL_B
C
HALL_C
GND
GND
Refer to the pinout page for more details.
All parameters pertaining to a hall effect encoder can be found at
<odrv>.hall_encoder0
.The hall feedback has 6 states for every pole pair (PP) in the motor, therefore the resolution is equal to 6 * PP. Since this is lower than most incremental or absolute encoders, we need to reduce the
encoder_bandwidth
to get smoother velocity estimates.Both
<axis>.config.load_encoder
and<axis>.config.commutation_encoder
should be set toEncoderId.HALL_ENCODER0
.Calibration requires two steps, first
ENCODER_HALL_POLARITY_CALIBRATION
thenENCODER_OFFSET_CALIBRATION
. This will automatically determine the order and polarity of the hall signals.
Important
Due to the relatively low resolution of hall effect encoders, ODrive Robotics recommends a different encoder type for position control or applications requiring high performance at low speeds.
SPI Encoders
SPI encoders usually measure an absolute angle, which means you don’t need to repeat the encoder calibration after every ODrive reboot.
Some of these chips come with evaluation boards that can simplify mounting the chips to your motor. For our purposes if you are using an evaluation board you should select the settings for 3.3v.
Note
The AMT23x family has a hardware bug that causes them to not properly tristate the MISO line. To use them with ODrive, there are two workarounds. One is to sequence power to the encoder a second or two after the ODrive recieves power. This allows 1 encoder to be used without issue. Another solution is to add a tristate buffer, such as the 74AHC1G125SE, on the MISO line between the ODrive and each AMT23x encoder. Tie the enable pin on the buffer to the CS line for the respective encoder. This allows for more than one AMT23x encoder, or one AMT23x and another SPI encoder, to be used at the same time.
The SPI interface has three required and one optonal signal connections: clock (SCK), data (MISO), chip select (nCS), and optionally data out (MOSI). Additionally the encoder will require power and ground from the ODrive.
Encoder
ODrive
Vcc
3.3V
SCK
SPI_SCK
MISO/DATA
SPI_MISO
MOSI (optional)
SPI_MOSI
nCS
SPI_nCS
GND
GND
Note
If you want to save a wire with AMS encoders, you can also connect the encoder’s MOSI to the encoder’s Vcc instead.
All parameters pertaining to an SPI encoder can be found at
<odrv>.spi_encoder0
.set
<odrv>.spi_encoder0.config.mode
to the correctSpiEncoderMode
for the encoder.
Important
Only the following modes are supported at this time:
CUI protocol: Compatible with the AMT23xx family (AMT232A, AMT232B, AMT233A, AMT233B).
AMS protocol: Compatible with AS5047P and AS5048A.
Identify the chip select pin number N on the ODrive, for Pro this is 17 (G17+) and for S1 this is 12 (G12).
Both
<axis>.config.load_encoder
and<axis>.config.commutation_encoder
should be set toEncoderId.SPI_ENCODER0
.Calibrate by running
Note
If you are having calibration problems, make sure that your magnet is centered on the axis of rotation on the motor. Also make sure that your magnet height is within range of the spec sheet.
Known and Supported Encoders
Key
✓: Supported
E: Experimental
S: Coming Soon
X: Not Supported
Encoder |
Interface |
Mode |
Pro |
S1 |
---|---|---|---|---|
Onboard Magnetic |
internal |
✓ |
✓ |
|
Incremental |
A,B,(Z) |
✓ |
✓ |
|
Incremental |
Sin,Cos |
X |
X |
|
Hall Effect Sensor |
A,B,C |
✓ |
✓ |
|
CUI AMT21 |
RS485 |
✓ |
✓ |
|
CUI AMT23 |
SPI |
✓ |
✓ |
|
AMS (AS5047p, AS5048A) |
SPI |
✓ |
✓ |
|
MA732, MA702 |
SPI |
E |
E |
|
Broadcom-AEAT-9922 |
SPI |
E |
E |
|
RLS (Orbis 14-bit only) |
SPI |
E |
E |
|
EnData/Tamagawa/RLS-AksIM |
~ |
X |
X |
Be sure to check the ODrive Encoder Spreadsheet.
Encoder Noise
Noise is found in all circuits, life is just about figuring out if it is preventing your system from working. Lots of users have no problems with noise interfering with their ODrive operation, others will tell you “I’ve been using the same encoder as you with no problems”. Power to ‘em, that may be true, but it doesn’t mean it will work for you. If you are concerned about noise, there are several possible sources:
Importantly, encoder wires may be too close to motor wires, avoid overlap as much as possible
Long wires between encoder and ODrive
Use of ribbon cable
The following might mitigate noise problems. Use shielded cable, or use twisted pairs, where one side of each twisted pair is tied to ground and the other side is tied to your signal. If you are using SPI, use a 20-50 ohm resistor in series on CLK, which is more susceptible noise.