mirror of
https://github.com/odriverobotics/ODrive.git
synced 2026-09-21 15:34:33 +08:00
Add unit tests for current_vel_limit (failing)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user