pimoroni-pico icon indicating copy to clipboard operation
pimoroni-pico copied to clipboard

Motor2040 encoders intermittently return infinite speed readings in micropython

Open tomoinn opened this issue 2 years ago • 11 comments

In micropython, calling the capture() method on an Encoder can sometimes return an infinite speed in the radians_per_second field. This is obviously a little inconvenient when using it to drive the input of a PID controller. Most readings are sensible, but after normally around 30s of use I get one that comes back as infinity.

I'd suggest it would be better to either return None and document that this might happen, or return the previous valid value. As it is I've done the latter in my code, but it took a long time to track down!

tomoinn avatar Nov 15 '22 16:11 tomoinn