How to set encoder.pos_estimate to 0


Hi, I am trying to set the zero position of my system, using current sensing. My approach is as follows

  1. Run odrive in velocity control mode in a fixed low velocity
  2. Monitor the current at the same time. There is a mechanical end limit and when the motors reach there, the current increases.
  1. when the current increases above a threshold, set the encoder.pos_estimate to 0

I could do steps 1& 2 and can detect the instant when current rises above a threshold. I understand that the encoder.pos_estimate can only be read. I tried using encoder.set_linear_count(0), but somehow calling it rotates the motor incrementally in a direction, without any change reflected in encoder.pos_estimate

Am I doing it the right way. Is there any way to set the encoder.pos_estimate to zero at an arbitrary position through a command. Any help would be appreciated


If you are using a motor with an encoder then it may be simpler to use the velocity error to detect an end stop than the motor current. See the velocity loop in the docs.

pos_estimate is always referenced to where the motor was at startup as far as I know. However, you can cause the motor to stay in a fixed position after hitting the end when back in position control mode stop by having <axis>.controller.pos_setpoint be equal to your current position after the end stop is detected.


You want encoder.set_linear_count(0)