Skip to content

Conversation

@Copper280z
Copy link
Contributor

@Copper280z Copper280z commented Feb 22, 2025

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.

const float delta_angle = current_angle - prev_angle;

// floating point equality checks are bad, so instead we check that the angle change is very small
if (fabsf(delta_angle) < 1e-8f) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we want to check for angles larger than this, rather than smaller?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, whoops! Should be fixed now.

@runger1101001
Copy link
Member

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?

@Copper280z
Copy link
Contributor Author

Merging after this release is totally fine by me!

@runger1101001 runger1101001 merged commit e8f777e into simplefoc:dev Jul 28, 2025
22 checks passed
@runger1101001
Copy link
Member

Merged, as we have now released version 2.3.5

@runger1101001 runger1101001 added this to the 2.4.0_Release milestone Jul 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants