소스 검색

Merge pull request #4278 from thinkyhead/rc_more_hotends_1

Fixups for PID_ADD_EXTRUSION_RATE and HOTENDS==1
Scott Lahteine 9 년 전
부모
커밋
a1de96d152
2개의 변경된 파일38개의 추가작업 그리고 23개의 파일을 삭제
  1. 14
    12
      Marlin/temperature.cpp
  2. 24
    11
      Marlin/temperature.h

+ 14
- 12
Marlin/temperature.cpp 파일 보기

@@ -128,7 +128,7 @@ volatile bool Temperature::temp_meas_ready = false;
128 128
 
129 129
   #if ENABLED(PID_ADD_EXTRUSION_RATE)
130 130
     float Temperature::cTerm[HOTENDS];
131
-    long Temperature::last_position[HOTENDS];
131
+    long Temperature::last_e_position;
132 132
     long Temperature::lpq[LPQ_MAX_LEN];
133 133
     int Temperature::lpq_ptr = 0;
134 134
   #endif
@@ -444,11 +444,11 @@ Temperature::Temperature() { }
444 444
 
445 445
 void Temperature::updatePID() {
446 446
   #if ENABLED(PIDTEMP)
447
+    #if ENABLED(PID_ADD_EXTRUSION_RATE)
448
+      last_e_position = 0;
449
+    #endif
447 450
     HOTEND_LOOP() {
448 451
       temp_iState_max[e] = (PID_INTEGRAL_DRIVE_MAX) / PID_PARAM(Ki, e);
449
-      #if ENABLED(PID_ADD_EXTRUSION_RATE)
450
-        last_position[e] = 0;
451
-      #endif
452 452
     }
453 453
   #endif
454 454
   #if ENABLED(PIDTEMPBED)
@@ -531,10 +531,8 @@ float Temperature::get_pid_output(int e) {
531 531
   #if HOTENDS == 1
532 532
     UNUSED(e);
533 533
     #define _HOTEND_TEST     true
534
-    #define _HOTEND_EXTRUDER active_extruder
535 534
   #else
536 535
     #define _HOTEND_TEST     e == active_extruder
537
-    #define _HOTEND_EXTRUDER e
538 536
   #endif
539 537
   float pid_output;
540 538
   #if ENABLED(PIDTEMP)
@@ -566,14 +564,14 @@ float Temperature::get_pid_output(int e) {
566 564
           cTerm[HOTEND_INDEX] = 0;
567 565
           if (_HOTEND_TEST) {
568 566
             long e_position = stepper.position(E_AXIS);
569
-            if (e_position > last_position[_HOTEND_EXTRUDER]) {
570
-              lpq[lpq_ptr++] = e_position - last_position[_HOTEND_EXTRUDER];
571
-              last_position[_HOTEND_EXTRUDER] = e_position;
567
+            if (e_position > last_e_position) {
568
+              lpq[lpq_ptr] = e_position - last_e_position;
569
+              last_e_position = e_position;
572 570
             }
573 571
             else {
574
-              lpq[lpq_ptr++] = 0;
572
+              lpq[lpq_ptr] = 0;
575 573
             }
576
-            if (lpq_ptr >= lpq_len) lpq_ptr = 0;
574
+            if (++lpq_ptr >= lpq_len) lpq_ptr = 0;
577 575
             cTerm[HOTEND_INDEX] = (lpq[lpq_ptr] / planner.axis_steps_per_mm[E_AXIS]) * PID_PARAM(Kc, HOTEND_INDEX);
578 576
             pid_output += cTerm[HOTEND_INDEX];
579 577
           }
@@ -952,7 +950,7 @@ void Temperature::init() {
952 950
       temp_iState_min[e] = 0.0;
953 951
       temp_iState_max[e] = (PID_INTEGRAL_DRIVE_MAX) / PID_PARAM(Ki, e);
954 952
       #if ENABLED(PID_ADD_EXTRUSION_RATE)
955
-        last_position[e] = 0;
953
+        last_e_position = 0;
956 954
       #endif
957 955
     #endif //PIDTEMP
958 956
     #if ENABLED(PIDTEMPBED)
@@ -961,6 +959,10 @@ void Temperature::init() {
961 959
     #endif //PIDTEMPBED
962 960
   }
963 961
 
962
+  #if ENABLED(PIDTEMP) && ENABLED(PID_ADD_EXTRUSION_RATE)
963
+    last_e_position = 0;
964
+  #endif
965
+
964 966
   #if HAS_HEATER_0
965 967
     SET_OUTPUT(HEATER_0_PIN);
966 968
   #endif

+ 24
- 11
Marlin/temperature.h 파일 보기

@@ -76,13 +76,13 @@ class Temperature {
76 76
 
77 77
     #if ENABLED(PIDTEMP)
78 78
 
79
-      #if ENABLED(PID_PARAMS_PER_HOTEND)
79
+      #if ENABLED(PID_PARAMS_PER_HOTEND) && HOTENDS > 1
80 80
 
81 81
         static float Kp[HOTENDS], Ki[HOTENDS], Kd[HOTENDS];
82 82
         #if ENABLED(PID_ADD_EXTRUSION_RATE)
83 83
           static float Kc[HOTENDS];
84 84
         #endif
85
-        #define PID_PARAM(param, e) Temperature::param[e]
85
+        #define PID_PARAM(param, h) Temperature::param[h]
86 86
 
87 87
       #else
88 88
 
@@ -90,7 +90,7 @@ class Temperature {
90 90
         #if ENABLED(PID_ADD_EXTRUSION_RATE)
91 91
           static float Kc;
92 92
         #endif
93
-        #define PID_PARAM(param, e) Temperature::param
93
+        #define PID_PARAM(param, h) Temperature::param
94 94
 
95 95
       #endif // PID_PARAMS_PER_HOTEND
96 96
 
@@ -150,7 +150,7 @@ class Temperature {
150 150
 
151 151
       #if ENABLED(PID_ADD_EXTRUSION_RATE)
152 152
         static float cTerm[HOTENDS];
153
-        static long last_position[HOTENDS];
153
+        static long last_e_position;
154 154
         static long lpq[LPQ_MAX_LEN];
155 155
         static int lpq_ptr;
156 156
       #endif
@@ -247,11 +247,24 @@ class Temperature {
247 247
      * Preheating hotends
248 248
      */
249 249
     #ifdef MILLISECONDS_PREHEAT_TIME
250
-      static bool is_preheating(uint8_t hotend) {
251
-        return preheat_end_time[hotend] && PENDING(millis(), preheat_end_time[hotend]);
250
+      static bool is_preheating(uint8_t e) {
251
+        #if HOTENDS == 1
252
+          UNUSED(e);
253
+        #endif
254
+        return preheat_end_time[HOTEND_INDEX] && PENDING(millis(), preheat_end_time[HOTEND_INDEX]);
255
+      }
256
+      static void start_preheat_time(uint8_t e) {
257
+        #if HOTENDS == 1
258
+          UNUSED(e);
259
+        #endif
260
+        preheat_end_time[HOTEND_INDEX] = millis() + MILLISECONDS_PREHEAT_TIME;
261
+      }
262
+      static void reset_preheat_time(uint8_t e) {
263
+        #if HOTENDS == 1
264
+          UNUSED(e);
265
+        #endif
266
+        preheat_end_time[HOTEND_INDEX] = 0;
252 267
       }
253
-      static void start_preheat_time(uint8_t hotend) { preheat_end_time[hotend] = millis() + MILLISECONDS_PREHEAT_TIME; }
254
-      static void reset_preheat_time(uint8_t hotend) { preheat_end_time[hotend] = 0; }
255 268
     #else
256 269
       #define is_preheating(n) (false)
257 270
     #endif
@@ -306,9 +319,9 @@ class Temperature {
306 319
       #endif
307 320
       #ifdef MILLISECONDS_PREHEAT_TIME
308 321
         if (celsius == 0.0f)
309
-          reset_preheat_time(hotend);
310
-        else if (target_temperature[hotend] == 0.0f)
311
-          start_preheat_time(hotend);
322
+          reset_preheat_time(HOTEND_INDEX);
323
+        else if (target_temperature[HOTEND_INDEX] == 0.0f)
324
+          start_preheat_time(HOTEND_INDEX);
312 325
       #endif
313 326
       target_temperature[HOTEND_INDEX] = celsius;
314 327
       #if ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0

Loading…
취소
저장