Browse Source

🚩 MPC update (#24253)

tombrazier 2 years ago
parent
commit
6ecf52f196
No account linked to committer's email address

+ 3
- 3
Marlin/Configuration.h View File

688
     //#define MPC_FAN_0_ACTIVE_HOTEND
688
     //#define MPC_FAN_0_ACTIVE_HOTEND
689
   #endif
689
   #endif
690
 
690
 
691
-  #define FILAMENT_HEAT_CAPACITY_PERMM 5.6e-3f        // 0.0056 J/K/mm for 1.75mm PLA (0.0149 J/K/mm for 2.85mm PLA).
692
-  //#define FILAMENT_HEAT_CAPACITY_PERMM 3.6e-3f      // 0.0036 J/K/mm for 1.75mm PETG (0.0094 J/K/mm for 2.85mm PETG).
691
+  #define FILAMENT_HEAT_CAPACITY_PERMM { 5.6e-3f }    // 0.0056 J/K/mm for 1.75mm PLA (0.0149 J/K/mm for 2.85mm PLA).
692
+  //#define FILAMENT_HEAT_CAPACITY_PERMM { 3.6e-3f }  // 0.0036 J/K/mm for 1.75mm PETG (0.0094 J/K/mm for 2.85mm PETG).
693
 
693
 
694
   // Advanced options
694
   // Advanced options
695
   #define MPC_SMOOTHING_FACTOR 0.5f                   // (0.0...1.0) Noisy temperature sensors may need a lower value for stabilization.
695
   #define MPC_SMOOTHING_FACTOR 0.5f                   // (0.0...1.0) Noisy temperature sensors may need a lower value for stabilization.
696
   #define MPC_MIN_AMBIENT_CHANGE 1.0f                 // (K/s) Modeled ambient temperature rate of change, when correcting model inaccuracies.
696
   #define MPC_MIN_AMBIENT_CHANGE 1.0f                 // (K/s) Modeled ambient temperature rate of change, when correcting model inaccuracies.
697
   #define MPC_STEADYSTATE 0.5f                        // (K/s) Temperature change rate for steady state logic to be enforced.
697
   #define MPC_STEADYSTATE 0.5f                        // (K/s) Temperature change rate for steady state logic to be enforced.
698
 
698
 
699
-  #define MPC_TUNING_POS { X_CENTER, Y_CENTER, 1.0f } // (mm) M306 Autotuning position, ideally bed center just above the surface.
699
+  #define MPC_TUNING_POS { X_CENTER, Y_CENTER, 1.0f } // (mm) M306 Autotuning position, ideally bed center at first layer height.
700
   #define MPC_TUNING_END_Z 10.0f                      // (mm) M306 Autotuning final Z position.
700
   #define MPC_TUNING_END_Z 10.0f                      // (mm) M306 Autotuning final Z position.
701
 #endif
701
 #endif
702
 
702
 

+ 6
- 2
Marlin/src/gcode/temp/M306.cpp View File

36
  *  C<joules/kelvin>          Block heat capacity.
36
  *  C<joules/kelvin>          Block heat capacity.
37
  *  E<extruder>               Extruder number to set. (Default: E0)
37
  *  E<extruder>               Extruder number to set. (Default: E0)
38
  *  F<watts/kelvin>           Ambient heat transfer coefficient (fan on full).
38
  *  F<watts/kelvin>           Ambient heat transfer coefficient (fan on full).
39
+ *  H<joules/kelvin/mm>       Filament heat capacity per mm.
39
  *  P<watts>                  Heater power.
40
  *  P<watts>                  Heater power.
40
  *  R<kelvin/second/kelvin>   Sensor responsiveness (= transfer coefficient / heat capcity).
41
  *  R<kelvin/second/kelvin>   Sensor responsiveness (= transfer coefficient / heat capcity).
41
  */
42
  */
43
 void GcodeSuite::M306() {
44
 void GcodeSuite::M306() {
44
   if (parser.seen_test('T')) { thermalManager.MPC_autotune(); return; }
45
   if (parser.seen_test('T')) { thermalManager.MPC_autotune(); return; }
45
 
46
 
46
-  if (parser.seen("ACFPR")) {
47
+  if (parser.seen("ACFPRH")) {
47
     const heater_id_t hid = (heater_id_t)parser.intval('E', 0);
48
     const heater_id_t hid = (heater_id_t)parser.intval('E', 0);
48
     MPC_t &constants = thermalManager.temp_hotend[hid].constants;
49
     MPC_t &constants = thermalManager.temp_hotend[hid].constants;
49
     if (parser.seenval('P')) constants.heater_power = parser.value_float();
50
     if (parser.seenval('P')) constants.heater_power = parser.value_float();
53
     #if ENABLED(MPC_INCLUDE_FAN)
54
     #if ENABLED(MPC_INCLUDE_FAN)
54
       if (parser.seenval('F')) constants.fan255_adjustment = parser.value_float() - constants.ambient_xfer_coeff_fan0;
55
       if (parser.seenval('F')) constants.fan255_adjustment = parser.value_float() - constants.ambient_xfer_coeff_fan0;
55
     #endif
56
     #endif
57
+    if (parser.seenval('H')) constants.filament_heat_capacity_permm = parser.value_float();
56
     return;
58
     return;
57
   }
59
   }
58
 
60
 
70
     SERIAL_ECHOPAIR_F(" R", constants.sensor_responsiveness, 4);
72
     SERIAL_ECHOPAIR_F(" R", constants.sensor_responsiveness, 4);
71
     SERIAL_ECHOPAIR_F(" A", constants.ambient_xfer_coeff_fan0, 4);
73
     SERIAL_ECHOPAIR_F(" A", constants.ambient_xfer_coeff_fan0, 4);
72
     #if ENABLED(MPC_INCLUDE_FAN)
74
     #if ENABLED(MPC_INCLUDE_FAN)
73
-      SERIAL_ECHOLNPAIR_F(" F", constants.ambient_xfer_coeff_fan0 + constants.fan255_adjustment, 4);
75
+      SERIAL_ECHOPAIR_F(" F", constants.ambient_xfer_coeff_fan0 + constants.fan255_adjustment, 4);
74
     #endif
76
     #endif
77
+    SERIAL_ECHOPAIR_F(" M", constants.filament_heat_capacity_permm, 4);
78
+    SERIAL_EOL();
75
   }
79
   }
76
 }
