bldc
bldc copied to clipboard
[Utils] Streamline `utils_saturate_vector_2d()`
There was no need to do the sqrt() unless the absolute magnitude is exceeded.
Passes unit tests but shouldn't be merged until #459 is merged.
It looks like the worst case, when saturation is needed, will still take the same amount of time. Also, sqrtf is quite fast on the FPU.
For optimizations like this one it would be good to set up a way to profile how much difference they make. Maybe this can be done by running a test on the STM32 with some build option and plot the result in VESC Tool.