Skip to content

Commit

Permalink
Autotuning
Browse files Browse the repository at this point in the history
  • Loading branch information
Candas1 committed Jul 21, 2024
1 parent 2de948c commit 26fbea0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/BLDCMotor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,16 @@ int BLDCMotor::init() {
// current control loop controls voltage
PID_current_q.limit = voltage_limit;
PID_current_d.limit = 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;
}
}

if(_isset(phase_resistance) || torque_controller != TorqueControlType::voltage){
// velocity control loop controls current
PID_velocity.limit = current_limit;
Expand Down
15 changes: 15 additions & 0 deletions src/StepperMotor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ int StepperMotor::init() {
// constrain voltage for sensor alignment
if(voltage_sensor_align > voltage_limit) voltage_sensor_align = voltage_limit;

// update the controller limits
if(current_sense){
// current control loop controls voltage
PID_current_q.limit = voltage_limit;
PID_current_d.limit = 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 the controller limits
if(_isset(phase_resistance)){
// velocity control loop controls current
Expand Down
2 changes: 2 additions & 0 deletions src/common/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 26fbea0

Please sign in to comment.