Use cs.Kp, cs.Ki and cs.Kd from ConfigurationStore.
This commit is contained in:
parent
f2ae3fb1f7
commit
54bcc8aa52
|
|
@ -124,7 +124,7 @@ void Config_PrintSettings(uint8_t level)
|
||||||
);
|
);
|
||||||
#ifdef PIDTEMP
|
#ifdef PIDTEMP
|
||||||
printf_P(PSTR("%SPID settings:\n%S M301 P%.2f I%.2f D%.2f\n"),
|
printf_P(PSTR("%SPID settings:\n%S M301 P%.2f I%.2f D%.2f\n"),
|
||||||
echomagic, echomagic, Kp, unscalePID_i(Ki), unscalePID_d(Kd));
|
echomagic, echomagic, cs.Kp, unscalePID_i(cs.Ki), unscalePID_d(cs.Kd));
|
||||||
#endif
|
#endif
|
||||||
#ifdef PIDTEMPBED
|
#ifdef PIDTEMPBED
|
||||||
printf_P(PSTR("%SPID heatbed settings:\n%S M304 P%.2f I%.2f D%.2f\n"),
|
printf_P(PSTR("%SPID heatbed settings:\n%S M304 P%.2f I%.2f D%.2f\n"),
|
||||||
|
|
|
||||||
|
|
@ -6212,9 +6212,9 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
|
||||||
#ifdef PIDTEMP
|
#ifdef PIDTEMP
|
||||||
case 301: // M301
|
case 301: // M301
|
||||||
{
|
{
|
||||||
if(code_seen('P')) Kp = code_value();
|
if(code_seen('P')) cs.Kp = code_value();
|
||||||
if(code_seen('I')) Ki = scalePID_i(code_value());
|
if(code_seen('I')) cs.Ki = scalePID_i(code_value());
|
||||||
if(code_seen('D')) Kd = scalePID_d(code_value());
|
if(code_seen('D')) cs.Kd = scalePID_d(code_value());
|
||||||
|
|
||||||
#ifdef PID_ADD_EXTRUSION_RATE
|
#ifdef PID_ADD_EXTRUSION_RATE
|
||||||
if(code_seen('C')) Kc = code_value();
|
if(code_seen('C')) Kc = code_value();
|
||||||
|
|
@ -6223,11 +6223,11 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
|
||||||
updatePID();
|
updatePID();
|
||||||
SERIAL_PROTOCOLRPGM(_T(MSG_OK));
|
SERIAL_PROTOCOLRPGM(_T(MSG_OK));
|
||||||
SERIAL_PROTOCOL(" p:");
|
SERIAL_PROTOCOL(" p:");
|
||||||
SERIAL_PROTOCOL(Kp);
|
SERIAL_PROTOCOL(cs.Kp);
|
||||||
SERIAL_PROTOCOL(" i:");
|
SERIAL_PROTOCOL(" i:");
|
||||||
SERIAL_PROTOCOL(unscalePID_i(Ki));
|
SERIAL_PROTOCOL(unscalePID_i(cs.Ki));
|
||||||
SERIAL_PROTOCOL(" d:");
|
SERIAL_PROTOCOL(" d:");
|
||||||
SERIAL_PROTOCOL(unscalePID_d(Kd));
|
SERIAL_PROTOCOL(unscalePID_d(cs.Kd));
|
||||||
#ifdef PID_ADD_EXTRUSION_RATE
|
#ifdef PID_ADD_EXTRUSION_RATE
|
||||||
SERIAL_PROTOCOL(" c:");
|
SERIAL_PROTOCOL(" c:");
|
||||||
//Kc does not have scaling applied above, or in resetting defaults
|
//Kc does not have scaling applied above, or in resetting defaults
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@
|
||||||
|
|
||||||
#include <avr/wdt.h>
|
#include <avr/wdt.h>
|
||||||
#include "adc.h"
|
#include "adc.h"
|
||||||
|
#include "ConfigurationStore.h"
|
||||||
|
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
|
|
@ -79,9 +80,6 @@ float current_temperature_bed = 0.0;
|
||||||
float _Kp, _Ki, _Kd;
|
float _Kp, _Ki, _Kd;
|
||||||
int pid_cycle, pid_number_of_cycles;
|
int pid_cycle, pid_number_of_cycles;
|
||||||
bool pid_tuning_finished = false;
|
bool pid_tuning_finished = false;
|
||||||
float Kp=DEFAULT_Kp;
|
|
||||||
float Ki=(DEFAULT_Ki*PID_dT);
|
|
||||||
float Kd=(DEFAULT_Kd/PID_dT);
|
|
||||||
#ifdef PID_ADD_EXTRUSION_RATE
|
#ifdef PID_ADD_EXTRUSION_RATE
|
||||||
float Kc=DEFAULT_Kc;
|
float Kc=DEFAULT_Kc;
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -422,7 +420,7 @@ void updatePID()
|
||||||
{
|
{
|
||||||
#ifdef PIDTEMP
|
#ifdef PIDTEMP
|
||||||
for(int e = 0; e < EXTRUDERS; e++) {
|
for(int e = 0; e < EXTRUDERS; e++) {
|
||||||
temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / Ki;
|
temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / cs.Ki;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef PIDTEMPBED
|
#ifdef PIDTEMPBED
|
||||||
|
|
@ -638,14 +636,14 @@ void manage_heater()
|
||||||
temp_iState[e] = 0.0;
|
temp_iState[e] = 0.0;
|
||||||
pid_reset[e] = false;
|
pid_reset[e] = false;
|
||||||
}
|
}
|
||||||
pTerm[e] = Kp * pid_error[e];
|
pTerm[e] = cs.Kp * pid_error[e];
|
||||||
temp_iState[e] += pid_error[e];
|
temp_iState[e] += pid_error[e];
|
||||||
temp_iState[e] = constrain(temp_iState[e], temp_iState_min[e], temp_iState_max[e]);
|
temp_iState[e] = constrain(temp_iState[e], temp_iState_min[e], temp_iState_max[e]);
|
||||||
iTerm[e] = Ki * temp_iState[e];
|
iTerm[e] = cs.Ki * temp_iState[e];
|
||||||
|
|
||||||
//K1 defined in Configuration.h in the PID settings
|
//K1 defined in Configuration.h in the PID settings
|
||||||
#define K2 (1.0-K1)
|
#define K2 (1.0-K1)
|
||||||
dTerm[e] = (Kd * (pid_input - temp_dState[e]))*K2 + (K1 * dTerm[e]);
|
dTerm[e] = (cs.Kd * (pid_input - temp_dState[e]))*K2 + (K1 * dTerm[e]);
|
||||||
pid_output = pTerm[e] + iTerm[e] - dTerm[e];
|
pid_output = pTerm[e] + iTerm[e] - dTerm[e];
|
||||||
if (pid_output > PID_MAX) {
|
if (pid_output > PID_MAX) {
|
||||||
if (pid_error[e] > 0 ) temp_iState[e] -= pid_error[e]; // conditional un-integration
|
if (pid_error[e] > 0 ) temp_iState[e] -= pid_error[e]; // conditional un-integration
|
||||||
|
|
@ -1040,7 +1038,7 @@ void tp_init()
|
||||||
maxttemp[e] = maxttemp[0];
|
maxttemp[e] = maxttemp[0];
|
||||||
#ifdef PIDTEMP
|
#ifdef PIDTEMP
|
||||||
temp_iState_min[e] = 0.0;
|
temp_iState_min[e] = 0.0;
|
||||||
temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / Ki;
|
temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / cs.Ki;
|
||||||
#endif //PIDTEMP
|
#endif //PIDTEMP
|
||||||
#ifdef PIDTEMPBED
|
#ifdef PIDTEMPBED
|
||||||
temp_iState_min_bed = 0.0;
|
temp_iState_min_bed = 0.0;
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ extern int current_voltage_raw_bed;
|
||||||
|
|
||||||
#ifdef PIDTEMP
|
#ifdef PIDTEMP
|
||||||
extern int pid_cycle, pid_number_of_cycles;
|
extern int pid_cycle, pid_number_of_cycles;
|
||||||
extern float Kp,Ki,Kd,Kc,_Kp,_Ki,_Kd;
|
extern float Kc,_Kp,_Ki,_Kd;
|
||||||
extern bool pid_tuning_finished;
|
extern bool pid_tuning_finished;
|
||||||
float scalePID_i(float i);
|
float scalePID_i(float i);
|
||||||
float scalePID_d(float d);
|
float scalePID_d(float d);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue