Преглед изворни кода

Merge Extrusion_rate_heater_compensation

Richard Wackerbarth пре 8 година
родитељ
комит
42e381f8e2

+ 2
- 1
Marlin/Configuration_adv.h Прегледај датотеку

@@ -41,7 +41,8 @@
41 41
   // if Kc is chosen well, the additional required power due to increased melting should be compensated.
42 42
   #define PID_ADD_EXTRUSION_RATE
43 43
   #if ENABLED(PID_ADD_EXTRUSION_RATE)
44
-    #define  DEFAULT_Kc (1) //heating power=Kc*(e_speed)
44
+    #define DEFAULT_Kc (100) //heating power=Kc*(e_speed)
45
+    #define LPQ_MAX_LEN 50
45 46
   #endif
46 47
 #endif
47 48
 

+ 4
- 0
Marlin/Marlin.h Прегледај датотеку

@@ -329,6 +329,10 @@ extern int fanSpeed;
329 329
   extern int meas_delay_cm; //delay distance
330 330
 #endif
331 331
 
332
+#if ENABLED(PID_ADD_EXTRUSION_RATE)
333
+  extern int lpq_len;
334
+#endif
335
+
332 336
 #if ENABLED(FWRETRACT)
333 337
   extern bool autoretract_enabled;
334 338
   extern bool retracted[EXTRUDERS]; // extruder[n].retracted

+ 16
- 1
Marlin/Marlin_main.cpp Прегледај датотеку

@@ -420,6 +420,10 @@ bool target_direction;
420 420
   boolean chdkActive = false;
421 421
 #endif
422 422
 
423
+#if ENABLED(PID_ADD_EXTRUSION_RATE)
424
+  int lpq_len = 20;
425
+#endif
426
+
423 427
 //===========================================================================
424 428
 //================================ Functions ================================
425 429
 //===========================================================================
