Skip to content
Draft
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
9 changes: 9 additions & 0 deletions src/BLDCMotor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 10 additions & 1 deletion src/StepperMotor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
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