Implement better algorithm

This commit is contained in:
Paul Guenette
2019-06-21 16:55:15 +02:00
parent 0481241a8b
commit 4c623f2068
+3 -6
View File
@@ -116,12 +116,9 @@ void Controller::update_filter_gains() {
namespace {
float limitVel(float vel_limit, float vel_estimate, float vel_gain, float Iq, float current_lim) {
float Imax = (vel_limit - std::abs(vel_estimate)) * vel_gain;
if (vel_estimate > 0.0f) {
return std::clamp(Iq, -current_lim, Imax);
} else {
return std::clamp(Iq, -Imax, current_lim);
}
float Imax = std::min((vel_limit - vel_estimate) * vel_gain, current_lim);
float Imin = std::max((-vel_limit - vel_estimate) * vel_gain, -current_lim);
return std::clamp(Iq, Imin, Imax);
}
} // namespace