Commit a8e1e08b authored by MagoKimbra's avatar MagoKimbra

Update

parent 433d7898
......@@ -215,10 +215,13 @@
//============================= PID Settings ================================
//===========================================================================
// 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 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
//#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
......@@ -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.
#define PID_FUNCTIONAL_RANGE 10 // degC
#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}
#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
#endif // PIDTEMP
//===========================================================================
//===========================================================================
//============================= PID > Bed Temperature Control ===============
......
......@@ -3204,10 +3204,10 @@ inline void gcode_G28() {
#ifdef ENABLE_AUTO_BED_LEVELING
void out_of_range_error(const char *edge) {
char msg[40];
sprintf_P(msg, PSTR("?Probe %s position out of range.\n"), edge);
ECHO_V(msg);
void out_of_range_error(const char *p_edge) {
ECHO_M("?Probe ");
PS_PGM(p_edge);
ECHO_EM(" position out of range.");
}
/**
......@@ -5123,18 +5123,20 @@ inline void gcode_M226() {
#endif // PREVENT_DANGEROUS_EXTRUDE
/**
#if defined(PIDTEMP) || defined(PIDTEMPBED)
/**
* M303: PID relay autotune
* S<temperature> sets the target temperature. (default target temperature = 150C)
* E<extruder> (-1 for the bed)
* C<cycles>
*/
inline void gcode_M303() {
inline void gcode_M303() {
int e = code_seen('E') ? code_value_short() : 0;
int c = code_seen('C') ? code_value_short() : 5;
float temp = code_seen('S') ? code_value() : (e < 0 ? 70.0 : 150.0);
PID_autotune(temp, e, c);
}
}
#endif
#ifdef PIDTEMPBED
// M304: Set bed PID parameters P I and D
......@@ -6425,8 +6427,10 @@ void process_next_command() {
gcode_M302(); break;
#endif // PREVENT_DANGEROUS_EXTRUDE
#if defined(PIDTEMP) || defined(PIDTEMPBED)
case 303: // M303 PID autotune
gcode_M303(); break;
#endif
#ifdef PIDTEMPBED
case 304: // M304
......
......@@ -184,7 +184,8 @@ static void updateTemperaturesFromRawValues();
//================================ 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;
int cycles = 0;
bool heating = true;
......@@ -333,6 +334,7 @@ void PID_autotune(float temp, int hotend, int ncycles) {
}
if (cycles > ncycles) {
ECHO_LM(DB, MSG_PID_AUTOTUNE_FINISHED);
#ifdef PIDTEMP
if (hotend >= 0) {
PID_PARAM(Kp, hotend) = Kp_temp;
PID_PARAM(Ki, hotend) = scalePID_i(Ki_temp);
......@@ -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_bedKd ", unscalePID_d(Kd_temp));
}
#endif
return;
}
lcd_update();
}
}
}
#endif
void updatePID() {
#ifdef PIDTEMP
......@@ -1646,10 +1650,10 @@ ISR(TIMER0_COMPB_vect) {
#endif //BABYSTEPPING
}
#ifdef PIDTEMP
#if defined(PIDTEMP) || defined(PIDTEMPBED)
// Apply the scale factors to the PID values
float scalePID_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 unscalePID_d(float d) { return d * PID_dT; }
#endif //PIDTEMP
#endif // defined(PIDTEMP) || defined(PIDTEMPBED)
......@@ -64,16 +64,19 @@ extern float current_temperature_bed;
#ifdef PIDTEMP
extern float Kp[HOTENDS], Ki[HOTENDS], Kd[HOTENDS];
#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
#ifdef PIDTEMPBED
extern float bedKp,bedKi,bedKd;
#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
extern volatile int babystepsTodo[3];
#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