80
 }
77
 
81
 

+ 3
- 0
Marlin/src/module/settings.cpp View File

3319
     #if ENABLED(MPC_INCLUDE_FAN)
3319
     #if ENABLED(MPC_INCLUDE_FAN)
3320
       constexpr float _mpc_ambient_xfer_coeff_fan255[] = MPC_AMBIENT_XFER_COEFF_FAN255;
3320
       constexpr float _mpc_ambient_xfer_coeff_fan255[] = MPC_AMBIENT_XFER_COEFF_FAN255;
3321
     #endif
3321
     #endif
3322
+    constexpr float _filament_heat_capacity_permm[] = FILAMENT_HEAT_CAPACITY_PERMM;
3322
 
3323
 
3323
     static_assert(COUNT(_mpc_heater_power) == HOTENDS, "MPC_HEATER_POWER must have HOTENDS items.");
3324
     static_assert(COUNT(_mpc_heater_power) == HOTENDS, "MPC_HEATER_POWER must have HOTENDS items.");
3324
     static_assert(COUNT(_mpc_block_heat_capacity) == HOTENDS, "MPC_BLOCK_HEAT_CAPACITY must have HOTENDS items.");
3325
     static_assert(COUNT(_mpc_block_heat_capacity) == HOTENDS, "MPC_BLOCK_HEAT_CAPACITY must have HOTENDS items.");
3327
     #if ENABLED(MPC_INCLUDE_FAN)
3328
     #if ENABLED(MPC_INCLUDE_FAN)
3328
       static_assert(COUNT(_mpc_ambient_xfer_coeff_fan255) == HOTENDS, "MPC_AMBIENT_XFER_COEFF_FAN255 must have HOTENDS items.");
3329
       static_assert(COUNT(_mpc_ambient_xfer_coeff_fan255) == HOTENDS, "MPC_AMBIENT_XFER_COEFF_FAN255 must have HOTENDS items.");
