Closed slimcdk closed 6 days ago
Correct, false stalls detections can occur if the parameters hasn't been dialed in for the specific application, motor etc. The values I provided are for my setup which runs without false triggers.
Good catch! I must have been sleeply when I submitted this as it appear that I have submitted parts of my testing config and not a final one 🙈 Sorry!
I have a corrected version of the encoder logic, but yours is a little cleaner to read, so I won't bother including mine. Instead of setting the homed position on boot, it might actually be better to save the value to flash and restore it after boot. The homed position can't be trusted before an actual homing is completed.
Thanks for taking a look at it!
Working configs are now in examples for ESPHome, so I'll close this PR
Think my previous problem was partially caused by the stall detection being triggered when the motor slowed down. This caused the home position to be reset.
I also found a problem with your handling of wrap around on the as5600 sensor. The encoder_diff calculation was only correct in one direction. I replaced the lambda with the following and seems to be working correctly now:
I also added the following to the on_boot so that home is the start position:
I imagine your idea of not having this was so that it could home itself on boot using the stall guard? However this does not work for all use cases (such as when using a large gear ratio or when blinds can move past the open/close position)