Made changes reflecting PR comments.

Added torque_ramp_rate to controller config.
Changed INPUT_MODE_CURRENT_RAMP to INPUT_MODE_TORQUE_RAMP for controller input mode enum.
Torque limits and current limits are now observed seperately. Torque limit is in the controller, current limit is in the motor object.
Fixed torque -> current calculation in motor_update to handle ACIM motors.
This commit is contained in:
pjohnson
2020-06-17 13:15:36 -04:00
parent d78119e29f
commit ceabd24582
9 changed files with 35 additions and 32 deletions
+17 -10
View File
@@ -177,19 +177,19 @@ bool Motor::do_checks() {
return true;
}
float Motor::effective_torque_lim() {
float Motor::effective_current_lim() {
// Configured limit
float torque_lim = config_.torque_lim;
float current_lim = config_.current_lim;
// Hardware limit
if (axis_->motor_.config_.motor_type == Motor::MOTOR_TYPE_GIMBAL) {
torque_lim = std::min(torque_lim, 0.98f*one_by_sqrt3*vbus_voltage); //gimbal motor is voltage control, not Nm or A
current_lim = std::min(current_lim, 0.98f*one_by_sqrt3*vbus_voltage); //gimbal motor is voltage control
} else {
torque_lim = std::min(torque_lim, axis_->motor_.current_control_.max_allowed_torque);
current_lim = std::min(current_lim, axis_->motor_.current_control_.max_allowed_current);
}
// Thermal limit
torque_lim = std::min(torque_lim, thermal_torque_lim_);
current_lim = std::min(current_lim, thermal_current_lim_);
return torque_lim;
return current_lim;
}
void Motor::log_timing(TimingLog_t log_idx) {
@@ -359,7 +359,7 @@ bool Motor::FOC_current(float Id_des, float Iq_des, float I_phase, float pwm_pha
ictrl.Id_measured += ictrl.I_measured_report_filter_k * (Id - ictrl.Id_measured);
// Check for violation of current limit
float I_trip = (effective_torque_lim() + config_.torque_lim_margin) / config_.torque_constant;
float I_trip = effective_current_lim() + config_.current_lim_margin;
if (SQ(Id) + SQ(Iq) > SQ(I_trip)) {
set_error(ERROR_CURRENT_LIMIT_VIOLATION);
return false;
@@ -441,13 +441,20 @@ bool Motor::FOC_current(float Id_des, float Iq_des, float I_phase, float pwm_pha
bool Motor::update(float torque_setpoint, float phase, float phase_vel) {
float current_setpoint = torque_setpoint / config_.torque_constant;
current_setpoint *= config_.direction;
float current_setpoint;
phase *= config_.direction;
phase_vel *= config_.direction;
if (config_.motor_type == MOTOR_TYPE_ACIM) {
current_setpoint = torque_setpoint / (config_.torque_constant * fmax(current_control_.acim_rotor_flux, config_.acim_gain_min_flux));
}
else {
current_setpoint = torque_setpoint / config_.torque_constant;
}
current_setpoint *= config_.direction;
// TODO: 2-norm vs independent clamping (current could be sqrt(2) bigger)
float ilim = effective_torque_lim() / config_.torque_constant;
float ilim = effective_current_lim();
float id = std::clamp(current_control_.Id_setpoint, -ilim, ilim);
float iq = std::clamp(current_setpoint, -ilim, ilim);