3329
     #endif
3330
     #endif
3331
+    static_assert(COUNT(_filament_heat_capacity_permm) == HOTENDS, "FILAMENT_HEAT_CAPACITY_PERMM must have HOTENDS items.");
3330
 
3332
 
3331
     HOTEND_LOOP() {
3333
     HOTEND_LOOP() {
3332
       thermalManager.temp_hotend[e].constants.heater_power = _mpc_heater_power[e];
3334
       thermalManager.temp_hotend[e].constants.heater_power = _mpc_heater_power[e];
3336
       #if ENABLED(MPC_INCLUDE_FAN)
3338
       #if ENABLED(MPC_INCLUDE_FAN)
3337
         thermalManager.temp_hotend[e].constants.fan255_adjustment = _mpc_ambient_xfer_coeff_fan255[e] - _mpc_ambient_xfer_coeff[e];
3339
         thermalManager.temp_hotend[e].constants.fan255_adjustment = _mpc_ambient_xfer_coeff_fan255[e] - _mpc_ambient_xfer_coeff[e];
3338
       #endif
3340
       #endif
3341
+      thermalManager.temp_hotend[e].constants.filament_heat_capacity_permm = _filament_heat_capacity_permm[e];
3339
     }
3342
     }
3340
   #endif
3343
   #endif
3341
 
3344
 

+ 3
- 3
Marlin/src/module/temperature.cpp View File

994
     float asymp_temp = (t2 * t2 - t1 * t3) / (2 * t2 - t1 - t3),
994
     float asymp_temp = (t2 * t2 - t1 * t3) / (2 * t2 - t1 - t3),
995
           block_responsiveness = -log((t2 - asymp_temp) / (t1 - asymp_temp)) / (sample_distance * (sample_count >> 1));
995
           block_responsiveness = -log((t2 - asymp_temp) / (t1 - asymp_temp)) / (sample_distance * (sample_count >> 1));
996
 
996
 
997
-    constants.ambient_xfer_coeff_fan0 = constants.heater_power * MPC_MAX / 255 / (asymp_temp - ambient_temp);
997
+    constants.ambient_xfer_coeff_fan0 = constants.heater_power * (MPC_MAX) / 255 / (asymp_temp - ambient_temp);
998
     constants.fan255_adjustment = 0.0f;
998
     constants.fan255_adjustment = 0.0f;
999
     constants.block_heat_capacity = constants.ambient_xfer_coeff_fan0 / block_responsiveness;
999
     constants.block_heat_capacity = constants.ambient_xfer_coeff_fan0 / block_responsiveness;
1000
     constants.sensor_responsiveness = block_responsiveness / (1.0f - (ambient_temp - asymp_temp) * exp(-block_responsiveness * t1_time) / (t1 - asymp_temp));
1000
     constants.sensor_responsiveness = block_responsiveness / (1.0f - (ambient_temp - asymp_temp) * exp(-block_responsiveness * t1_time) / (t1 - asymp_temp));
1058
     #endif
1058
     #endif
1059
 
1059
 
1060
     // Calculate a new and better asymptotic temperature and re-evaluate the other constants
1060
     // Calculate a new and better asymptotic temperature and re-evaluate the other constants
1061
-    asymp_temp = ambient_temp + constants.heater_power / constants.ambient_xfer_coeff_fan0;
1061
+    asymp_temp = ambient_temp + constants.heater_power * (MPC_MAX) / 255 / constants.ambient_xfer_coeff_fan0;
1062
     block_responsiveness = -log((t2 - asymp_temp) / (t1 - asymp_temp)) / (sample_distance * (sample_count >> 1));
1062
     block_responsiveness = -log((t2 - asymp_temp) / (t1 - asymp_temp)) / (sample_distance * (sample_count >> 1));
1063
     constants.block_heat_capacity = constants.ambient_xfer_coeff_fan0 / block_responsiveness;
1063
     constants.block_heat_capacity = constants.ambient_xfer_coeff_fan0 / block_responsiveness;
1064
     constants.sensor_responsiveness = block_responsiveness / (1.0f - (ambient_temp - asymp_temp) * exp(-block_responsiveness * t1_time) / (t1 - asymp_temp));
