Arduino-FOC icon indicating copy to clipboard operation
Arduino-FOC copied to clipboard

Velocity Calculation rework

Open Copper280z opened this issue 11 months ago • 2 comments

Seeing the relatively frequent questions and problems associated with noisy velocity measurements on the discord server, what do you think about a change like this to the velocity calculation?

The idea being that currently when we make a call to getVelocity(), if the angle change is zero then we get a zero velocity, if we have a non-zero angle change it appears as a very high velocity because all of that change is accounted for in one cycle. Because our loop can often run many cycles between angle changes. This shows up (unfiltered) as a series of zero velocity measurements with large single sample spikes, this is obviously nonphysical. The current fix to this is to heavily filter the velocity signal, which introduces a large phase loss in the control system.

This change only updates the velocity if an angle change is observed and otherwise reports the previous velocity. This results in a closer approximation to a continuous signal.

One degenerate case that is not handled is if the motor comes to a complete and total stop, the velocity will not be reported as zero. Practically, this doesn't seem like a problem because the reported velocity will be very small, very few motors will come to an absolute stop for any long period of time, and a floating point zero value (vs very small non-zero) isn't actually very useful.

This change is currently untested on hardware.

Copper280z avatar Feb 22 '25 17:02 Copper280z

Hey, thanks a lot for contributing this. I think it is a good idea, as you have mentioned the unstable velocity signal is a real pain for many people. This seems like a very reasonable approach, but I'd like to merge it to the dev branch and try it a bit before releasing. So if its ok with you I would merge it immediately after doing the next release?

runger1101001 avatar Feb 24 '25 11:02 runger1101001

Merging after this release is totally fine by me!

Copper280z avatar Feb 26 '25 12:02 Copper280z

Merged, as we have now released version 2.3.5

runger1101001 avatar Jul 28 '25 19:07 runger1101001