Nice work! That is better doing the spike filter with purely relative checks rather than needing a threshold. It does introduce latency since it will typically return the second-to-last reading, whereas the threshold method will typically return the latest value, but since we’re taking multiple samples per frame, the one returned will still be plenty recent.
Also good that you didn’t have to increase the sample rate since it would eat up a lot of CPU cycles.
Lowpass filtering the readings will cause the angle to lag behind reality by the filter time constant, which could become significant at high speed. If you’ll be spending much time at high speed, it could potentially be corrected using SmoothingSensor, by setting sensor.angle_prev_ts = _micros()*1e-6f - filter.Tf; (you’ll have to edit Sensor.h to make angle_prev_ts public).
When applying the lowpass, don’t forget to multiply by dt. The way you’re doing it here, the effective time constant will be different depending on the loop rate, which will be much faster during this test than when running loopFOC and move. You could just use the LowPassFilter class since it already handles dt measurement. It’s a waste of CPU cycles measuring it separately in every instance, but not terribly much. There is a proposal to fix that, but doesn’t seem to have gotten any traction [FEATURE] Calculate dt for Loopfoc and move only once · Issue #325 · simplefoc/Arduino-FOC · GitHub