Skip to content

Commit

Permalink
Make vel_ramp safer by limiting the vel_setpoint to vel_limit
Browse files Browse the repository at this point in the history
  • Loading branch information
Wetmelon committed Sep 22, 2022
1 parent f64c075 commit e88fa10
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Firmware/MotorControl/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,13 @@ bool Controller::update() {

}

// Never command a setpoint beyond its limit
if(config_.enable_vel_limit) {
vel_setpoint_ = std::clamp(vel_setpoint_, -config_.vel_limit, config_.vel_limit);
}
const float Tlim = axis_->motor_.max_available_torque();
torque_setpoint_ = std::clamp(torque_setpoint_, -Tlim, Tlim);

// Position control
// TODO Decide if we want to use encoder or pll position here
float gain_scheduling_multiplier = 1.0f;
Expand Down Expand Up @@ -373,7 +380,6 @@ bool Controller::update() {

// Torque limiting
bool limited = false;
float Tlim = axis_->motor_.max_available_torque();
if (torque > Tlim) {
limited = true;
torque = Tlim;
Expand Down

0 comments on commit e88fa10

Please sign in to comment.