diff --git a/src/BLDCMotor.cpp b/src/BLDCMotor.cpp index 1292f3a0..e39397e4 100644 --- a/src/BLDCMotor.cpp +++ b/src/BLDCMotor.cpp @@ -75,6 +75,15 @@ int BLDCMotor::init() { // constrain voltage for sensor alignment if(voltage_sensor_align > voltage_limit) voltage_sensor_align = voltage_limit; + // update the controller limits + if (_isset(phase_resistance) && _isset(phase_inductance)){ + PID_current_d.P = phase_inductance * DEF_CURR_BANDWIDTH * _2PI; + PID_current_d.I = PID_current_d.P * phase_resistance / phase_inductance; + + PID_current_q.P = phase_inductance * DEF_CURR_BANDWIDTH * _2PI; + PID_current_q.I = PID_current_q.P * phase_resistance /phase_inductance; + } + // update limits in the motor controllers updateCurrentLimit(current_limit); updateVoltageLimit(voltage_limit); diff --git a/src/StepperMotor.cpp b/src/StepperMotor.cpp index 36dcaf5a..b657c169 100644 --- a/src/StepperMotor.cpp +++ b/src/StepperMotor.cpp @@ -47,7 +47,16 @@ int StepperMotor::init() { // constrain voltage for sensor alignment if(voltage_sensor_align > voltage_limit) voltage_sensor_align = voltage_limit; - + + + if (_isset(phase_resistance) && _isset(phase_inductance)){ + PID_current_d.P = phase_inductance * DEF_CURR_BANDWIDTH * _2PI; + PID_current_d.I = PID_current_d.P * phase_resistance / phase_inductance; + + PID_current_q.P = phase_inductance * DEF_CURR_BANDWIDTH * _2PI; + PID_current_q.I = PID_current_q.P * phase_resistance /phase_inductance; + } + // update limits in the motor controllers updateCurrentLimit(current_limit); updateVoltageLimit(voltage_limit); diff --git a/src/common/defaults.h b/src/common/defaults.h index ac57daa1..0bf851a7 100644 --- a/src/common/defaults.h +++ b/src/common/defaults.h @@ -18,6 +18,7 @@ #define DEF_PID_CURR_RAMP 1000.0f //!< default PID controller voltage ramp value #define DEF_PID_CURR_LIMIT (DEF_POWER_SUPPLY) //!< default PID controller voltage limit #define DEF_CURR_FILTER_Tf 0.01f //!< default velocity filter time constant +#define DEF_CURR_BANDWIDTH 300.0f //!< current bandwidth #else // for stm32, due, teensy, esp32 and similar #define DEF_PID_CURR_P 3 //!< default PID controller P value @@ -26,6 +27,7 @@ #define DEF_PID_CURR_RAMP 0 //!< default PID controller voltage ramp value #define DEF_PID_CURR_LIMIT (DEF_POWER_SUPPLY) //!< default PID controller voltage limit #define DEF_CURR_FILTER_Tf 0.005f //!< default currnet filter time constant +#define DEF_CURR_BANDWIDTH 300.0f //!< current bandwidth #endif // default current limit values #define DEF_CURRENT_LIM 2.0f //!< 2Amps current limit by default