Remove dead code from get_pid_output

See #12981
This commit is contained in:
Scott Lahteine 2019-03-03 05:29:55 -06:00
parent 35ae5daf2d
commit 599cdc3f0f

View File

@ -725,62 +725,57 @@ float Temperature::get_pid_output(const int8_t e) {
float pid_error = target_temperature[HOTEND_INDEX] - current_temperature[HOTEND_INDEX]; float pid_error = target_temperature[HOTEND_INDEX] - current_temperature[HOTEND_INDEX];
work_pid[HOTEND_INDEX].Kd = PID_K2 * PID_PARAM(Kd, HOTEND_INDEX) * (current_temperature[HOTEND_INDEX] - temp_dState[HOTEND_INDEX]) + float(PID_K1) * work_pid[HOTEND_INDEX].Kd; work_pid[HOTEND_INDEX].Kd = PID_K2 * PID_PARAM(Kd, HOTEND_INDEX) * (current_temperature[HOTEND_INDEX] - temp_dState[HOTEND_INDEX]) + float(PID_K1) * work_pid[HOTEND_INDEX].Kd;
temp_dState[HOTEND_INDEX] = current_temperature[HOTEND_INDEX]; temp_dState[HOTEND_INDEX] = current_temperature[HOTEND_INDEX];
#if HEATER_IDLE_HANDLER
if (heater_idle_timeout_exceeded[HOTEND_INDEX]) { if (target_temperature[HOTEND_INDEX] == 0
pid_output = 0; || pid_error < -(PID_FUNCTIONAL_RANGE)
pid_reset[HOTEND_INDEX] = true; #if HEATER_IDLE_HANDLER
|| heater_idle_timeout_exceeded[HOTEND_INDEX]
#endif
) {
pid_output = 0;
pid_reset[HOTEND_INDEX] = true;
}
else if (pid_error > PID_FUNCTIONAL_RANGE) {
pid_output = BANG_MAX;
pid_reset[HOTEND_INDEX] = true;
}
else {
if (pid_reset[HOTEND_INDEX]) {
temp_iState[HOTEND_INDEX] = 0.0;
pid_reset[HOTEND_INDEX] = false;
} }
else temp_iState[HOTEND_INDEX] += pid_error;
#endif work_pid[HOTEND_INDEX].Kp = PID_PARAM(Kp, HOTEND_INDEX) * pid_error;
if (pid_error > PID_FUNCTIONAL_RANGE) { work_pid[HOTEND_INDEX].Ki = PID_PARAM(Ki, HOTEND_INDEX) * temp_iState[HOTEND_INDEX];
pid_output = BANG_MAX;
pid_reset[HOTEND_INDEX] = true; pid_output = work_pid[HOTEND_INDEX].Kp + work_pid[HOTEND_INDEX].Ki - work_pid[HOTEND_INDEX].Kd;
}
else if (pid_error < -(PID_FUNCTIONAL_RANGE) || target_temperature[HOTEND_INDEX] == 0 #if ENABLED(PID_EXTRUSION_SCALING)
#if HEATER_IDLE_HANDLER work_pid[HOTEND_INDEX].Kc = 0;
|| heater_idle_timeout_exceeded[HOTEND_INDEX] if (_HOTEND_TEST) {
#endif const long e_position = stepper.position(E_AXIS);
) { if (e_position > last_e_position) {
pid_output = 0; lpq[lpq_ptr] = e_position - last_e_position;
pid_reset[HOTEND_INDEX] = true; last_e_position = e_position;
}
else {
if (pid_reset[HOTEND_INDEX]) {
temp_iState[HOTEND_INDEX] = 0.0;
pid_reset[HOTEND_INDEX] = false;
} }
temp_iState[HOTEND_INDEX] += pid_error; else
work_pid[HOTEND_INDEX].Kp = PID_PARAM(Kp, HOTEND_INDEX) * pid_error; lpq[lpq_ptr] = 0;
work_pid[HOTEND_INDEX].Ki = PID_PARAM(Ki, HOTEND_INDEX) * temp_iState[HOTEND_INDEX];
pid_output = work_pid[HOTEND_INDEX].Kp + work_pid[HOTEND_INDEX].Ki - work_pid[HOTEND_INDEX].Kd; if (++lpq_ptr >= lpq_len) lpq_ptr = 0;
work_pid[HOTEND_INDEX].Kc = (lpq[lpq_ptr] * planner.steps_to_mm[E_AXIS]) * PID_PARAM(Kc, HOTEND_INDEX);
#if ENABLED(PID_EXTRUSION_SCALING) pid_output += work_pid[HOTEND_INDEX].Kc;
work_pid[HOTEND_INDEX].Kc = 0;
if (_HOTEND_TEST) {
const long e_position = stepper.position(E_AXIS);
if (e_position > last_e_position) {
lpq[lpq_ptr] = e_position - last_e_position;
last_e_position = e_position;
}
else
lpq[lpq_ptr] = 0;
if (++lpq_ptr >= lpq_len) lpq_ptr = 0;
work_pid[HOTEND_INDEX].Kc = (lpq[lpq_ptr] * planner.steps_to_mm[E_AXIS]) * PID_PARAM(Kc, HOTEND_INDEX);
pid_output += work_pid[HOTEND_INDEX].Kc;
}
#endif // PID_EXTRUSION_SCALING
if (pid_output > PID_MAX) {
if (pid_error > 0) temp_iState[HOTEND_INDEX] -= pid_error; // conditional un-integration
pid_output = PID_MAX;
}
else if (pid_output < 0) {
if (pid_error < 0) temp_iState[HOTEND_INDEX] -= pid_error; // conditional un-integration
pid_output = 0;
}
} }
#endif // PID_EXTRUSION_SCALING
if (pid_output > PID_MAX) {
if (pid_error > 0) temp_iState[HOTEND_INDEX] -= pid_error; // conditional un-integration
pid_output = PID_MAX;
}
else if (pid_output < 0) {
if (pid_error < 0) temp_iState[HOTEND_INDEX] -= pid_error; // conditional un-integration
pid_output = 0;
}
}
#else // PID_OPENLOOP #else // PID_OPENLOOP
@ -806,11 +801,12 @@ float Temperature::get_pid_output(const int8_t e) {
#else /* PID off */ #else /* PID off */
#if HEATER_IDLE_HANDLER #if HEATER_IDLE_HANDLER
if (heater_idle_timeout_exceeded[HOTEND_INDEX]) #define _TIMED_OUT_TEST heater_idle_timeout_exceeded[HOTEND_INDEX]
pid_output = 0; #else
else #define _TIMED_OUT_TEST false
#endif #endif
pid_output = (current_temperature[HOTEND_INDEX] < target_temperature[HOTEND_INDEX]) ? BANG_MAX : 0; pid_output = (!_TIMED_OUT_TEST && current_temperature[HOTEND_INDEX] < target_temperature[HOTEND_INDEX]) ? BANG_MAX : 0;
#undef _TIMED_OUT_TEST
#endif #endif
return pid_output; return pid_output;