Further reduce the complexity of the limitVel algorithm

This commit is contained in:
Paul Guenette
2019-06-21 21:52:10 +02:00
parent 1cbbf4127c
commit 7e569a2e1d
2 changed files with 11 additions and 11 deletions
+3 -3
View File
@@ -237,9 +237,9 @@ TEST_SUITE("velLimiter") {
#include <algorithm>
using doctest::Approx;
auto limitVel(float vel_limit, float vel_estimate, float vel_gain, float Iq, float current_lim = 50.0f) {
float Imax = std::min((vel_limit - vel_estimate) * vel_gain, current_lim);
float Imin = std::max((-vel_limit - vel_estimate) * vel_gain, -current_lim);
auto limitVel(float vel_limit, float vel_estimate, float vel_gain, float Iq) {
float Imax = (vel_limit - vel_estimate) * vel_gain;
float Imin = (-vel_limit - vel_estimate) * vel_gain;
return std::clamp(Iq, Imin, Imax);
}