Add unit tests for current_vel_limit (failing)

This commit is contained in:
Paul Guenette
2019-06-19 22:36:40 +02:00
4 changed files with 60 additions and 11 deletions
+21 -1
View File
@@ -218,7 +218,7 @@ bool Controller::update(float pos_estimate, float vel_estimate, float* current_s
if (vel_des < -vel_lim) vel_des = -vel_lim;
// Check for overspeed fault (done in this module (controller) for cohesion with vel_lim)
if (config_.vel_limit_tolerance > 0.0f) { // 0.0f to disable
if (config_.vel_limit_tolerance > 0.0f) { // 0.0f to disable
if (fabsf(vel_estimate) > config_.vel_limit_tolerance * vel_lim) {
set_error(ERROR_OVERSPEED);
return false;
@@ -255,6 +255,26 @@ bool Controller::update(float pos_estimate, float vel_estimate, float* current_s
Iq = -Ilim;
}
// Velocity limiting in current mode
if (config_.control_mode < CTRL_MODE_VELOCITY_CONTROL && config_.vel_limit > 0.0f && config_.vel_gain > 0.0f) {
float Imax = (config_.vel_limit - fabsf(vel_estimate)) * config_.vel_gain;
if (Iq > 0 && Iq > Imax) {
limited = true;
if (Imax > 0) {
Iq = Imax;
} else {
Iq = 0;
}
} else if (Iq < 0 && Iq < -Imax) {
limited = true;
if (Imax > 0) {
Iq = -Imax;
} else {
Iq = 0;
}
}
}
// Velocity integrator (behaviour dependent on limiting)
if (config_.control_mode < CTRL_MODE_VELOCITY_CONTROL) {
// reset integral if not in use