Commit a8e1e08b authored by MagoKimbra's avatar MagoKimbra

Update

parent 433d7898
...@@ -215,10 +215,13 @@ ...@@ -215,10 +215,13 @@
//============================= PID Settings ================================ //============================= PID Settings ================================
//=========================================================================== //===========================================================================
// PID Tuning Guide here: http://reprap.org/wiki/PID_Tuning // PID Tuning Guide here: http://reprap.org/wiki/PID_Tuning
// Comment the following line to disable PID and enable bang-bang.
#define PIDTEMP
#define BANG_MAX 255 // limits current to nozzle while in bang-bang mode; 255=full current #define BANG_MAX 255 // limits current to nozzle while in bang-bang mode; 255=full current
#define PID_MAX BANG_MAX // limits current to nozzle while PID is active (see PID_FUNCTIONAL_RANGE below); 255=full current #define PID_MAX BANG_MAX // limits current to nozzle while PID is active (see PID_FUNCTIONAL_RANGE below); 255=full current
#define K1 0.95 // Smoothing factor within the PID
#define MAX_OVERSHOOT_PID_AUTOTUNE 20 // Max valor for overshoot autotune
// Comment the following line to disable PID and enable bang-bang.
#define PIDTEMP
#ifdef PIDTEMP #ifdef PIDTEMP
//#define PID_DEBUG // Sends debug data to the serial port. //#define PID_DEBUG // Sends debug data to the serial port.
//#define PID_OPENLOOP 1 // Puts PID in open loop. M104/M140 sets the output power from 0 to PID_MAX //#define PID_OPENLOOP 1 // Puts PID in open loop. M104/M140 sets the output power from 0 to PID_MAX
...@@ -227,16 +230,12 @@ ...@@ -227,16 +230,12 @@
// is more then PID_FUNCTIONAL_RANGE then the PID will be shut off and the heater will be set to min/max. // 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_FUNCTIONAL_RANGE 10 // degC
#define PID_INTEGRAL_DRIVE_MAX PID_MAX // Limit for the integral term #define PID_INTEGRAL_DRIVE_MAX PID_MAX // Limit for the integral term
#define K1 0.95 // Smoothing factor within the PID
#define MAX_OVERSHOOT_PID_AUTOTUNE 20 // Max valor for overshoot autotune
// HotEnd{HE0,HE1,HE2,HE3} // HotEnd{HE0,HE1,HE2,HE3}
#define DEFAULT_Kp {40, 40, 40, 40} // Kp for E0, E1, E2, E3 #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_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_Kd {60, 60, 60, 60} // Kd for E0, E1, E2, E3
#endif // PIDTEMP #endif // PIDTEMP
//===========================================================================
//=========================================================================== //===========================================================================
//============================= PID > Bed Temperature Control =============== //============================= PID > Bed Temperature Control ===============
......
...@@ -3204,10 +3204,10 @@ inline void gcode_G28() { ...@@ -3204,10 +3204,10 @@ inline void gcode_G28() {
#ifdef ENABLE_AUTO_BED_LEVELING #ifdef ENABLE_AUTO_BED_LEVELING
void out_of_range_error(const char *edge) { void out_of_range_error(const char *p_edge) {
char msg[40]; ECHO_M("?Probe ");
sprintf_P(msg, PSTR("?Probe %s position out of range.\n"), edge); PS_PGM(p_edge);
ECHO_V(msg); ECHO_EM(" position out of range.");
} }
/** /**
...@@ -5123,18 +5123,20 @@ inline void gcode_M226() { ...@@ -5123,18 +5123,20 @@ inline void gcode_M226() {
#endif // PREVENT_DANGEROUS_EXTRUDE #endif // PREVENT_DANGEROUS_EXTRUDE
/** #if defined(PIDTEMP) || defined(PIDTEMPBED)
/**
* M303: PID relay autotune * M303: PID relay autotune
* S<temperature> sets the target temperature. (default target temperature = 150C) * S<temperature> sets the target temperature. (default target temperature = 150C)
* E<extruder> (-1 for the bed) * E<extruder> (-1 for the bed)
* C<cycles> * C<cycles>
*/ */
inline void gcode_M303() { inline void gcode_M303() {
int e = code_seen('E') ? code_value_short() : 0; int e = code_seen('E') ? code_value_short() : 0;
int c = code_seen('C') ? code_value_short() : 5; int c = code_seen('C') ? code_value_short() : 5;
float temp = code_seen('S') ? code_value() : (e < 0 ? 70.0 : 150.0); float temp = code_seen('S') ? code_value() : (e < 0 ? 70.0 : 150.0);
PID_autotune(temp, e, c); PID_autotune(temp, e, c);
} }
#endif
#ifdef PIDTEMPBED #ifdef PIDTEMPBED
// M304: Set bed PID parameters P I and D // M304: Set bed PID parameters P I and D
...@@ -6425,8 +6427,10 @@ void process_next_command() { ...@@ -6425,8 +6427,10 @@ void process_next_command() {
gcode_M302(); break; gcode_M302(); break;
#endif // PREVENT_DANGEROUS_EXTRUDE #endif // PREVENT_DANGEROUS_EXTRUDE
#if defined(PIDTEMP) || defined(PIDTEMPBED)
case 303: // M303 PID autotune case 303: // M303 PID autotune
gcode_M303(); break; gcode_M303(); break;
#endif
#ifdef PIDTEMPBED #ifdef PIDTEMPBED
case 304: // M304 case 304: // M304
......
...@@ -184,7 +184,8 @@ static void updateTemperaturesFromRawValues(); ...@@ -184,7 +184,8 @@ static void updateTemperaturesFromRawValues();
//================================ Functions ================================ //================================ Functions ================================
//=========================================================================== //===========================================================================
void PID_autotune(float temp, int hotend, int ncycles) { #if defined(PIDTEMP) || defined(PIDTEMPBED)
void PID_autotune(float temp, int hotend, int ncycles) {
float input = 0.0; float input = 0.0;
int cycles = 0; int cycles = 0;
bool heating = true; bool heating = true;
...@@ -333,6 +334,7 @@ void PID_autotune(float temp, int hotend, int ncycles) { ...@@ -333,6 +334,7 @@ void PID_autotune(float temp, int hotend, int ncycles) {
} }
if (cycles > ncycles) { if (cycles > ncycles) {
ECHO_LM(DB, MSG_PID_AUTOTUNE_FINISHED); ECHO_LM(DB, MSG_PID_AUTOTUNE_FINISHED);
#ifdef PIDTEMP
if (hotend >= 0) { if (hotend >= 0) {
PID_PARAM(Kp, hotend) = Kp_temp; PID_PARAM(Kp, hotend) = Kp_temp;
PID_PARAM(Ki, hotend) = scalePID_i(Ki_temp); PID_PARAM(Ki, hotend) = scalePID_i(Ki_temp);
...@@ -348,11 +350,13 @@ void PID_autotune(float temp, int hotend, int ncycles) { ...@@ -348,11 +350,13 @@ void PID_autotune(float temp, int hotend, int ncycles) {
ECHO_LMV(DB, "#define DEFAULT_bedKi ", unscalePID_i(Ki_temp)); ECHO_LMV(DB, "#define DEFAULT_bedKi ", unscalePID_i(Ki_temp));
ECHO_LMV(DB, "#define DEFAULT_bedKd ", unscalePID_d(Kd_temp)); ECHO_LMV(DB, "#define DEFAULT_bedKd ", unscalePID_d(Kd_temp));
} }
#endif
return; return;
} }
lcd_update(); lcd_update();
} }
} }
#endif
void updatePID() { void updatePID() {
#ifdef PIDTEMP #ifdef PIDTEMP
...@@ -1646,10 +1650,10 @@ ISR(TIMER0_COMPB_vect) { ...@@ -1646,10 +1650,10 @@ ISR(TIMER0_COMPB_vect) {
#endif //BABYSTEPPING #endif //BABYSTEPPING
} }
#ifdef PIDTEMP #if defined(PIDTEMP) || defined(PIDTEMPBED)
// Apply the scale factors to the PID values // Apply the scale factors to the PID values
float scalePID_i(float i) { return i * PID_dT; } float scalePID_i(float i) { return i * PID_dT; }
float unscalePID_i(float i) { return i / PID_dT; } float unscalePID_i(float i) { return i / PID_dT; }
float scalePID_d(float d) { return d / PID_dT; } float scalePID_d(float d) { return d / PID_dT; }
float unscalePID_d(float d) { return d * PID_dT; } float unscalePID_d(float d) { return d * PID_dT; }
#endif //PIDTEMP #endif // defined(PIDTEMP) || defined(PIDTEMPBED)
...@@ -64,16 +64,19 @@ extern float current_temperature_bed; ...@@ -64,16 +64,19 @@ extern float current_temperature_bed;
#ifdef PIDTEMP #ifdef PIDTEMP
extern float Kp[HOTENDS], Ki[HOTENDS], Kd[HOTENDS]; extern float Kp[HOTENDS], Ki[HOTENDS], Kd[HOTENDS];
#define PID_PARAM(param, e) param[e] // use macro to point to array value #define PID_PARAM(param, e) param[e] // use macro to point to array value
float scalePID_i(float i);
float scalePID_d(float d);
float unscalePID_i(float i);
float unscalePID_d(float d);
#endif #endif
#ifdef PIDTEMPBED #ifdef PIDTEMPBED
extern float bedKp,bedKi,bedKd; extern float bedKp,bedKi,bedKd;
#endif #endif
#if defined(PIDTEMP) || defined(PIDTEMPBED)
float scalePID_i(float i);
float scalePID_d(float d);
float unscalePID_i(float i);
float unscalePID_d(float d);
#endif
#ifdef BABYSTEPPING #ifdef BABYSTEPPING
extern volatile int babystepsTodo[3]; extern volatile int babystepsTodo[3];
#endif #endif
......
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