|
@@ -725,62 +725,57 @@ float Temperature::get_pid_output(const int8_t e) {
|
725
|
725
|
float pid_error = target_temperature[HOTEND_INDEX] - current_temperature[HOTEND_INDEX];
|
726
|
726
|
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;
|
727
|
727
|
temp_dState[HOTEND_INDEX] = current_temperature[HOTEND_INDEX];
|
728
|
|
- #if HEATER_IDLE_HANDLER
|
729
|
|
- if (heater_idle_timeout_exceeded[HOTEND_INDEX]) {
|
730
|
|
- pid_output = 0;
|
731
|
|
- pid_reset[HOTEND_INDEX] = true;
|
|
728
|
+
|
|
729
|
+ if (target_temperature[HOTEND_INDEX] == 0
|
|
730
|
+ || pid_error < -(PID_FUNCTIONAL_RANGE)
|
|
731
|
+ #if HEATER_IDLE_HANDLER
|
|
732
|
+ || heater_idle_timeout_exceeded[HOTEND_INDEX]
|
|
733
|
+ #endif
|
|
734
|
+ ) {
|
|
735
|
+ pid_output = 0;
|
|
736
|
+ pid_reset[HOTEND_INDEX] = true;
|
|
737
|
+ }
|
|
738
|
+ else if (pid_error > PID_FUNCTIONAL_RANGE) {
|
|
739
|
+ pid_output = BANG_MAX;
|
|
740
|
+ pid_reset[HOTEND_INDEX] = true;
|
|
741
|
+ }
|
|
742
|
+ else {
|
|
743
|
+ if (pid_reset[HOTEND_INDEX]) {
|
|
744
|
+ temp_iState[HOTEND_INDEX] = 0.0;
|
|
745
|
+ pid_reset[HOTEND_INDEX] = false;
|
732
|
746
|
}
|
733
|
|
- else
|
734
|
|
- #endif
|
735
|
|
- if (pid_error > PID_FUNCTIONAL_RANGE) {
|
736
|
|
- pid_output = BANG_MAX;
|
737
|
|
- pid_reset[HOTEND_INDEX] = true;
|
738
|
|
- }
|
739
|
|
- else if (pid_error < -(PID_FUNCTIONAL_RANGE) || target_temperature[HOTEND_INDEX] == 0
|
740
|
|
- #if HEATER_IDLE_HANDLER
|
741
|
|
- || heater_idle_timeout_exceeded[HOTEND_INDEX]
|
742
|
|
- #endif
|
743
|
|
- ) {
|
744
|
|
- pid_output = 0;
|
745
|
|
- pid_reset[HOTEND_INDEX] = true;
|
746
|
|
- }
|
747
|
|
- else {
|
748
|
|
- if (pid_reset[HOTEND_INDEX]) {
|
749
|
|
- temp_iState[HOTEND_INDEX] = 0.0;
|
750
|
|
- pid_reset[HOTEND_INDEX] = false;
|
751
|
|
- }
|
752
|
|
- temp_iState[HOTEND_INDEX] += pid_error;
|
753
|
|
- work_pid[HOTEND_INDEX].Kp = PID_PARAM(Kp, HOTEND_INDEX) * pid_error;
|
754
|
|
- work_pid[HOTEND_INDEX].Ki = PID_PARAM(Ki, HOTEND_INDEX) * temp_iState[HOTEND_INDEX];
|
755
|
|
-
|
756
|
|
- pid_output = work_pid[HOTEND_INDEX].Kp + work_pid[HOTEND_INDEX].Ki - work_pid[HOTEND_INDEX].Kd;
|
757
|
|
-
|
758
|
|
- #if ENABLED(PID_EXTRUSION_SCALING)
|
759
|
|
- work_pid[HOTEND_INDEX].Kc = 0;
|
760
|
|
- if (_HOTEND_TEST) {
|
761
|
|
- const long e_position = stepper.position(E_AXIS);
|
762
|
|
- if (e_position > last_e_position) {
|
763
|
|
- lpq[lpq_ptr] = e_position - last_e_position;
|
764
|
|
- last_e_position = e_position;
|
765
|
|
- }
|
766
|
|
- else
|
767
|
|
- lpq[lpq_ptr] = 0;
|
768
|
|
-
|
769
|
|
- if (++lpq_ptr >= lpq_len) lpq_ptr = 0;
|
770
|
|
- work_pid[HOTEND_INDEX].Kc = (lpq[lpq_ptr] * planner.steps_to_mm[E_AXIS]) * PID_PARAM(Kc, HOTEND_INDEX);
|
771
|
|
- pid_output += work_pid[HOTEND_INDEX].Kc;
|
772
|
|
- }
|
773
|
|
- #endif // PID_EXTRUSION_SCALING
|
|
747
|
+ temp_iState[HOTEND_INDEX] += pid_error;
|
|
748
|
+ work_pid[HOTEND_INDEX].Kp = PID_PARAM(Kp, HOTEND_INDEX) * pid_error;
|
|
749
|
+ work_pid[HOTEND_INDEX].Ki = PID_PARAM(Ki, HOTEND_INDEX) * temp_iState[HOTEND_INDEX];
|
774
|
750
|
|
775
|
|
- if (pid_output > PID_MAX) {
|
776
|
|
- if (pid_error > 0) temp_iState[HOTEND_INDEX] -= pid_error; // conditional un-integration
|
777
|
|
- pid_output = PID_MAX;
|
778
|
|
- }
|
779
|
|
- else if (pid_output < 0) {
|
780
|
|
- if (pid_error < 0) temp_iState[HOTEND_INDEX] -= pid_error; // conditional un-integration
|
781
|
|
- pid_output = 0;
|
|
751
|
+ pid_output = work_pid[HOTEND_INDEX].Kp + work_pid[HOTEND_INDEX].Ki - work_pid[HOTEND_INDEX].Kd;
|
|
752
|
+
|
|
753
|
+ #if ENABLED(PID_EXTRUSION_SCALING)
|
|
754
|
+ work_pid[HOTEND_INDEX].Kc = 0;
|
|
755
|
+ if (_HOTEND_TEST) {
|
|
756
|
+ const long e_position = stepper.position(E_AXIS);
|
|
757
|
+ if (e_position > last_e_position) {
|
|
758
|
+ lpq[lpq_ptr] = e_position - last_e_position;
|
|
759
|
+ last_e_position = e_position;
|
782
|
760
|
}
|
|
761
|
+ else
|
|
762
|
+ lpq[lpq_ptr] = 0;
|
|
763
|
+
|
|
764
|
+ if (++lpq_ptr >= lpq_len) lpq_ptr = 0;
|
|
765
|
+ work_pid[HOTEND_INDEX].Kc = (lpq[lpq_ptr] * planner.steps_to_mm[E_AXIS]) * PID_PARAM(Kc, HOTEND_INDEX);
|
|
766
|
+ pid_output += work_pid[HOTEND_INDEX].Kc;
|
783
|
767
|
}
|
|
768
|
+ #endif // PID_EXTRUSION_SCALING
|
|
769
|
+
|
|
770
|
+ if (pid_output > PID_MAX) {
|
|
771
|
+ if (pid_error > 0) temp_iState[HOTEND_INDEX] -= pid_error; // conditional un-integration
|
|
772
|
+ pid_output = PID_MAX;
|
|
773
|
+ }
|
|
774
|
+ else if (pid_output < 0) {
|
|
775
|
+ if (pid_error < 0) temp_iState[HOTEND_INDEX] -= pid_error; // conditional un-integration
|
|
776
|
+ pid_output = 0;
|
|
777
|
+ }
|
|
778
|
+ }
|
784
|
779
|
|
785
|
780
|
#else // PID_OPENLOOP
|
786
|
781
|
|
|
@@ -806,11 +801,12 @@ float Temperature::get_pid_output(const int8_t e) {
|
806
|
801
|
|
807
|
802
|
#else /* PID off */
|
808
|
803
|
#if HEATER_IDLE_HANDLER
|
809
|
|
- if (heater_idle_timeout_exceeded[HOTEND_INDEX])
|
810
|
|
- pid_output = 0;
|
811
|
|
- else
|
|
804
|
+ #define _TIMED_OUT_TEST heater_idle_timeout_exceeded[HOTEND_INDEX]
|
|
805
|
+ #else
|
|
806
|
+ #define _TIMED_OUT_TEST false
|
812
|
807
|
#endif
|
813
|
|
- pid_output = (current_temperature[HOTEND_INDEX] < target_temperature[HOTEND_INDEX]) ? BANG_MAX : 0;
|
|
808
|
+ pid_output = (!_TIMED_OUT_TEST && current_temperature[HOTEND_INDEX] < target_temperature[HOTEND_INDEX]) ? BANG_MAX : 0;
|
|
809
|
+ #undef _TIMED_OUT_TEST
|
814
|
810
|
#endif
|
815
|
811
|
|
816
|
812
|
return pid_output;
|