Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/common/base_classes/FOCMotor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,17 @@ void FOCMotor::loopFOC() {
SIMPLEFOC_MOTOR_ERROR("no torque control selected!");
break;
}
// optionally limit the magnitude of the dq voltage vector
// d and q are scaled together, so the direction of the voltage vector is preserved
if(limit_voltage_vector){
float magnitude_sq = voltage.q*voltage.q + voltage.d*voltage.d;
float limit_sq = voltage_limit*voltage_limit;
if(magnitude_sq > limit_sq){
float scale = voltage_limit / sqrtf(magnitude_sq);
voltage.q *= scale;
voltage.d *= scale;
}
}
// set the phase voltage - FOC heart function :)
setPhaseVoltage(voltage.q, voltage.d, electrical_angle);
}
Expand Down
1 change: 1 addition & 0 deletions src/common/base_classes/FOCMotor.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ class FOCMotor

// limiting variables
float voltage_limit; //!< Voltage limiting variable - global limit
bool limit_voltage_vector = false; //!< if true, the d and q voltages are scaled together so that the voltage vector magnitude does not exceed voltage_limit (default: false, d and q are limited independently)
float current_limit; //!< Current limiting variable - global limit
float velocity_limit; //!< Velocity limiting variable - global limit

Expand Down