There are quite a few people with the exact same use-case and question. The feature to handle this is planned and not yet implemented. I can write down the steps on how we plan to do this, in case anyone here wishes to implement this themselves (to make it happen faster ).
Index pulse encoder reset feature
We need a simple interrupt service routine that responds to the index pulse and when fired:
- resets the encoder register to 0
- sets a “index found” variable
- turns off
- disables the interrupt.
This feature should start disabled at power-on.
During commissioning of the drive, you would use the axis without load, or tilt the assembly such that there is no gravity load. Either:
- Activate index pulse reset, spin motor by hand until it is found.
- Calibrate motor, after calibration activate index pulse reset, enable motor, and then spin the motor: It will by virtue of the
enable_motor turn-off in the index pulse IRQ, be automatically de-energized when the index is found.
Then run motor calibration (again), with a properly zeroed encoder. This will yield a value for
encoder_offset. Read out this value (over USB, or UART, etc). Write the value to
encoder_offset in the code, recompile and flash.
Startup against gravity
We activate the index reset IRQ. We then have two options:
- Rotate the axis by hand until index is found.
- Use “lock-in drive”, which is to slowly rotate a large current (probably the continous current rating of the motor) in the direction pre-defined to be against gravity. This is very inefficient, but should be able to move the axis. This drive-mode should quit when the
enable_motor disables from the IRQ. If we don’t want the axis to drop to the mechanical stop at this point we could jump straight into normal control.