I have an implementation of reset position working, but I would like to get some recommendations and advice if there is a better way of doing this. My use case of "reset position" is being able to set the motor position to any arbitrary value.
For example, the sequence to reset the position to 0 is:
- Disable closed loop - Set ENC_IN_CONF regulation_modus = 0
- Set VMAX = 0
- Set XACTUAL = MSCNT
- Set XTARGET = MSCNT
- Set ENC_POS = MSCNT
- Cache MSCNT value
- Enable closed loop - Set ENC_IN_CONF regulation_modus = 1
My understanding from the datasheet is that XACTUAL must match the corresponding MSCNT microstep position in closed loop mode. So in the above example, the positions are reset to MSCNT. And to retrieve the "real" position, we read from XACTUAL and then offset it will the original MSCNT value it was reset with, i.e. XACTUAL - cached_MSCNT.
Here is a concrete example for how this works:
- Initial positions: XACTUAL=1000, XTARGET=1000, ENC_POS=1000, MSCNT=512
- Reset position to 0 (also cache MSCNT value 512 as offset): XACTUAL=512, XTARGET=512, ENC_POS=512, MSCNT=512
- Read current position: XACTUAL - 512 = 512 - 512 = 0
- Move to position 1000: Set XTARGET = 1000 + 512 = 1512
The handling of the MSCNT offset is a bit convoluted, is there a better way of doing this?
Corrected some info
[edited by: IsaacC at 5:22 AM (GMT -4) on 16 Sep 2024]