@@ -4770,7 +4774,16 @@ inline void gcode_M226() {
4770 4774
 #if ENABLED(PIDTEMP)
4771 4775
 
4772 4776
   /**
4773
-   * M301: Set PID parameters P I D (and optionally C)
4777
+   * M301: Set PID parameters P I D (and optionally C, L)
4778
+   *
4779
+   *   P[float] Kp term
4780
+   *   I[float] Ki term (unscaled)
4781
+   *   D[float] Kd term (unscaled)
4782
+   *
4783
+   * With PID_ADD_EXTRUSION_RATE:
4784
+   *
4785
+   *   C[float] Kc term
4786
+   *   L[float] LPQ length
4774 4787
    */
4775 4788
   inline void gcode_M301() {
4776 4789
 
@@ -4784,6 +4797,8 @@ inline void gcode_M226() {
4784 4797
       if (code_seen('D')) PID_PARAM(Kd, e) = scalePID_d(code_value());
4785 4798
       #if ENABLED(PID_ADD_EXTRUSION_RATE)
4786 4799
         if (code_seen('C')) PID_PARAM(Kc, e) = code_value();
4800
+        if (code_seen('L')) lpq_len = code_value();
4801
+        NOMORE(lpq_len, LPQ_MAX_LEN);
4787 4802
       #endif
4788 4803
 
4789 4804
       updatePID();

+ 19
- 3
Marlin/configuration_store.cpp Прегледај датотеку

@@ -14,7 +14,7 @@
14 14
  *
15 15
  */
16 16
 
17
-#define EEPROM_VERSION "V20"
17
+#define EEPROM_VERSION "V21"
18 18
 
19 19
 /**
20 20
  * V19 EEPROM Layout:
@@ -60,6 +60,7 @@
60 60
  *  M301 E1 PIDC  Kp[1], Ki[1], Kd[1], Kc[1]
61 61
  *  M301 E2 PIDC  Kp[2], Ki[2], Kd[2], Kc[2]
62 62
  *  M301 E3 PIDC  Kp[3], Ki[3], Kd[3], Kc[3]
63
+ *  M301 L        lpq_len
63 64
  *
64 65
  * PIDTEMPBED:
65 66
  *  M304 PID  bedKp, bedKi, bedKd
@@ -227,6 +228,11 @@ void Config_StoreSettings()  {
227 228
 
228 229
   } // Extruders Loop
229 230
 
231
+  #if DISABLED(PID_ADD_EXTRUSION_RATE)
232
+    int lpq_len = 20;
233
+  #endif
234
+  EEPROM_WRITE_VAR(i, lpq_len);
235
+
230 236
   #if DISABLED(PIDTEMPBED)
231 237
     float bedKp = DUMMY_PID_VALUE, bedKi = DUMMY_PID_VALUE, bedKd = DUMMY_PID_VALUE;
232 238
   #endif
@@ -393,6 +399,11 @@ void Config_RetrieveSettings() {
393 399
       for (int q=16; q--;) EEPROM_READ_VAR(i, dummy);  // 4x Kp, Ki, Kd, Kc
394 400
     #endif // !PIDTEMP
395 401
 
402
+    #if DISABLED(PID_ADD_EXTRUSION_RATE)
403
+      int lpq_len;
404
+    #endif
405
+    EEPROM_READ_VAR(i, lpq_len);
406
+
396 407
     #if DISABLED(PIDTEMPBED)
397 408
       float bedKp, bedKi, bedKd;
398 409
     #endif
@@ -539,6 +550,9 @@ void Config_ResetDefault() {
539 550
         PID_PARAM(Kc, e) = DEFAULT_Kc;
540 551
       #endif
541 552
     }
553
+    #if ENABLED(PID_ADD_EXTRUSION_RATE)
554
+      lpq_len = 20; // default last-position-queue size
555
+    #endif
542 556
     // call updatePID (similar to when we have processed M301)
543 557
     updatePID();
544 558
   #endif // PIDTEMP
@@ -744,7 +758,8 @@ void Config_PrintSettings(bool forReplay) {
744 758
             SERIAL_ECHOPAIR(" D", unscalePID_d(PID_PARAM(Kd, i)));
745 759
             #if ENABLED(PID_ADD_EXTRUSION_RATE)
746 760
               SERIAL_ECHOPAIR(" C", PID_PARAM(Kc, i));
747
-            #endif      
761
+              if (i == 0) SERIAL_ECHOPAIR(" L", lpq_len);
762
+            #endif
748 763
             SERIAL_EOL;
749 764
           }
750 765
         }
@@ -758,7 +773,8 @@ void Config_PrintSettings(bool forReplay) {
758 773
         SERIAL_ECHOPAIR(" D", unscalePID_d(PID_PARAM(Kd, 0)));
759 774
         #if ENABLED(PID_ADD_EXTRUSION_RATE)
760 775
           SERIAL_ECHOPAIR(" C", PID_PARAM(Kc, 0));
761
-        #endif      
776
+          SERIAL_ECHOPAIR(" L", lpq_len);
777
+        #endif
762 778
         SERIAL_EOL;
763 779
       }
764 780
     #endif // PIDTEMP

+ 2
- 1
Marlin/configurator/config/Configuration_adv.h Прегледај датотеку

@@ -41,7 +41,8 @@
41 41
   // if Kc is chosen well, the additional required power due to increased melting should be compensated.
42 42
   #define PID_ADD_EXTRUSION_RATE
43 43
   #if ENABLED(PID_ADD_EXTRUSION_RATE)
44
-    #define  DEFAULT_Kc (1) //heating power=Kc*(e_speed)
44
+    #define DEFAULT_Kc (100) //heating power=Kc*(e_speed)
45
+    #define LPQ_MAX_LEN 50
45 46
   #endif
46 47
 #endif
47 48
 

+ 1
- 0
Marlin/configurator/config/language.h Прегледај датотеку

@@ -199,6 +199,7 @@
199 199
 #define MSG_PID_DEBUG_PTERM                 " pTerm "
200 200
 #define MSG_PID_DEBUG_ITERM                 " iTerm "
201 201
 #define MSG_PID_DEBUG_DTERM                 " dTerm "
202
+#define MSG_PID_DEBUG_CTERM                 " cTerm "
202 203
 #define MSG_INVALID_EXTRUDER_NUM            " - Invalid extruder number !"
203 204
 
204 205
 #define MSG_HEATER_BED                      "bed"

+ 2
- 1
Marlin/example_configurations/Felix/Configuration_adv.h Прегледај датотеку

@@ -51,7 +51,8 @@
51 51
   // if Kc is chosen well, the additional required power due to increased melting should be compensated.
52 52
   #define PID_ADD_EXTRUSION_RATE
53 53
   #if ENABLED(PID_ADD_EXTRUSION_RATE)
54
-    #define  DEFAULT_Kc (1) //heating power=Kc*(e_speed)
54
+    #define DEFAULT_Kc (100) //heating power=Kc*(e_speed)
55
+    #define LPQ_MAX_LEN 50
55 56
   #endif
56 57
 #endif
57 58
 

+ 2
- 1
Marlin/example_configurations/Hephestos/Configuration_adv.h Прегледај датотеку

@@ -51,7 +51,8 @@
51 51
   // if Kc is chosen well, the additional required power due to increased melting should be compensated.
52 52
   #define PID_ADD_EXTRUSION_RATE
53 53
   #if ENABLED(PID_ADD_EXTRUSION_RATE)
54
-    #define  DEFAULT_Kc (1) //heating power=Kc*(e_speed)
54
+    #define DEFAULT_Kc (100) //heating power=Kc*(e_speed)
55
+    #define LPQ_MAX_LEN 50
55 56
   #endif
56 57
 #endif
57 58
 

+ 2
- 1
Marlin/example_configurations/K8200/Configuration_adv.h Прегледај датотеку

@@ -51,7 +51,8 @@
51 51
   // if Kc is chosen well, the additional required power due to increased melting should be compensated.
52 52
   #define PID_ADD_EXTRUSION_RATE
53 53
   #if ENABLED(PID_ADD_EXTRUSION_RATE)
54
-    #define  DEFAULT_Kc (1) //heating power=Kc*(e_speed)
54
+    #define DEFAULT_Kc (100) //heating power=Kc*(e_speed)
55
+    #define LPQ_MAX_LEN 50
55 56
   #endif
56 57
 #endif
57 58
 

+ 2
- 1
Marlin/example_configurations/RigidBot/Configuration_adv.h Прегледај датотеку

@@ -41,7 +41,8 @@
41 41
   // if Kc is chosen well, the additional required power due to increased melting should be compensated.
42 42
   #define PID_ADD_EXTRUSION_RATE
43 43
   #if ENABLED(PID_ADD_EXTRUSION_RATE)
44
-    #define  DEFAULT_Kc (1) //heating power=Kc*(e_speed)
44
+    #define DEFAULT_Kc (100) //heating power=Kc*(e_speed)
45
+    #define LPQ_MAX_LEN 50
45 46
   #endif
46 47
 #endif
47 48
 

+ 2
- 1
Marlin/example_configurations/SCARA/Configuration_adv.h Прегледај датотеку

@@ -51,7 +51,8 @@
51 51
   // if Kc is chosen well, the additional required power due to increased melting should be compensated.
52 52
   #define PID_ADD_EXTRUSION_RATE
53 53
   #if ENABLED(PID_ADD_EXTRUSION_RATE)
54
-    #define  DEFAULT_Kc (1) //heating power=Kc*(e_speed)
54
+    #define DEFAULT_Kc (100) //heating power=Kc*(e_speed)
55
+    #define LPQ_MAX_LEN 50
55 56
   #endif
56 57
 #endif
57 58
 

+ 2
- 1
Marlin/example_configurations/TAZ4/Configuration_adv.h Прегледај датотеку

@@ -41,7 +41,8 @@
41 41
   // if Kc is chosen well, the additional required power due to increased melting should be compensated.
42 42
   #define PID_ADD_EXTRUSION_RATE
43 43
   #if ENABLED(PID_ADD_EXTRUSION_RATE)
44
-    #define  DEFAULT_Kc (1) //heating power=Kc*(e_speed)
44
+    #define DEFAULT_Kc (100) //heating power=Kc*(e_speed)
45
+    #define LPQ_MAX_LEN 50
45 46
   #endif
46 47
 #endif
47 48
 

+ 2
- 1
Marlin/example_configurations/WITBOX/Configuration_adv.h Прегледај датотеку

@@ -51,7 +51,8 @@
51 51
   // if Kc is chosen well, the additional required power due to increased melting should be compensated.
52 52
   #define PID_ADD_EXTRUSION_RATE
53 53
   #if ENABLED(PID_ADD_EXTRUSION_RATE)
54
-    #define  DEFAULT_Kc (1) //heating power=Kc*(e_speed)
54
+    #define DEFAULT_Kc (100) //heating power=Kc*(e_speed)
55
+    #define LPQ_MAX_LEN 50
55 56
   #endif
56 57
 #endif
57 58
 

+ 2
- 1
Marlin/example_configurations/delta/biv2.5/Configuration_adv.h Прегледај датотеку

@@ -51,7 +51,8 @@
51 51
   // if Kc is chosen well, the additional required power due to increased melting should be compensated.
52 52
   #define PID_ADD_EXTRUSION_RATE
53 53
   #if ENABLED(PID_ADD_EXTRUSION_RATE)
54
-    #define  DEFAULT_Kc (1) //heating power=Kc*(e_speed)
54
+    #define DEFAULT_Kc (100) //heating power=Kc*(e_speed)
55
+    #define LPQ_MAX_LEN 50
55 56
   #endif
56 57
 #endif
57 58
 

+ 2
- 1
Marlin/example_configurations/delta/generic/Configuration_adv.h Прегледај датотеку

@@ -51,7 +51,8 @@
51 51
   // if Kc is chosen well, the additional required power due to increased melting should be compensated.
52 52
   #define PID_ADD_EXTRUSION_RATE
53 53
   #if ENABLED(PID_ADD_EXTRUSION_RATE)
54
-    #define  DEFAULT_Kc (1) //heating power=Kc*(e_speed)
54
+    #define DEFAULT_Kc (100) //heating power=Kc*(e_speed)
55
+    #define LPQ_MAX_LEN 50
55 56
   #endif
56 57
 #endif
57 58
 

+ 2
- 1
Marlin/example_configurations/delta/kossel_mini/Configuration_adv.h Прегледај датотеку

@@ -51,7 +51,8 @@
51 51
   // if Kc is chosen well, the additional required power due to increased melting should be compensated.
52 52
   #define PID_ADD_EXTRUSION_RATE
53 53
   #if ENABLED(PID_ADD_EXTRUSION_RATE)
54
-    #define  DEFAULT_Kc (1) //heating power=Kc*(e_speed)
54
+    #define DEFAULT_Kc (100) //heating power=Kc*(e_speed)
55
+    #define LPQ_MAX_LEN 50
55 56
   #endif
56 57
 #endif
57 58
 

+ 2
- 1
Marlin/example_configurations/delta/kossel_pro/Configuration_adv.h Прегледај датотеку

@@ -55,7 +55,8 @@
55 55
   // if Kc is chosen well, the additional required power due to increased melting should be compensated.
56 56
   #define PID_ADD_EXTRUSION_RATE
57 57
   #if ENABLED(PID_ADD_EXTRUSION_RATE)
58
-    #define  DEFAULT_Kc (1) //heating power=Kc*(e_speed)
58
+    #define DEFAULT_Kc (100) //heating power=Kc*(e_speed)
59
+    #define LPQ_MAX_LEN 50
59 60
   #endif
60 61
 #endif
61 62
 

+ 2
- 1
Marlin/example_configurations/makibox/Configuration_adv.h Прегледај датотеку

@@ -51,7 +51,8 @@
51 51
   // if Kc is chosen well, the additional required power due to increased melting should be compensated.
52 52
   #define PID_ADD_EXTRUSION_RATE
53 53
   #if ENABLED(PID_ADD_EXTRUSION_RATE)
54
-    #define  DEFAULT_Kc (1) //heating power=Kc*(e_speed)
54
+    #define DEFAULT_Kc (100) //heating power=Kc*(e_speed)
55
+    #define LPQ_MAX_LEN 50
55 56
   #endif
56 57
 #endif
57 58
 

+ 2
- 1
Marlin/example_configurations/tvrrug/Round2/Configuration_adv.h Прегледај датотеку

@@ -51,7 +51,8 @@
51 51
   // if Kc is chosen well, the additional required power due to increased melting should be compensated.
52 52
   #define PID_ADD_EXTRUSION_RATE
53 53
   #if ENABLED(PID_ADD_EXTRUSION_RATE)
54
-    #define  DEFAULT_Kc (1) //heating power=Kc*(e_speed)
54
+    #define DEFAULT_Kc (100) //heating power=Kc*(e_speed)
55
+    #define LPQ_MAX_LEN 50
55 56
   #endif
56 57
 #endif
57 58
 

+ 1
- 0
Marlin/language.h Прегледај датотеку

@@ -200,6 +200,7 @@
200 200
 #define MSG_PID_DEBUG_PTERM                 " pTerm "
201 201
 #define MSG_PID_DEBUG_ITERM                 " iTerm "
202 202
 #define MSG_PID_DEBUG_DTERM                 " dTerm "
203
+#define MSG_PID_DEBUG_CTERM                 " cTerm "
203 204
 #define MSG_INVALID_EXTRUDER_NUM            " - Invalid extruder number !"
204 205
 
205 206
 #define MSG_HEATER_BED                      "bed"

+ 39
- 12
Marlin/temperature.cpp Прегледај датотеку

@@ -99,6 +99,12 @@ static volatile bool temp_meas_ready = false;
99 99
   static float pTerm[EXTRUDERS];
100 100
   static float iTerm[EXTRUDERS];
101 101
   static float dTerm[EXTRUDERS];
102
+  #if ENABLED(PID_ADD_EXTRUSION_RATE)
103
+    static float cTerm[EXTRUDERS];
104
+    static long last_position[EXTRUDERS];
105
+    static long lpq[LPQ_MAX_LEN];
106
+    static int lpq_ptr = 0;
107
+  #endif
102 108
   //int output;
103 109
   static float pid_error[EXTRUDERS];
104 110
   static float temp_iState_min[EXTRUDERS];
@@ -357,6 +363,9 @@ void updatePID() {
357 363
   #if ENABLED(PIDTEMP)
358 364
     for (int e = 0; e < EXTRUDERS; e++) {
359 365
       temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / PID_PARAM(Ki,e);
366
+      #if ENABLED(PID_ADD_EXTRUSION_RATE)
367
+        last_position[e] = 0;
368
+      #endif
360 369
     }
361 370
   #endif
362 371
   #if ENABLED(PIDTEMPBED)
@@ -497,6 +506,23 @@ float get_pid_output(int e) {
497 506
         iTerm[e] = PID_PARAM(Ki,e) * temp_iState[e];
498 507
 
499 508
         pid_output = pTerm[e] + iTerm[e] - dTerm[e];
509
+
510
+        #if ENABLED(PID_ADD_EXTRUSION_RATE)
511
+          cTerm[e] = 0;
512
+          if (e == active_extruder) {
513
+            long e_position = st_get_position(E_AXIS);
514
+            if (e_position > last_position[e]) {
515
+              lpq[lpq_ptr++] = e_position - last_position[e];
516
+              last_position[e] = e_position;
517
+            } else {
518
+              lpq[lpq_ptr++] = 0;
519
+            }
520
+            if (lpq_ptr >= lpq_len) lpq_ptr = 0;
521
+            cTerm[e] = (lpq[lpq_ptr] / axis_steps_per_unit[E_AXIS]) * Kc;
522
+            pid_output += cTerm[e];
523
+          }
524
+        #endif //PID_ADD_EXTRUSION_RATE
525
+
500 526
         if (pid_output > PID_MAX) {
501 527
           if (pid_error[e] > 0) temp_iState[e] -= pid_error[e]; // conditional un-integration
502 528
           pid_output = PID_MAX;
@@ -512,18 +538,16 @@ float get_pid_output(int e) {
512 538
 
513 539
     #if ENABLED(PID_DEBUG)
514 540
       SERIAL_ECHO_START;
515
-      SERIAL_ECHO(MSG_PID_DEBUG);
516
-      SERIAL_ECHO(e);
517
-      SERIAL_ECHO(MSG_PID_DEBUG_INPUT);
518
-      SERIAL_ECHO(current_temperature[e]);
519
-      SERIAL_ECHO(MSG_PID_DEBUG_OUTPUT);
520
-      SERIAL_ECHO(pid_output);
521
-      SERIAL_ECHO(MSG_PID_DEBUG_PTERM);
522
-      SERIAL_ECHO(pTerm[e]);
523
-      SERIAL_ECHO(MSG_PID_DEBUG_ITERM);
524
-      SERIAL_ECHO(iTerm[e]);
525
-      SERIAL_ECHO(MSG_PID_DEBUG_DTERM);
526
-      SERIAL_ECHOLN(dTerm[e]);
541
+      SERIAL_ECHOPAIR(MSG_PID_DEBUG, e);
542
+      SERIAL_ECHOPAIR(MSG_PID_DEBUG_INPUT, current_temperature[e]);
543
+      SERIAL_ECHOPAIR(MSG_PID_DEBUG_OUTPUT, pid_output);
544
+      SERIAL_ECHOPAIR(MSG_PID_DEBUG_PTERM, pTerm[e]);
545
+      SERIAL_ECHOPAIR(MSG_PID_DEBUG_ITERM, iTerm[e]);
546
+      SERIAL_ECHOPAIR(MSG_PID_DEBUG_DTERM, dTerm[e]);
547
+      #if ENABLED(PID_ADD_EXTRUSION_RATE)
548
+        SERIAL_ECHOPAIR(MSG_PID_DEBUG_CTERM, cTerm[e]);
549
+      #endif
550
+      SERIAL_EOL;
527 551
     #endif //PID_DEBUG
528 552
 
529 553
   #else /* PID off */
@@ -837,6 +861,9 @@ void tp_init() {
837 861
     #if ENABLED(PIDTEMP)
838 862
       temp_iState_min[e] = 0.0;
839 863
       temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / PID_PARAM(Ki,e);
864
+      #if ENABLED(PID_ADD_EXTRUSION_RATE)
865
+        last_position[e] = 0;
866
+      #endif
840 867
     #endif //PIDTEMP
841 868
     #if ENABLED(PIDTEMPBED)
842 869
       temp_iState_min_bed = 0.0;

Loading…
Откажи
Сачувај