Browse Source

Per-Hotend Default PIDs (#18483)

Scott Lahteine 4 years ago
parent
commit
70fa4c9323
No account linked to committer's email address

+ 3
- 0
Marlin/src/gcode/config/M301.cpp View File

@@ -30,6 +30,8 @@
30 30
 /**
31 31
  * M301: Set PID parameters P I D (and optionally C, L)
32 32
  *
33
+ *   E[extruder] Default: 0
34
+ *
33 35
  *   P[float] Kp term
34 36
  *   I[float] Ki term (unscaled)
35 37
  *   D[float] Kd term (unscaled)
@@ -65,6 +67,7 @@ void GcodeSuite::M301() {
65 67
     #endif
66 68
 
67 69
     thermalManager.updatePID();
70
+
68 71
     SERIAL_ECHO_START();
69 72
     #if ENABLED(PID_PARAMS_PER_HOTEND)
70 73
       SERIAL_ECHOPAIR(" e:", e); // specify extruder in serial output

+ 2
- 0
Marlin/src/inc/Conditionals_LCD.h View File

@@ -477,6 +477,8 @@
477 477
     #define HAS_MULTI_HOTEND 1
478 478
     #define HAS_HOTEND_OFFSET 1
479 479
   #endif
480
+#else
481
+  #undef PID_PARAMS_PER_HOTEND
480 482
 #endif
481 483
 
482 484
 // Helper macros for extruder and hotend arrays

+ 25
- 21
Marlin/src/inc/SanityCheck.h View File

@@ -1629,28 +1629,8 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal
1629 1629
 #endif
1630 1630
 
1631 1631
 /**
1632
- * Test Heater, Temp Sensor, and Extruder Pins; Sensor Type must also be set.
1632
+ * A Sensor ID has to be set for each heater
1633 1633
  */
1634
-#if !HAS_HEATER_0
1635
-  #error "HEATER_0_PIN not defined for this board."
1636
-#elif !ANY_PIN(TEMP_0, MAX6675_SS)
1637
-  #error "TEMP_0_PIN not defined for this board."
1638
-#elif ((defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)) && !PINS_EXIST(E0_STEP, E0_DIR))
1639
-  #error "E0_STEP_PIN or E0_DIR_PIN not defined for this board."
1640
-#elif ( !(defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)) && (!PINS_EXIST(E0_STEP, E0_DIR) || !HAS_E0_ENABLE))
1641
-  #error "E0_STEP_PIN, E0_DIR_PIN, or E0_ENABLE_PIN not defined for this board."
1642
-#elif EXTRUDERS && TEMP_SENSOR_0 == 0
1643
-  #error "TEMP_SENSOR_0 is required with any extruders."
1644
-#endif
1645
-
1646
-// Pins are required for heaters
1647
-#if ENABLED(HEATER_0_USES_MAX6675) && !PIN_EXISTS(MAX6675_SS)
1648
-  #error "MAX6675_SS_PIN (required for TEMP_SENSOR_0) not defined for this board."
1649
-#elif HAS_HOTEND && !HAS_TEMP_HOTEND
1650
-  #error "TEMP_0_PIN (required for TEMP_SENSOR_0) not defined for this board."
1651
-#elif EITHER(HAS_MULTI_HOTEND, HEATERS_PARALLEL) && !HAS_HEATER_1
1652
-  #error "HEATER_1_PIN not defined for this board."
1653
-#endif
1654 1634
 
1655 1635
 #if HAS_MULTI_HOTEND
1656 1636
   #if ENABLED(HEATER_1_USES_MAX6675) && !PIN_EXISTS(MAX6675_SS2)
@@ -1793,6 +1773,30 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal
1793 1773
 #endif
1794 1774
 
1795 1775
 /**
1776
+ * Test Heater, Temp Sensor, and Extruder Pins
1777
+ */
1778
+#if !HAS_HEATER_0
1779
+  #error "HEATER_0_PIN not defined for this board."
1780
+#elif !ANY_PIN(TEMP_0, MAX6675_SS)
1781
+  #error "TEMP_0_PIN not defined for this board."
1782
+#elif ((defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)) && !PINS_EXIST(E0_STEP, E0_DIR))
1783
+  #error "E0_STEP_PIN or E0_DIR_PIN not defined for this board."
1784
+#elif ( !(defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)) && (!PINS_EXIST(E0_STEP, E0_DIR) || !HAS_E0_ENABLE))
1785
+  #error "E0_STEP_PIN, E0_DIR_PIN, or E0_ENABLE_PIN not defined for this board."
1786
+#elif EXTRUDERS && TEMP_SENSOR_0 == 0
1787
+  #error "TEMP_SENSOR_0 is required if there are any extruders."
1788
+#endif
1789
+
1790
+// Pins are required for heaters
1791
+#if ENABLED(HEATER_0_USES_MAX6675) && !PIN_EXISTS(MAX6675_SS)
1792
+  #error "MAX6675_SS_PIN (required for TEMP_SENSOR_0) not defined for this board."
1793
+#elif HAS_HOTEND && !HAS_TEMP_HOTEND
1794
+  #error "TEMP_0_PIN (required for TEMP_SENSOR_0) not defined for this board."
1795
+#elif EITHER(HAS_MULTI_HOTEND, HEATERS_PARALLEL) && !HAS_HEATER_1
1796
+  #error "HEATER_1_PIN is not defined. TEMP_SENSOR_1 might not be set, or the board (not EEB / EEF?) doesn't define a pin."
1797
+#endif
1798
+
1799
+/**
1796 1800
  * Temperature status LEDs
1797 1801
  */
1798 1802
 #if ENABLED(TEMP_STAT_LEDS) && !ANY_PIN(STAT_LED_RED, STAT_LED_BLUE)

+ 4
- 8
Marlin/src/lcd/menu/menu_advanced.cpp View File

@@ -205,16 +205,12 @@ void menu_cancelobject();
205 205
   // Helpers for editing PID Ki & Kd values
206 206
   // grab the PID value out of the temp variable; scale it; then update the PID driver
207 207
   void copy_and_scalePID_i(int16_t e) {
208
-    #if DISABLED(PID_PARAMS_PER_HOTEND) || HOTENDS == 1
209
-      UNUSED(e);
210
-    #endif
208
+    TERN(PID_PARAMS_PER_HOTEND,,UNUSED(e));
211 209
     PID_PARAM(Ki, e) = scalePID_i(raw_Ki);
212 210
     thermalManager.updatePID();
213 211
   }
214 212
   void copy_and_scalePID_d(int16_t e) {
215
-    #if DISABLED(PID_PARAMS_PER_HOTEND) || HOTENDS == 1
216
-      UNUSED(e);
217
-    #endif
213
+    TERN(PID_PARAMS_PER_HOTEND,,UNUSED(e));
218 214
     PID_PARAM(Kd, e) = scalePID_d(raw_Kd);
219 215
     thermalManager.updatePID();
220 216
   }
@@ -239,7 +235,7 @@ void menu_cancelobject();
239 235
 
240 236
 #if HAS_HOTEND
241 237
   DEFINE_PIDTEMP_FUNCS(0);
242
-  #if BOTH(HAS_MULTI_HOTEND, PID_PARAMS_PER_HOTEND)
238
+  #if ENABLED(PID_PARAMS_PER_HOTEND)
243 239
     REPEAT_S(1, HOTENDS, DEFINE_PIDTEMP_FUNCS)
244 240
   #endif
245 241
 #endif
@@ -314,7 +310,7 @@ void menu_cancelobject();
314 310
     #endif
315 311
 
316 312
     PID_EDIT_MENU_ITEMS(0);
317
-    #if BOTH(HAS_MULTI_HOTEND, PID_PARAMS_PER_HOTEND)
313
+    #if ENABLED(PID_PARAMS_PER_HOTEND)
318 314
       REPEAT_S(1, HOTENDS, PID_EDIT_MENU_ITEMS)
319 315
     #endif
320 316
 

+ 53
- 6
Marlin/src/module/configuration_store.cpp View File

@@ -2587,12 +2587,59 @@ void MarlinSettings::reset() {
2587 2587
   //
2588 2588
 
2589 2589
   #if ENABLED(PIDTEMP)
2590
+    #if ENABLED(PID_PARAMS_PER_HOTEND)
2591
+      constexpr float defKp[] =
2592
+        #ifdef DEFAULT_Kp_LIST
2593
+          DEFAULT_Kp_LIST
2594
+        #else
2595
+          ARRAY_BY_HOTENDS1(DEFAULT_Kp)
2596
+        #endif
2597
+      , defKi[] =
2598
+        #ifdef DEFAULT_Ki_LIST
2599
+          DEFAULT_Ki_LIST
2600
+        #else
2601
+          ARRAY_BY_HOTENDS1(DEFAULT_Ki)
2602
+        #endif
2603
+      , defKd[] =
2604
+        #ifdef DEFAULT_Kd_LIST
2605
+          DEFAULT_Kd_LIST
2606
+        #else
2607
+          ARRAY_BY_HOTENDS1(DEFAULT_Kd)
2608
+        #endif
2609
+      ;
2610
+      static_assert(WITHIN(COUNT(defKp), 1, HOTENDS), "DEFAULT_Kp_LIST must have between 1 and HOTENDS items.");
2611
+      static_assert(WITHIN(COUNT(defKi), 1, HOTENDS), "DEFAULT_Ki_LIST must have between 1 and HOTENDS items.");
2612
+      static_assert(WITHIN(COUNT(defKd), 1, HOTENDS), "DEFAULT_Kd_LIST must have between 1 and HOTENDS items.");
2613
+      #if ENABLED(PID_EXTRUSION_SCALING)
2614
+        constexpr float defKc[] =
2615
+          #ifdef DEFAULT_Kc_LIST
2616
+            DEFAULT_Kc_LIST
2617
+          #else
2618
+            ARRAY_BY_HOTENDS1(DEFAULT_Kc)
2619
+          #endif
2620
+        ;
2621
+        static_assert(WITHIN(COUNT(defKc), 1, HOTENDS), "DEFAULT_Kc_LIST must have between 1 and HOTENDS items.");
2622
+      #endif
2623
+      #if ENABLED(PID_FAN_SCALING)
2624
+        constexpr float defKf[] =
2625
+          #ifdef DEFAULT_Kf_LIST
2626
+            DEFAULT_Kf_LIST
2627
+          #else
2628
+            ARRAY_BY_HOTENDS1(DEFAULT_Kf)
2629
+          #endif
2630
+        ;
2631
+        static_assert(WITHIN(COUNT(defKf), 1, HOTENDS), "DEFAULT_Kf_LIST must have between 1 and HOTENDS items.");
2632
+      #endif
2633
+      #define PID_DEFAULT(N,E) def##N[E]
2634
+    #else
2635
+      #define PID_DEFAULT(N,E) DEFAULT_##N
2636
+    #endif
2590 2637
     HOTEND_LOOP() {
2591
-      PID_PARAM(Kp, e) = float(DEFAULT_Kp);
2592
-      PID_PARAM(Ki, e) = scalePID_i(DEFAULT_Ki);
2593
-      PID_PARAM(Kd, e) = scalePID_d(DEFAULT_Kd);
2594
-      TERN_(PID_EXTRUSION_SCALING, PID_PARAM(Kc, e) = DEFAULT_Kc);
2595
-      TERN_(PID_FAN_SCALING, PID_PARAM(Kf, e) = DEFAULT_Kf);
2638
+      PID_PARAM(Kp, e) = float(PID_DEFAULT(Kp, ALIM(e, defKp)));
2639
+      PID_PARAM(Ki, e) = scalePID_i(PID_DEFAULT(Ki, ALIM(e, defKi)));
2640
+      PID_PARAM(Kd, e) = scalePID_d(PID_DEFAULT(Kd, ALIM(e, defKd)));
2641
+      TERN_(PID_EXTRUSION_SCALING, PID_PARAM(Kc, e) = float(PID_DEFAULT(Kc, ALIM(e, defKc))));
2642
+      TERN_(PID_FAN_SCALING, PID_PARAM(Kf, e) = float(PID_DEFAULT(Kf, ALIM(e, defKf))));
2596 2643
     }
2597 2644
   #endif
2598 2645
 
@@ -3140,7 +3187,7 @@ void MarlinSettings::reset() {
3140 3187
         HOTEND_LOOP() {
3141 3188
           CONFIG_ECHO_START();
3142 3189
           SERIAL_ECHOPAIR_P(
3143
-            #if BOTH(HAS_MULTI_HOTEND, PID_PARAMS_PER_HOTEND)
3190
+            #if ENABLED(PID_PARAMS_PER_HOTEND)
3144 3191
               PSTR("  M301 E"), e,
3145 3192
               SP_P_STR
3146 3193
             #else

+ 9
- 26
Marlin/src/module/temperature.h View File

@@ -37,13 +37,8 @@
37 37
   #define SOFT_PWM_SCALE 0
38 38
 #endif
39 39
 
40
-#if HOTENDS <= 1
41
-  #define HOTEND_INDEX  0
42
-  #define E_NAME
43
-#else
44
-  #define HOTEND_INDEX  e
45
-  #define E_NAME e
46
-#endif
40
+#define HOTEND_INDEX TERN(HAS_MULTI_HOTEND, e, 0)
41
+#define E_NAME TERN_(HAS_MULTI_HOTEND, e)
47 42
 
48 43
 // Identifiers for other heaters
49 44
 typedef enum : int8_t {
@@ -74,30 +69,18 @@ hotend_pid_t;
74 69
   typedef IF<(LPQ_MAX_LEN > 255), uint16_t, uint8_t>::type lpq_ptr_t;
75 70
 #endif
76 71
 
72
+#define PID_PARAM(F,H) _PID_##F(TERN(PID_PARAMS_PER_HOTEND, H, 0))
73
+#define _PID_Kp(H) TERN(PIDTEMP, Temperature::temp_hotend[H].pid.Kp, NAN)
74
+#define _PID_Ki(H) TERN(PIDTEMP, Temperature::temp_hotend[H].pid.Ki, NAN)
75
+#define _PID_Kd(H) TERN(PIDTEMP, Temperature::temp_hotend[H].pid.Kd, NAN)
77 76
 #if ENABLED(PIDTEMP)
78
-  #define _PID_Kp(H) Temperature::temp_hotend[H].pid.Kp
79
-  #define _PID_Ki(H) Temperature::temp_hotend[H].pid.Ki
80
-  #define _PID_Kd(H) Temperature::temp_hotend[H].pid.Kd
81
-  #if ENABLED(PID_EXTRUSION_SCALING)
82
-    #define _PID_Kc(H) Temperature::temp_hotend[H].pid.Kc
83
-  #else
84
-    #define _PID_Kc(H) 1
85
-  #endif
86
-
87
-  #if ENABLED(PID_FAN_SCALING)
88
-    #define _PID_Kf(H) Temperature::temp_hotend[H].pid.Kf
89
-  #else
90
-    #define _PID_Kf(H) 0
91
-  #endif
77
+  #define _PID_Kc(H) TERN(PID_EXTRUSION_SCALING, Temperature::temp_hotend[H].pid.Kc, 1)
78
+  #define _PID_Kf(H) TERN(PID_FAN_SCALING,       Temperature::temp_hotend[H].pid.Kf, 0)
92 79
 #else
93
-  #define _PID_Kp(H) NAN
94
-  #define _PID_Ki(H) NAN
95
-  #define _PID_Kd(H) NAN
96 80
   #define _PID_Kc(H) 1
81
+  #define _PID_Kf(H) 0
97 82
 #endif
98 83
 
99
-#define PID_PARAM(F,H) _PID_##F(H)
100
-
101 84
 /**
102 85
  * States for ADC reading in the ISR
103 86
  */

Loading…
Cancel
Save