Check out the ODrive Encoder Guide.
All encoder types that are currently supported require the ODrive to do some sort of encoder calibration at every startup before you can run the motor control. Take this into account when designing your application.
During encoder offset 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.
<axis>.requested_state = AXIS_STATE_ENCODER_OFFSET_CALIBRATION Enter.
To verify everything went well, check the following variables:
<axis>.errorshould be 0.
<axis>.encoder.config.offset- This should print a number, like -326 or 1364.
<axis>.motor.config.direction- This should print 1 or -1.
If you have an encoder with an index (Z) signal, you may avoid having to do the offset calibration on every startup, and instead use the index signal to re-sync the encoder to a stored calibration.
Below are the steps to do the one-time calibration and configuration. Note that you can follow these steps with one motor at a time, or all motors together, as you wish.
<axis>.requested_state = AXIS_STATE_ENCODER_INDEX_SEARCH. This will make the motor turn in one direction until it finds the encoder index.
Trueto confirm that the offset is valid with respect to the index pulse.
<axis>.requested_state = AXIS_STATE_ENCODER_INDEX_SEARCHon every bootup.
Trueto save the current motor calibration and avoid doing it again on bootup.
That’s it, now on every reboot the motor will turn in one direction until it finds the encoder index.