This is due to the fact that we are measuring time in microseconds and when you are reading the sensor only ( without foc loop) this can be very crude.
So therefore for the motion control we have a low pass filter to deal with this in the BLDCMotor class and a bit more similar to what you’ve done ( and more recommended) is to downsample the motion control and only calculate the velocity each N calls of sensor angle call.
This gives a bit more time in between velocity calls. And you can set it with:
motor.motion_downsample = 5; // 0 - disabled
If you’re using only the sensor itself without the rest of the library, the best choice would be to add the delay function or not to call the getVelocity in the each loop.
Are you sure motor.motion_downsample gives more time in between velocity calls? I’m asking because changing this parameter doesn’t seem to get me the expected results. Moreover, looking at the code, I’m not sure I understand how it could work (see lines 304 and 309):
You are absolutely right. The shaftVelocity call should be after the downsampling snippet. Or better said the downsampling snippet should be the first thing in the move function.
This has been corrected by @runger in the dev branch. (as well as many other improvements such as floating point error).