1064
     constants.sensor_responsiveness = block_responsiveness / (1.0f - (ambient_temp - asymp_temp) * exp(-block_responsiveness * t1_time) / (t1 - asymp_temp));
1442
         if (fabs(e_speed) > planner.settings.max_feedrate_mm_s[E_AXIS])
1442
         if (fabs(e_speed) > planner.settings.max_feedrate_mm_s[E_AXIS])
1443
           mpc_e_position = e_position;
1443
           mpc_e_position = e_position;
1444
         else if (e_speed > 0.0f) {  // Ignore retract/recover moves
1444
         else if (e_speed > 0.0f) {  // Ignore retract/recover moves
1445
-          ambient_xfer_coeff += e_speed * FILAMENT_HEAT_CAPACITY_PERMM;
1445
+          ambient_xfer_coeff += e_speed * constants.filament_heat_capacity_permm;
1446
           mpc_e_position = e_position;
1446
           mpc_e_position = e_position;
1447
         }
1447
         }
1448
       }
1448
       }

+ 6
- 5
Marlin/src/module/temperature.h View File

96
 
96
 
97
 #if ENABLED(MPCTEMP)
97
 #if ENABLED(MPCTEMP)
98
   typedef struct {
98
   typedef struct {
99
-    float heater_power;             // M306 P
100
-    float block_heat_capacity;      // M306 C
101
-    float sensor_responsiveness;    // M306 R
102
-    float ambient_xfer_coeff_fan0;  // M306 A
99
+    float heater_power;                 // M306 P
100
+    float block_heat_capacity;          // M306 C
101
+    float sensor_responsiveness;        // M306 R
102
+    float ambient_xfer_coeff_fan0;      // M306 A
103
     #if ENABLED(MPC_INCLUDE_FAN)
103
     #if ENABLED(MPC_INCLUDE_FAN)
104
-      float fan255_adjustment;      // M306 F
104
+      float fan255_adjustment;          // M306 F
105
     #endif
105
     #endif
106
+    float filament_heat_capacity_permm; // M306 M
106
   } MPC_t;
107
   } MPC_t;
107
 #endif
108
 #endif
108
 
109
 

+ 2
- 1
buildroot/tests/BIGTREE_GTR_V1_0 View File

37
         MPC_BLOCK_HEAT_CAPACITY '{ 16.7f, 16.7f, 16.7f }' \
37
         MPC_BLOCK_HEAT_CAPACITY '{ 16.7f, 16.7f, 16.7f }' \
38
         MPC_SENSOR_RESPONSIVENESS '{ 0.22f, 0.22f, 0.22f }' \
38
         MPC_SENSOR_RESPONSIVENESS '{ 0.22f, 0.22f, 0.22f }' \
39
         MPC_AMBIENT_XFER_COEFF '{ 0.068f, 0.068f, 0.068f }' \
39
         MPC_AMBIENT_XFER_COEFF '{ 0.068f, 0.068f, 0.068f }' \
40
-        MPC_AMBIENT_XFER_COEFF_FAN255 '{ 0.097f, 0.097f, 0.097f }'
40
+        MPC_AMBIENT_XFER_COEFF_FAN255 '{ 0.097f, 0.097f, 0.097f }' \
41
+        FILAMENT_HEAT_CAPACITY_PERMM '{ 5.6e-3f, 3.6e-3f, 5.6e-3f }'
41
 opt_enable SWITCHING_TOOLHEAD TOOL_SENSOR MPCTEMP MPC_EDIT_MENU MPC_AUTOTUNE_MENU
42
 opt_enable SWITCHING_TOOLHEAD TOOL_SENSOR MPCTEMP MPC_EDIT_MENU MPC_AUTOTUNE_MENU
42
 opt_disable PIDTEMP
43
 opt_disable PIDTEMP
43
 exec_test $1 $2 "BigTreeTech GTR | MPC | Switching Toolhead | Tool Sensors" "$3"
44
 exec_test $1 $2 "BigTreeTech GTR | MPC | Switching Toolhead | Tool Sensors" "$3"

Loading…
Cancel
Save