Commit 03152a21 authored by MagoKimbra's avatar MagoKimbra

Add PID_EXTRUSION_RATE

parent c9fc2819
### Version 4.2.0
* Add PID Extrusion Rate Kc in percent.
* New configuration systems (Now you can create a separate file with all configuration and use it in you FW update)
* New namings for file
* Added more documentation inside configuration file
......
......@@ -169,11 +169,16 @@
// is more then PID_FUNCTIONAL_RANGE then the PID will be shut off and the heater will be set to min/max.
#define PID_FUNCTIONAL_RANGE 10 // degC
#define PID_INTEGRAL_DRIVE_MAX PID_MAX // Limit for the integral term
// this adds an experimental additional term to the heating power, proportional to the extrusion speed.
// if Kc is chosen well, the additional required power due to increased melting should be compensated.
//#define PID_ADD_EXTRUSION_RATE
#define LPQ_MAX_LEN 50
// HotEnd{HE0,HE1,HE2,HE3}
#define DEFAULT_Kp {40, 40, 40, 40} // Kp for E0, E1, E2, E3
#define DEFAULT_Ki {07, 07, 07, 07} // Ki for E0, E1, E2, E3
#define DEFAULT_Kd {60, 60, 60, 60} // Kd for E0, E1, E2, E3
#define DEFAULT_Kc {100, 100, 100, 100} // heating power = Kc * (e_speed)
/***********************************************************************/
......
......@@ -195,7 +195,7 @@
* M250 - Set LCD contrast C<contrast value> (value 0..63)
* M280 - Set servo position absolute. P: servo index, S: angle or microseconds
* M300 - Play beep sound S<frequency Hz> P<duration ms>
* M301 - Set PID parameters P I and D
* M301 - Set PID parameters P I D and C
* M302 - Allow cold extrudes, or set the minimum extrude S<temperature>.
* M303 - PID relay autotune S<temperature> sets the target temperature. (default target temperature = 150C)
* M304 - Set bed PID parameters P I and D
......@@ -489,6 +489,10 @@ unsigned long printer_usage_seconds;
boolean chdkActive = false;
#endif
#if ENABLED(PIDTEMP) && ENABLED(PID_ADD_EXTRUSION_RATE)
int lpq_len = 20;
#endif
//===========================================================================
//================================ Functions ================================
//===========================================================================
......@@ -5899,25 +5903,44 @@ inline void gcode_M226() {
#if ENABLED(PIDTEMP)
/**
* M301: Set PID parameters P I D
* M301: Set PID parameters P I D (and optionally C, L)
*
* P[float] Kp term
* I[float] Ki term (unscaled)
* D[float] Kd term (unscaled)
*
* With PID_ADD_EXTRUSION_RATE:
*
* C[float] Kc term
* L[float] LPQ length
*/
inline void gcode_M301() {
// multi-hotend PID patch: M301 updates or prints a single hotend's PID values
// default behaviour (omitting E parameter) is to update for hotend 0 only
int e = code_seen('E') ? code_value() : 0; // hotend being updated
int e = code_seen('H') ? code_value() : 0; // hotend being updated
if (e < HOTENDS) { // catch bad input value
if (code_seen('P')) PID_PARAM(Kp, e) = code_value();
if (code_seen('I')) PID_PARAM(Ki, e) = scalePID_i(code_value());
if (code_seen('D')) PID_PARAM(Kd, e) = scalePID_d(code_value());
#if ENABLED(PID_ADD_EXTRUSION_RATE)
if (code_seen('C')) PID_PARAM(Kc, e) = code_value();
if (code_seen('L')) lpq_len = code_value();
NOMORE(lpq_len, LPQ_MAX_LEN);
#endif
updatePID();
ECHO_SMV(OK, "e:", e);
ECHO_MV(" p:", PID_PARAM(Kp, e));
ECHO_MV(" i:", unscalePID_i(PID_PARAM(Ki, e)));
ECHO_EMV(" d:", unscalePID_d(PID_PARAM(Kd, e)));
ECHO_MV(" d:", unscalePID_d(PID_PARAM(Kd, e)));
#if ENABLED(PID_ADD_EXTRUSION_RATE)
ECHO_MV(" c:", PID_PARAM(Kc, e));
#endif
ECHO_E;
}
else {
ECHO_LM(ER, MSG_INVALID_EXTRUDER);
......
......@@ -10,7 +10,6 @@ void idle(bool ignore_stepper_queue = false);
void manage_inactivity(bool ignore_stepper_queue=false);
void FlushSerialRequestResend();
void ok_to_send();
......@@ -172,6 +171,10 @@ extern int fanSpeed;
extern void IDLE_OOZING_retract(bool retracting);
#endif
#if ENABLED(PIDTEMP) && ENABLED(PID_ADD_EXTRUSION_RATE)
extern int lpq_len;
#endif
#if ENABLED(FWRETRACT)
extern bool autoretract_enabled;
extern bool retracted[EXTRUDERS]; // extruder[n].retracted
......
......@@ -29,10 +29,10 @@
*
*/
#define EEPROM_VERSION "V24"
#define EEPROM_VERSION "V25"
/**
* V24 EEPROM Layout:
* V25 EEPROM Layout:
*
* ver
* M92 XYZ E0 ... axis_steps_per_unit X,Y,Z,E0 ... (per extruder)
......@@ -77,10 +77,11 @@
* M145 S2 F gumPreheatFanSpeed
*
* PIDTEMP:
* M301 E0 PID Kp[0], Ki[0], Kd[0]
* M301 E1 PID Kp[1], Ki[1], Kd[1]
* M301 E2 PID Kp[2], Ki[2], Kd[2]
* M301 E3 PID Kp[3], Ki[3], Kd[3]
* M301 E0 PIDC Kp[0], Ki[0], Kd[0], Kc[0]
* M301 E1 PIDC Kp[1], Ki[1], Kd[1], Kc[1]
* M301 E2 PIDC Kp[2], Ki[2], Kd[2], Kc[2]
* M301 E3 PIDC Kp[3], Ki[3], Kd[3], Kc[3]
* M301 L lpq_len
*
* PIDTEMPBED:
* M304 PID bedKp, bedKi, bedKd
......@@ -199,13 +200,19 @@ void Config_StoreSettings() {
EEPROM_WRITE_VAR(i, gumPreheatFanSpeed);
#if ENABLED(PIDTEMP)
for (int e = 0; e < HOTENDS; e++) {
EEPROM_WRITE_VAR(i, PID_PARAM(Kp, e));
EEPROM_WRITE_VAR(i, PID_PARAM(Ki, e));
EEPROM_WRITE_VAR(i, PID_PARAM(Kd, e));
for (int h = 0; h < HOTENDS; h++) {
EEPROM_WRITE_VAR(i, PID_PARAM(Kp, h));
EEPROM_WRITE_VAR(i, PID_PARAM(Ki, h));
EEPROM_WRITE_VAR(i, PID_PARAM(Kd, h));
EEPROM_WRITE_VAR(i, PID_PARAM(Kc, h));
}
#endif
#if DISABLED(PID_ADD_EXTRUSION_RATE)
int lpq_len = 20;
#endif
EEPROM_WRITE_VAR(i, lpq_len);
#if ENABLED(PIDTEMPBED)
EEPROM_WRITE_VAR(i, bedKp);
EEPROM_WRITE_VAR(i, bedKi);
......@@ -336,13 +343,19 @@ void Config_RetrieveSettings() {
EEPROM_READ_VAR(i, gumPreheatFanSpeed);
#if ENABLED(PIDTEMP)
for (int8_t e = 0; e < HOTENDS; e++) {
EEPROM_READ_VAR(i, PID_PARAM(Kp, e));
EEPROM_READ_VAR(i, PID_PARAM(Ki, e));
EEPROM_READ_VAR(i, PID_PARAM(Kd, e));
for (int8_t h = 0; h < HOTENDS; h++) {
EEPROM_READ_VAR(i, PID_PARAM(Kp, h));
EEPROM_READ_VAR(i, PID_PARAM(Ki, h));
EEPROM_READ_VAR(i, PID_PARAM(Kd, h));
EEPROM_READ_VAR(i, PID_PARAM(Kc, h));
}
#endif // PIDTEMP
#if DISABLED(PID_ADD_EXTRUSION_RATE)
int lpq_len;
#endif
EEPROM_READ_VAR(i, lpq_len);
#if ENABLED(PIDTEMPBED)
EEPROM_READ_VAR(i, bedKp);
EEPROM_READ_VAR(i, bedKi);
......@@ -420,14 +433,15 @@ void Config_ResetDefault() {
float tmp6[] = DEFAULT_Kp;
float tmp7[] = DEFAULT_Ki;
float tmp8[] = DEFAULT_Kd;
float tmp9[] = DEFAULT_Kc;
#endif // PIDTEMP
#if ENABLED(HOTEND_OFFSET_X) && ENABLED(HOTEND_OFFSET_Y)
float tmp9[] = HOTEND_OFFSET_X;
float tmp10[] = HOTEND_OFFSET_Y;
float tmp10[] = HOTEND_OFFSET_X;
float tmp11[] = HOTEND_OFFSET_Y;
#else
float tmp9[] = {0};
float tmp10[] = {0};
float tmp11[] = {0};
#endif
for (int8_t i = 0; i < 3 + EXTRUDERS; i++) {
......@@ -459,14 +473,14 @@ void Config_ResetDefault() {
else
max_e_jerk[i] = tmp5[max_i - 1];
#if HOTENDS > 1
max_i = sizeof(tmp9) / sizeof(*tmp9);
max_i = sizeof(tmp10) / sizeof(*tmp10);
if(i < max_i)
hotend_offset[X_AXIS][i] = tmp9[i];
hotend_offset[X_AXIS][i] = tmp10[i];
else
hotend_offset[X_AXIS][i] = 0;
max_i = sizeof(tmp10) / sizeof(*tmp10);
max_i = sizeof(tmp11) / sizeof(*tmp11);
if(i < max_i)
hotend_offset[Y_AXIS][i] = tmp10[i];
hotend_offset[Y_AXIS][i] = tmp11[i];
else
hotend_offset[Y_AXIS][i] = 0;
#endif // HOTENDS > 1
......@@ -535,11 +549,15 @@ void Config_ResetDefault() {
#endif
#if ENABLED(PIDTEMP)
for (int8_t e = 0; e < HOTENDS; e++) {
Kp[e] = tmp6[e];
Ki[e] = scalePID_i(tmp7[e]);
Kd[e] = scalePID_d(tmp8[e]);
for (int8_t h = 0; h < HOTENDS; h++) {
Kp[h] = tmp6[h];
Ki[h] = scalePID_i(tmp7[h]);
Kd[h] = scalePID_d(tmp8[h]);
Kc[h] = tmp9[h];
}
#if ENABLED(PID_ADD_EXTRUSION_RATE)
lpq_len = 20; // default last-position-queue size
#endif
// call updatePID (similar to when we have processed M301)
updatePID();
#endif // PIDTEMP
......@@ -752,12 +770,19 @@ void Config_ResetDefault() {
ECHO_LM(DB, "PID settings:");
}
#if ENABLED(PIDTEMP)
for (int e = 0; e < HOTENDS; e++) {
ECHO_SMV(DB, " M301 E", e);
ECHO_MV(" P", PID_PARAM(Kp, e));
ECHO_MV(" I", unscalePID_i(PID_PARAM(Ki, e)));
ECHO_EMV(" D", unscalePID_d(PID_PARAM(Kd, e)));
}
for (int h = 0; h < HOTENDS; h++) {
ECHO_SMV(DB, " M301 H", h);
ECHO_MV(" P", PID_PARAM(Kp, h));
ECHO_MV(" I", unscalePID_i(PID_PARAM(Ki, h)));
ECHO_MV(" D", unscalePID_d(PID_PARAM(Kd, h)));
#if ENABLED(PID_ADD_EXTRUSION_RATE)
ECHO_MV(" C", PID_PARAM(Kc, h));
#endif
ECHO_E;
}
#if ENABLED(PID_ADD_EXTRUSION_RATE)
ECHO_SMV(DB, " M301 L", lpq_len);
#endif
#endif
#if ENABLED(PIDTEMPBED)
ECHO_SMV(DB, " M304 P", bedKp); // for compatibility with hosts, only echos values for E0
......
......@@ -179,6 +179,7 @@
#define MSG_KP " Kp: "
#define MSG_KI " Ki: "
#define MSG_KD " Kd: "
#define MSG_KC " Kc: "
#define MSG_B "B:"
#define MSG_T "T:"
#define MSG_AT "@:"
......@@ -191,6 +192,7 @@
#define MSG_PID_DEBUG_PTERM " pTerm "
#define MSG_PID_DEBUG_ITERM " iTerm "
#define MSG_PID_DEBUG_DTERM " dTerm "
#define MSG_PID_DEBUG_CTERM " cTerm "
#define MSG_INVALID_EXTRUDER_NUM " - Invalid extruder number !"
#define MSG_HEATER_BED "bed"
......
This diff is collapsed.
......@@ -62,12 +62,12 @@ extern float current_temperature_bed;
#endif
#if ENABLED(PIDTEMP)
extern float Kp[HOTENDS], Ki[HOTENDS], Kd[HOTENDS];
extern float Kp[HOTENDS], Ki[HOTENDS], Kd[HOTENDS], Kc[HOTENDS];
#define PID_PARAM(param, e) param[e] // use macro to point to array value
#endif
#if ENABLED(PIDTEMPBED)
extern float bedKp,bedKi,bedKd;
extern float bedKp, bedKi, bedKd;
#endif
#if ENABLED(PIDTEMP) || ENABLED(PIDTEMPBED)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment