浏览代码

Optimize target_extruder, ignore T with mixing (#12432)

* Optimize target_extruder, ignore T with mixing
* Give G-code Tn parity with tool_change
Scott Lahteine 6 年前
父节点
当前提交
d2bb53702a
没有帐户链接到提交者的电子邮件

+ 8
- 5
Marlin/src/gcode/config/M200-M205.cpp 查看文件

34
    */
34
    */
35
   void GcodeSuite::M200() {
35
   void GcodeSuite::M200() {
36
 
36
 
37
-    if (get_target_extruder_from_command()) return;
37
+    const int8_t target_extruder = get_target_extruder_from_command();
38
+    if (target_extruder < 0) return;
38
 
39
 
39
     if (parser.seen('D')) {
40
     if (parser.seen('D')) {
40
       // setting any extruder filament size disables volumetric on the assumption that
41
       // setting any extruder filament size disables volumetric on the assumption that
55
  */
56
  */
56
 void GcodeSuite::M201() {
57
 void GcodeSuite::M201() {
57
 
58
 
58
-  GET_TARGET_EXTRUDER();
59
+  const int8_t target_extruder = get_target_extruder_from_command();
60
+  if (target_extruder < 0) return;
59
 
61
 
60
   LOOP_XYZE(i) {
62
   LOOP_XYZE(i) {
61
     if (parser.seen(axis_codes[i])) {
63
     if (parser.seen(axis_codes[i])) {
62
-      const uint8_t a = i + (i == E_AXIS ? TARGET_EXTRUDER : 0);
64
+      const uint8_t a = (i == E_AXIS ? E_AXIS_N(target_extruder) : i);
63
       planner.settings.max_acceleration_mm_per_s2[a] = parser.value_axis_units((AxisEnum)a);
65
       planner.settings.max_acceleration_mm_per_s2[a] = parser.value_axis_units((AxisEnum)a);
64
     }
66
     }
65
   }
67
   }
74
  */
76
  */
75
 void GcodeSuite::M203() {
77
 void GcodeSuite::M203() {
76
 
78
 
77
-  GET_TARGET_EXTRUDER();
79
+  const int8_t target_extruder = get_target_extruder_from_command();
80
+  if (target_extruder < 0) return;
78
 
81
 
79
   LOOP_XYZE(i)
82
   LOOP_XYZE(i)
80
     if (parser.seen(axis_codes[i])) {
83
     if (parser.seen(axis_codes[i])) {
81
-      const uint8_t a = i + (i == E_AXIS ? TARGET_EXTRUDER : 0);
84
+      const uint8_t a = (i == E_AXIS ? E_AXIS_N(target_extruder) : i);
82
       planner.settings.max_feedrate_mm_s[a] = parser.value_axis_units((AxisEnum)a);
85
       planner.settings.max_feedrate_mm_s[a] = parser.value_axis_units((AxisEnum)a);
83
     }
86
     }
84
 }
87
 }

+ 3
- 1
Marlin/src/gcode/config/M218.cpp 查看文件

40
  *   Z<zoffset>
40
  *   Z<zoffset>
41
  */
41
  */
42
 void GcodeSuite::M218() {
42
 void GcodeSuite::M218() {
43
-  if (get_target_extruder_from_command() || target_extruder == 0) return;
43
+
44
+  const int8_t target_extruder = get_target_extruder_from_command();
45
+  if (target_extruder < 0) return;
44
 
46
 
45
   if (parser.seenval('X')) hotend_offset[X_AXIS][target_extruder] = parser.value_linear_units();
47
   if (parser.seenval('X')) hotend_offset[X_AXIS][target_extruder] = parser.value_linear_units();
46
   if (parser.seenval('Y')) hotend_offset[Y_AXIS][target_extruder] = parser.value_linear_units();
48
   if (parser.seenval('Y')) hotend_offset[Y_AXIS][target_extruder] = parser.value_linear_units();

+ 4
- 1
Marlin/src/gcode/config/M221.cpp 查看文件

27
  * M221: Set extrusion percentage (M221 T0 S95)
27
  * M221: Set extrusion percentage (M221 T0 S95)
28
  */
28
  */
29
 void GcodeSuite::M221() {
29
 void GcodeSuite::M221() {
30
-  if (get_target_extruder_from_command()) return;
30
+
31
+  const int8_t target_extruder = get_target_extruder_from_command();
32
+  if (target_extruder < 0) return;
33
+
31
   if (parser.seenval('S')) {
34
   if (parser.seenval('S')) {
32
     planner.flow_percentage[target_extruder] = parser.value_int();
35
     planner.flow_percentage[target_extruder] = parser.value_int();
33
     planner.refresh_e_factor(target_extruder);
36
     planner.refresh_e_factor(target_extruder);

+ 7
- 6
Marlin/src/gcode/config/M92.cpp 查看文件

31
  */
31
  */
32
 void GcodeSuite::M92() {
32
 void GcodeSuite::M92() {
33
 
33
 
34
-  GET_TARGET_EXTRUDER();
34
+  const int8_t target_extruder = get_target_extruder_from_command();
35
+  if (target_extruder < 0) return;
35
 
36
 
36
   LOOP_XYZE(i) {
37
   LOOP_XYZE(i) {
37
     if (parser.seen(axis_codes[i])) {
38
     if (parser.seen(axis_codes[i])) {
38
       if (i == E_AXIS) {
39
       if (i == E_AXIS) {
39
-        const float value = parser.value_per_axis_units((AxisEnum)(E_AXIS + TARGET_EXTRUDER));
40
+        const float value = parser.value_per_axis_units((AxisEnum)(E_AXIS_N(target_extruder)));
40
         if (value < 20) {
41
         if (value < 20) {
41
-          float factor = planner.settings.axis_steps_per_mm[E_AXIS + TARGET_EXTRUDER] / value; // increase e constants if M92 E14 is given for netfab.
42
+          float factor = planner.settings.axis_steps_per_mm[E_AXIS_N(target_extruder)] / value; // increase e constants if M92 E14 is given for netfab.
42
           #if HAS_CLASSIC_JERK && (DISABLED(JUNCTION_DEVIATION) || DISABLED(LIN_ADVANCE))
43
           #if HAS_CLASSIC_JERK && (DISABLED(JUNCTION_DEVIATION) || DISABLED(LIN_ADVANCE))
43
             planner.max_jerk[E_AXIS] *= factor;
44
             planner.max_jerk[E_AXIS] *= factor;
44
           #endif
45
           #endif
45
-          planner.settings.max_feedrate_mm_s[E_AXIS + TARGET_EXTRUDER] *= factor;
46
-          planner.max_acceleration_steps_per_s2[E_AXIS + TARGET_EXTRUDER] *= factor;
46
+          planner.settings.max_feedrate_mm_s[E_AXIS_N(target_extruder)] *= factor;
47
+          planner.max_acceleration_steps_per_s2[E_AXIS_N(target_extruder)] *= factor;
47
         }
48
         }
48
-        planner.settings.axis_steps_per_mm[E_AXIS + TARGET_EXTRUDER] = value;
49
+        planner.settings.axis_steps_per_mm[E_AXIS_N(target_extruder)] = value;
49
       }
50
       }
50
       else {
51
       else {
51
         planner.settings.axis_steps_per_mm[i] = parser.value_per_axis_units((AxisEnum)i);
52
         planner.settings.axis_steps_per_mm[i] = parser.value_per_axis_units((AxisEnum)i);

+ 7
- 7
Marlin/src/gcode/control/T.cpp 查看文件

33
  *   F[units/min] Set the movement feedrate
33
  *   F[units/min] Set the movement feedrate
34
  *   S1           Don't move the tool in XY after change
34
  *   S1           Don't move the tool in XY after change
35
  */
35
  */
36
-void GcodeSuite::T(const uint8_t tmp_extruder) {
36
+void GcodeSuite::T(const uint8_t tool_index) {
37
 
37
 
38
   #if ENABLED(DEBUG_LEVELING_FEATURE)
38
   #if ENABLED(DEBUG_LEVELING_FEATURE)
39
     if (DEBUGGING(LEVELING)) {
39
     if (DEBUGGING(LEVELING)) {
40
-      SERIAL_ECHOPAIR(">>> T(", tmp_extruder);
40
+      SERIAL_ECHOPAIR(">>> T(", tool_index);
41
       SERIAL_CHAR(')');
41
       SERIAL_CHAR(')');
42
       SERIAL_EOL();
42
       SERIAL_EOL();
43
       DEBUG_POS("BEFORE", current_position);
43
       DEBUG_POS("BEFORE", current_position);
44
     }
44
     }
45
   #endif
45
   #endif
46
 
46
 
47
-  #if HOTENDS == 1 || (ENABLED(MIXING_EXTRUDER) && MIXING_VIRTUAL_TOOLS > 1)
47
+  #if EXTRUDERS < 2
48
 
48
 
49
-    tool_change(tmp_extruder);
49
+    tool_change(tool_index);
50
 
50
 
51
-  #elif HOTENDS > 1
51
+  #else
52
 
52
 
53
     tool_change(
53
     tool_change(
54
-      tmp_extruder,
54
+      tool_index,
55
       MMM_TO_MMS(parser.linearval('F')),
55
       MMM_TO_MMS(parser.linearval('F')),
56
-      (tmp_extruder == active_extruder) || parser.boolval('S')
56
+      (tool_index == active_extruder) || parser.boolval('S')
57
     );
57
     );
58
 
58
 
59
   #endif
59
   #endif

+ 2
- 1
Marlin/src/gcode/feature/pause/M600.cpp 查看文件

54
 void GcodeSuite::M600() {
54
 void GcodeSuite::M600() {
55
   point_t park_point = NOZZLE_PARK_POINT;
55
   point_t park_point = NOZZLE_PARK_POINT;
56
 
56
 
57
-  if (get_target_extruder_from_command()) return;
57
+  const int8_t target_extruder = get_target_extruder_from_command();
58
+  if (target_extruder < 0) return;
58
 
59
 
59
   #if ENABLED(DUAL_X_CARRIAGE)
60
   #if ENABLED(DUAL_X_CARRIAGE)
60
     int8_t DXC_ext = target_extruder;
61
     int8_t DXC_ext = target_extruder;

+ 2
- 1
Marlin/src/gcode/feature/pause/M603.cpp 查看文件

43
  */
43
  */
44
 void GcodeSuite::M603() {
44
 void GcodeSuite::M603() {
45
 
45
 
46
-  if (get_target_extruder_from_command()) return;
46
+  const int8_t target_extruder = get_target_extruder_from_command();
47
+  if (target_extruder < 0) return;
47
 
48
 
48
   // Unload length
49
   // Unload length
49
   if (parser.seen('U')) {
50
   if (parser.seen('U')) {

+ 7
- 4
Marlin/src/gcode/feature/pause/M701_M702.cpp 查看文件

55
     if (axis_unhomed_error()) park_point.z = 0;
55
     if (axis_unhomed_error()) park_point.z = 0;
56
   #endif
56
   #endif
57
 
57
 
58
-  if (get_target_extruder_from_command()) return;
58
+  const int8_t target_extruder = get_target_extruder_from_command();
59
+  if (target_extruder < 0) return;
60
+
59
 
61
 
60
   // Z axis lift
62
   // Z axis lift
61
   if (parser.seenval('Z')) park_point.z = parser.linearval('Z');
63
   if (parser.seenval('Z')) park_point.z = parser.linearval('Z');
121
     if (axis_unhomed_error()) park_point.z = 0;
123
     if (axis_unhomed_error()) park_point.z = 0;
122
   #endif
124
   #endif
123
 
125
 
124
-  if (get_target_extruder_from_command()) return;
126
+  const int8_t target_extruder = get_target_extruder_from_command();
127
+  if (target_extruder < 0) return;
125
 
128
 
126
   // Z axis lift
129
   // Z axis lift
127
   if (parser.seenval('Z')) park_point.z = parser.linearval('Z');
130
   if (parser.seenval('Z')) park_point.z = parser.linearval('Z');
154
   #endif
157
   #endif
155
   {
158
   {
156
     // Unload length
159
     // Unload length
157
-    const float unload_length = -ABS(parser.seen('U') ? parser.value_axis_units(E_AXIS) :
158
-                                                        fc_settings[target_extruder].unload_length);
160
+    const float unload_length = -ABS(parser.seen('U') ? parser.value_axis_units(E_AXIS)
161
+                                                      : fc_settings[target_extruder].unload_length);
159
 
162
 
160
     unload_filament(unload_length, true, ADVANCED_PAUSE_MODE_UNLOAD_FILAMENT);
163
     unload_filament(unload_length, true, ADVANCED_PAUSE_MODE_UNLOAD_FILAMENT);
161
   }
164
   }

+ 2
- 1
Marlin/src/gcode/feature/trinamic/M906.cpp 查看文件

73
         #endif
73
         #endif
74
         break;
74
         break;
75
       case E_AXIS: {
75
       case E_AXIS: {
76
-        if (get_target_extruder_from_command()) return;
76
+        const int8_t target_extruder = get_target_extruder_from_command();
77
+        if (target_extruder < 0) return;
77
         switch (target_extruder) {
78
         switch (target_extruder) {
78
           #if AXIS_IS_TMC(E0)
79
           #if AXIS_IS_TMC(E0)
79
             case 0: TMC_SET_CURRENT(E0); break;
80
             case 0: TMC_SET_CURRENT(E0); break;

+ 2
- 1
Marlin/src/gcode/feature/trinamic/M911-M915.cpp 查看文件

232
           #endif
232
           #endif
233
           break;
233
           break;
234
         case E_AXIS: {
234
         case E_AXIS: {
235
-          if (get_target_extruder_from_command()) return;
235
+          const int8_t target_extruder = get_target_extruder_from_command();
236
+          if (target_extruder < 0) return;
236
           switch (target_extruder) {
237
           switch (target_extruder) {
237
             #if AXIS_HAS_STEALTHCHOP(E0)
238
             #if AXIS_HAS_STEALTHCHOP(E0)
238
               case 0: TMC_SET_PWMTHRS_E(0); break;
239
               case 0: TMC_SET_PWMTHRS_E(0); break;

+ 9
- 12
Marlin/src/gcode/gcode.cpp 查看文件

38
 
38
 
39
 #include "../Marlin.h" // for idle() and suspend_auto_report
39
 #include "../Marlin.h" // for idle() and suspend_auto_report
40
 
40
 
41
-uint8_t GcodeSuite::target_extruder;
42
 millis_t GcodeSuite::previous_move_ms;
41
 millis_t GcodeSuite::previous_move_ms;
43
 
42
 
44
 bool GcodeSuite::axis_relative_modes[] = AXIS_RELATIVE_MODES;
43
 bool GcodeSuite::axis_relative_modes[] = AXIS_RELATIVE_MODES;
58
 #endif
57
 #endif
59
 
58
 
60
 /**
59
 /**
61
- * Set target_extruder from the T parameter or the active_extruder
62
- *
63
- * Returns TRUE if the target is invalid
60
+ * Get the target extruder from the T parameter or the active_extruder
61
+ * Return -1 if the T parameter is out of range
64
  */
62
  */
65
-bool GcodeSuite::get_target_extruder_from_command() {
63
+int8_t GcodeSuite::get_target_extruder_from_command() {
66
   if (parser.seenval('T')) {
64
   if (parser.seenval('T')) {
67
     const int8_t e = parser.value_byte();
65
     const int8_t e = parser.value_byte();
68
     if (e >= EXTRUDERS) {
66
     if (e >= EXTRUDERS) {
70
       SERIAL_CHAR('M');
68
       SERIAL_CHAR('M');
71
       SERIAL_ECHO(parser.codenum);
69
       SERIAL_ECHO(parser.codenum);
72
       SERIAL_ECHOLNPAIR(" " MSG_INVALID_EXTRUDER " ", e);
70
       SERIAL_ECHOLNPAIR(" " MSG_INVALID_EXTRUDER " ", e);
73
-      return true;
71
+      return -1;
74
     }
72
     }
75
-    target_extruder = e;
73
+    return e;
76
   }
74
   }
77
-  else
78
-    target_extruder = active_extruder;
79
-
80
-  return false;
75
+  return active_extruder;
81
 }
76
 }
82
 
77
 
83
 /**
78
 /**
539
         case 302: M302(); break;                                  // M302: Allow cold extrudes (set the minimum extrude temperature)
534
         case 302: M302(); break;                                  // M302: Allow cold extrudes (set the minimum extrude temperature)
540
       #endif
535
       #endif
541
 
536
 
542
-      case 303: M303(); break;                                    // M303: PID autotune
537
+      #if HAS_PID_HEATING
538
+        case 303: M303(); break;                                  // M303: PID autotune
539
+      #endif
543
 
540
 
544
       #if ENABLED(MORGAN_SCARA)
541
       #if ENABLED(MORGAN_SCARA)
545
         case 360: if (M360()) return; break;                      // M360: SCARA Theta pos1
542
         case 360: if (M360()) return; break;                      // M360: SCARA Theta pos1

+ 6
- 16
Marlin/src/gcode/gcode.h 查看文件

267
 
267
 
268
   GcodeSuite() {}
268
   GcodeSuite() {}
269
 
269
 
270
-  static uint8_t target_extruder;
271
-
272
   static bool axis_relative_modes[];
270
   static bool axis_relative_modes[];
273
 
271
 
274
   #if ENABLED(CNC_WORKSPACE_PLANES)
272
   #if ENABLED(CNC_WORKSPACE_PLANES)
290
   static millis_t previous_move_ms;
288
   static millis_t previous_move_ms;
291
   FORCE_INLINE static void reset_stepper_timeout() { previous_move_ms = millis(); }
289
   FORCE_INLINE static void reset_stepper_timeout() { previous_move_ms = millis(); }
292
 
290
 
293
-  static bool get_target_extruder_from_command();
291
+  static int8_t get_target_extruder_from_command();
294
   static void get_destination_from_command();
292
   static void get_destination_from_command();
293
+
295
   static void process_parsed_command(
294
   static void process_parsed_command(
296
     #if USE_EXECUTE_COMMANDS_IMMEDIATE
295
     #if USE_EXECUTE_COMMANDS_IMMEDIATE
297
       const bool no_ok = false
296
       const bool no_ok = false
306
 
305
 
307
   FORCE_INLINE static void home_all_axes() { G28(true); }
306
   FORCE_INLINE static void home_all_axes() { G28(true); }
308
 
307
 
309
-  /**
310
-   * Multi-stepper support for M92, M201, M203
311
-   */
312
-  #if ENABLED(DISTINCT_E_FACTORS)
313
-    #define GET_TARGET_EXTRUDER() if (gcode.get_target_extruder_from_command()) return
314
-    #define TARGET_EXTRUDER gcode.target_extruder
315
-  #else
316
-    #define GET_TARGET_EXTRUDER() NOOP
317
-    #define TARGET_EXTRUDER 0
318
-  #endif
319
-
320
   #if ENABLED(HOST_KEEPALIVE_FEATURE)
308
   #if ENABLED(HOST_KEEPALIVE_FEATURE)
321
     /**
309
     /**
322
      * States for managing Marlin and host communication
310
      * States for managing Marlin and host communication
669
     static void M302();
657
     static void M302();
670
   #endif
658
   #endif
671
 
659
 
672
-  static void M303();
660
+  #if HAS_PID_HEATING
661
+    static void M303();
662
+  #endif
673
 
663
 
674
   #if ENABLED(PIDTEMPBED)
664
   #if ENABLED(PIDTEMPBED)
675
     static void M304();
665
     static void M304();
832
 
822
 
833
   static void M999();
823
   static void M999();
834
 
824
 
835
-  static void T(const uint8_t tmp_extruder);
825
+  static void T(const uint8_t tool_index);
836
 
826
 
837
 };
827
 };
838
 
828
 

+ 14
- 3
Marlin/src/gcode/temperature/M104_M109.cpp 查看文件

39
  * M104: Set hot end temperature
39
  * M104: Set hot end temperature
40
  */
40
  */
41
 void GcodeSuite::M104() {
41
 void GcodeSuite::M104() {
42
-  if (get_target_extruder_from_command()) return;
42
+
43
   if (DEBUGGING(DRYRUN)) return;
43
   if (DEBUGGING(DRYRUN)) return;
44
 
44
 
45
-  const uint8_t e = target_extruder;
45
+  #if ENABLED(MIXING_EXTRUDER) && MIXING_VIRTUAL_TOOLS > 1
46
+    constexpr int8_t e = 0;
47
+  #else
48
+    const int8_t e = get_target_extruder_from_command();
49
+    if (e < 0) return;
50
+  #endif
46
 
51
 
47
   if (parser.seenval('S')) {
52
   if (parser.seenval('S')) {
48
     const int16_t temp = parser.value_celsius();
53
     const int16_t temp = parser.value_celsius();
82
  */
87
  */
83
 void GcodeSuite::M109() {
88
 void GcodeSuite::M109() {
84
 
89
 
85
-  if (get_target_extruder_from_command()) return;
86
   if (DEBUGGING(DRYRUN)) return;
90
   if (DEBUGGING(DRYRUN)) return;
87
 
91
 
92
+  #if ENABLED(MIXING_EXTRUDER) && MIXING_VIRTUAL_TOOLS > 1
93
+    constexpr int8_t target_extruder = 0;
94
+  #else
95
+    const int8_t target_extruder = get_target_extruder_from_command();
96
+    if (target_extruder < 0) return;
97
+  #endif
98
+
88
   const bool no_wait_for_cooling = parser.seenval('S'),
99
   const bool no_wait_for_cooling = parser.seenval('S'),
89
              set_temp = no_wait_for_cooling || parser.seenval('R');
100
              set_temp = no_wait_for_cooling || parser.seenval('R');
90
   if (set_temp) {
101
   if (set_temp) {

+ 5
- 3
Marlin/src/gcode/temperature/M105.cpp 查看文件

31
  * M105: Read hot end and bed temperature
31
  * M105: Read hot end and bed temperature
32
  */
32
  */
33
 void GcodeSuite::M105() {
33
 void GcodeSuite::M105() {
34
-  if (get_target_extruder_from_command()) return;
34
+
35
+  const int8_t target_extruder = get_target_extruder_from_command();
36
+  if (target_extruder < 0) return;
35
 
37
 
36
   #if NUM_SERIAL > 1
38
   #if NUM_SERIAL > 1
37
     const int16_t port = command_queue_port[cmd_queue_index_r];
39
     const int16_t port = command_queue_port[cmd_queue_index_r];
39
 
41
 
40
   #if HAS_TEMP_SENSOR
42
   #if HAS_TEMP_SENSOR
41
     SERIAL_PROTOCOLPGM_P(port, MSG_OK);
43
     SERIAL_PROTOCOLPGM_P(port, MSG_OK);
42
-    thermalManager.print_heaterstates(
44
+    thermalManager.print_heater_states(target_extruder
43
       #if NUM_SERIAL > 1
45
       #if NUM_SERIAL > 1
44
-        port
46
+        , port
45
       #endif
47
       #endif
46
     );
48
     );
47
   #else // !HAS_TEMP_SENSOR
49
   #else // !HAS_TEMP_SENSOR

+ 30
- 16
Marlin/src/gcode/temperature/M303.cpp 查看文件

20
  *
20
  *
21
  */
21
  */
22
 
22
 
23
+#include "../../inc/MarlinConfig.h"
24
+
25
+#if HAS_PID_HEATING
26
+
23
 #include "../gcode.h"
27
 #include "../gcode.h"
24
 #include "../../module/temperature.h"
28
 #include "../../module/temperature.h"
25
 
29
 
32
  *       U<bool> with a non-zero value will apply the result to current settings
36
  *       U<bool> with a non-zero value will apply the result to current settings
33
  */
37
  */
34
 void GcodeSuite::M303() {
38
 void GcodeSuite::M303() {
35
-  #if HAS_PID_HEATING
36
-    const int e = parser.intval('E'), c = parser.intval('C', 5);
37
-    const bool u = parser.boolval('U');
38
-
39
-    int16_t temp = parser.celsiusval('S', e < 0 ? 70 : 150);
40
 
39
 
41
-    if (WITHIN(e, 0, HOTENDS - 1))
42
-      target_extruder = e;
40
+  const int8_t e = parser.byteval('E');
43
 
41
 
44
-    #if DISABLED(BUSY_WHILE_HEATING)
45
-      KEEPALIVE_STATE(NOT_BUSY);
42
+  if (!WITHIN(e, 0
43
+    #if ENABLED(PIDTEMPBED)
44
+      -1
46
     #endif
45
     #endif
46
+    ,
47
+    #if ENABLED(PIDTEMP)
48
+      HOTENDS
49
+    #endif
50
+    -1
51
+  )) {
52
+    SERIAL_ECHOLNPGM(MSG_PID_BAD_EXTRUDER_NUM);
53
+    return;
54
+  }
47
 
55
 
48
-    thermalManager.PID_autotune(temp, e, c, u);
56
+  const int c = parser.intval('C', 5);
57
+  const bool u = parser.boolval('U');
58
+  const int16_t temp = parser.celsiusval('S', e < 0 ? 70 : 150);
49
 
59
 
50
-    #if DISABLED(BUSY_WHILE_HEATING)
51
-      KEEPALIVE_STATE(IN_HANDLER);
52
-    #endif
53
-  #else
54
-    SERIAL_ERROR_START();
55
-    SERIAL_ERRORLNPGM(MSG_ERR_M303_DISABLED);
60
+  #if DISABLED(BUSY_WHILE_HEATING)
61
+    KEEPALIVE_STATE(NOT_BUSY);
62
+  #endif
63
+
64
+  thermalManager.PID_autotune(temp, e, c, u);
65
+
66
+  #if DISABLED(BUSY_WHILE_HEATING)
67
+    KEEPALIVE_STATE(IN_HANDLER);
56
   #endif
68
   #endif
57
 }
69
 }
70
+
71
+#endif // HAS_PID_HEATING

+ 33
- 51
Marlin/src/module/temperature.cpp 查看文件

236
    * Alternately heat and cool the nozzle, observing its behavior to
236
    * Alternately heat and cool the nozzle, observing its behavior to
237
    * determine the best PID values to achieve a stable temperature.
237
    * determine the best PID values to achieve a stable temperature.
238
    */
238
    */
239
-  void Temperature::PID_autotune(const float &target, const int8_t hotend, const int8_t ncycles, const bool set_result/*=false*/) {
239
+  void Temperature::PID_autotune(const float &target, const int8_t heater, const int8_t ncycles, const bool set_result/*=false*/) {
240
     float current = 0.0;
240
     float current = 0.0;
241
     int cycles = 0;
241
     int cycles = 0;
242
     bool heating = true;
242
     bool heating = true;
249
     float max = 0, min = 10000;
249
     float max = 0, min = 10000;
250
 
250
 
251
     #if HAS_PID_FOR_BOTH
251
     #if HAS_PID_FOR_BOTH
252
-      #define GHV(B,H) (hotend < 0 ? (B) : (H))
253
-      #define SHV(S,B,H) do{ if (hotend < 0) S##_bed = B; else S [hotend] = H; }while(0)
254
-      #define ONHEATINGSTART() (hotend < 0 ? printerEventLEDs.onBedHeatingStart() : printerEventLEDs.onHotendHeatingStart())
255
-      #define ONHEATING(S,C,T) do{ if (hotend < 0) printerEventLEDs.onBedHeating(S,C,T); else printerEventLEDs.onHotendHeating(S,C,T); }while(0)
252
+      #define GHV(B,H) (heater < 0 ? (B) : (H))
253
+      #define SHV(S,B,H) do{ if (heater < 0) S##_bed = B; else S [heater] = H; }while(0)
254
+      #define ONHEATINGSTART() (heater < 0 ? printerEventLEDs.onBedHeatingStart() : printerEventLEDs.onHotendHeatingStart())
255
+      #define ONHEATING(S,C,T) do{ if (heater < 0) printerEventLEDs.onBedHeating(S,C,T); else printerEventLEDs.onHotendHeating(S,C,T); }while(0)
256
     #elif ENABLED(PIDTEMPBED)
256
     #elif ENABLED(PIDTEMPBED)
257
       #define GHV(B,H) B
257
       #define GHV(B,H) B
258
       #define SHV(S,B,H) (S##_bed = B)
258
       #define SHV(S,B,H) (S##_bed = B)
260
       #define ONHEATING(S,C,T) printerEventLEDs.onBedHeating(S,C,T)
260
       #define ONHEATING(S,C,T) printerEventLEDs.onBedHeating(S,C,T)
261
     #else
261
     #else
262
       #define GHV(B,H) H
262
       #define GHV(B,H) H
263
-      #define SHV(S,B,H) (S [hotend] = H)
263
+      #define SHV(S,B,H) (S [heater] = H)
264
       #define ONHEATINGSTART() printerEventLEDs.onHotendHeatingStart()
264
       #define ONHEATINGSTART() printerEventLEDs.onHotendHeatingStart()
265
       #define ONHEATING(S,C,T) printerEventLEDs.onHotendHeating(S,C,T)
265
       #define ONHEATING(S,C,T) printerEventLEDs.onHotendHeating(S,C,T)
266
     #endif
266
     #endif
268
     #if WATCH_THE_BED || WATCH_HOTENDS
268
     #if WATCH_THE_BED || WATCH_HOTENDS
269
       #define HAS_TP_BED (ENABLED(THERMAL_PROTECTION_BED) && ENABLED(PIDTEMPBED))
269
       #define HAS_TP_BED (ENABLED(THERMAL_PROTECTION_BED) && ENABLED(PIDTEMPBED))
270
       #if HAS_TP_BED && ENABLED(THERMAL_PROTECTION_HOTENDS) && ENABLED(PIDTEMP)
270
       #if HAS_TP_BED && ENABLED(THERMAL_PROTECTION_HOTENDS) && ENABLED(PIDTEMP)
271
-        #define GTV(B,H) (hotend < 0 ? (B) : (H))
271
+        #define GTV(B,H) (heater < 0 ? (B) : (H))
272
       #elif HAS_TP_BED
272
       #elif HAS_TP_BED
273
         #define GTV(B,H) (B)
273
         #define GTV(B,H) (B)
274
       #else
274
       #else
286
       next_auto_fan_check_ms = next_temp_ms + 2500UL;
286
       next_auto_fan_check_ms = next_temp_ms + 2500UL;
287
     #endif
287
     #endif
288
 
288
 
289
-    #if ENABLED(PIDTEMP)
290
-      #define _TOP_HOTEND HOTENDS - 1
291
-    #else
292
-      #define _TOP_HOTEND -1
293
-    #endif
294
-    #if ENABLED(PIDTEMPBED)
295
-      #define _BOT_HOTEND -1
296
-    #else
297
-      #define _BOT_HOTEND 0
298
-    #endif
299
-
300
-    if (!WITHIN(hotend, _BOT_HOTEND, _TOP_HOTEND)) {
301
-      SERIAL_ECHOLNPGM(MSG_PID_BAD_EXTRUDER_NUM);
302
-      return;
303
-    }
304
-
305
     SERIAL_ECHOLNPGM(MSG_PID_AUTOTUNE_START);
289
     SERIAL_ECHOLNPGM(MSG_PID_AUTOTUNE_START);
306
 
290
 
307
     disable_all_heaters();
291
     disable_all_heaters();
310
 
294
 
311
     wait_for_heatup = true; // Can be interrupted with M108
295
     wait_for_heatup = true; // Can be interrupted with M108
312
     #if ENABLED(PRINTER_EVENT_LEDS)
296
     #if ENABLED(PRINTER_EVENT_LEDS)
313
-      const float start_temp = GHV(current_temperature_bed, current_temperature[hotend]);
297
+      const float start_temp = GHV(current_temperature_bed, current_temperature[heater]);
314
       LEDColor color = ONHEATINGSTART();
298
       LEDColor color = ONHEATINGSTART();
315
     #endif
299
     #endif
316
 
300
 
323
         updateTemperaturesFromRawValues();
307
         updateTemperaturesFromRawValues();
324
 
308
 
325
         // Get the current temperature and constrain it
309
         // Get the current temperature and constrain it
326
-        current = GHV(current_temperature_bed, current_temperature[hotend]);
310
+        current = GHV(current_temperature_bed, current_temperature[heater]);
327
         NOLESS(max, current);
311
         NOLESS(max, current);
328
         NOMORE(min, current);
312
         NOMORE(min, current);
329
 
313
 
412
       // Report heater states every 2 seconds
396
       // Report heater states every 2 seconds
413
       if (ELAPSED(ms, next_temp_ms)) {
397
       if (ELAPSED(ms, next_temp_ms)) {
414
         #if HAS_TEMP_SENSOR
398
         #if HAS_TEMP_SENSOR
415
-          print_heaterstates();
399
+          print_heater_states(heater >= 0 ? heater : active_extruder);
416
           SERIAL_EOL();
400
           SERIAL_EOL();
417
         #endif
401
         #endif
418
         next_temp_ms = ms + 2000UL;
402
         next_temp_ms = ms + 2000UL;
423
             #if WATCH_THE_BED && WATCH_HOTENDS
407
             #if WATCH_THE_BED && WATCH_HOTENDS
424
               true
408
               true
425
             #elif WATCH_HOTENDS
409
             #elif WATCH_HOTENDS
426
-              hotend >= 0
410
+              heater >= 0
427
             #else
411
             #else
428
-              hotend < 0
412
+              heater < 0
429
             #endif
413
             #endif
430
           ) {
414
           ) {
431
             if (!heated) {                                          // If not yet reached target...
415
             if (!heated) {                                          // If not yet reached target...
435
                 if (current > watch_temp_target) heated = true;     // - Flag if target temperature reached
419
                 if (current > watch_temp_target) heated = true;     // - Flag if target temperature reached
436
               }
420
               }
437
               else if (ELAPSED(ms, temp_change_ms))                 // Watch timer expired
421
               else if (ELAPSED(ms, temp_change_ms))                 // Watch timer expired
438
-                _temp_error(hotend, PSTR(MSG_T_HEATING_FAILED), TEMP_ERR_PSTR(MSG_HEATING_FAILED_LCD, hotend));
422
+                _temp_error(heater, PSTR(MSG_T_HEATING_FAILED), TEMP_ERR_PSTR(MSG_HEATING_FAILED_LCD, heater));
439
             }
423
             }
440
             else if (current < target - (MAX_OVERSHOOT_PID_AUTOTUNE)) // Heated, then temperature fell too far?
424
             else if (current < target - (MAX_OVERSHOOT_PID_AUTOTUNE)) // Heated, then temperature fell too far?
441
-              _temp_error(hotend, PSTR(MSG_T_THERMAL_RUNAWAY), TEMP_ERR_PSTR(MSG_THERMAL_RUNAWAY, hotend));
425
+              _temp_error(heater, PSTR(MSG_T_THERMAL_RUNAWAY), TEMP_ERR_PSTR(MSG_THERMAL_RUNAWAY, heater));
442
           }
426
           }
443
         #endif
427
         #endif
444
       } // every 2 seconds
428
       } // every 2 seconds
477
         }while(0)
461
         }while(0)
478
 
462
 
479
         #define _SET_EXTRUDER_PID() do { \
463
         #define _SET_EXTRUDER_PID() do { \
480
-          PID_PARAM(Kp, hotend) = tune_pid.Kp; \
481
-          PID_PARAM(Ki, hotend) = scalePID_i(tune_pid.Ki); \
482
-          PID_PARAM(Kd, hotend) = scalePID_d(tune_pid.Kd); \
464
+          PID_PARAM(Kp, heater) = tune_pid.Kp; \
465
+          PID_PARAM(Ki, heater) = scalePID_i(tune_pid.Ki); \
466
+          PID_PARAM(Kd, heater) = scalePID_d(tune_pid.Kd); \
483
           updatePID(); }while(0)
467
           updatePID(); }while(0)
484
 
468
 
485
         // Use the result? (As with "M303 U1")
469
         // Use the result? (As with "M303 U1")
486
         if (set_result) {
470
         if (set_result) {
487
           #if HAS_PID_FOR_BOTH
471
           #if HAS_PID_FOR_BOTH
488
-            if (hotend < 0) _SET_BED_PID(); else _SET_EXTRUDER_PID();
472
+            if (heater < 0) _SET_BED_PID(); else _SET_EXTRUDER_PID();
489
           #elif ENABLED(PIDTEMP)
473
           #elif ENABLED(PIDTEMP)
490
             _SET_EXTRUDER_PID();
474
             _SET_EXTRUDER_PID();
491
           #else
475
           #else
575
 //
559
 //
576
 // Temperature Error Handlers
560
 // Temperature Error Handlers
577
 //
561
 //
578
-void Temperature::_temp_error(const int8_t e, PGM_P const serial_msg, PGM_P const lcd_msg) {
562
+void Temperature::_temp_error(const int8_t heater, PGM_P const serial_msg, PGM_P const lcd_msg) {
579
   static bool killed = false;
563
   static bool killed = false;
580
   if (IsRunning()) {
564
   if (IsRunning()) {
581
     SERIAL_ERROR_START();
565
     SERIAL_ERROR_START();
582
     serialprintPGM(serial_msg);
566
     serialprintPGM(serial_msg);
583
     SERIAL_ERRORPGM(MSG_STOPPED_HEATER);
567
     SERIAL_ERRORPGM(MSG_STOPPED_HEATER);
584
-    if (e >= 0) SERIAL_ERRORLN((int)e); else SERIAL_ERRORLNPGM(MSG_HEATER_BED);
568
+    if (heater >= 0) SERIAL_ERRORLN((int)heater); else SERIAL_ERRORLNPGM(MSG_HEATER_BED);
585
   }
569
   }
586
   #if DISABLED(BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE)
570
   #if DISABLED(BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE)
587
     if (!killed) {
571
     if (!killed) {
594
   #endif
578
   #endif
595
 }
579
 }
596
 
580
 
597
-void Temperature::max_temp_error(const int8_t e) {
598
-  _temp_error(e, PSTR(MSG_T_MAXTEMP), TEMP_ERR_PSTR(MSG_ERR_MAXTEMP, e));
581
+void Temperature::max_temp_error(const int8_t heater) {
582
+  _temp_error(heater, PSTR(MSG_T_MAXTEMP), TEMP_ERR_PSTR(MSG_ERR_MAXTEMP, heater));
599
 }
583
 }
600
 
584
 
601
-void Temperature::min_temp_error(const int8_t e) {
602
-  _temp_error(e, PSTR(MSG_T_MINTEMP), TEMP_ERR_PSTR(MSG_ERR_MINTEMP, e));
585
+void Temperature::min_temp_error(const int8_t heater) {
586
+  _temp_error(heater, PSTR(MSG_T_MINTEMP), TEMP_ERR_PSTR(MSG_ERR_MINTEMP, heater));
603
 }
587
 }
604
 
588
 
605
 float Temperature::get_pid_output(const int8_t e) {
589
 float Temperature::get_pid_output(const int8_t e) {
2346
     delay(2);
2330
     delay(2);
2347
   }
2331
   }
2348
 
2332
 
2349
-  void Temperature::print_heaterstates(
2333
+  void Temperature::print_heater_states(const uint8_t target_extruder
2350
     #if NUM_SERIAL > 1
2334
     #if NUM_SERIAL > 1
2351
-      const int8_t port
2335
+      , const int8_t port
2352
     #endif
2336
     #endif
2353
   ) {
2337
   ) {
2354
     #if HAS_TEMP_HOTEND
2338
     #if HAS_TEMP_HOTEND
2355
-      print_heater_state(degHotend(gcode.target_extruder), degTargetHotend(gcode.target_extruder)
2339
+      print_heater_state(degHotend(target_extruder), degTargetHotend(target_extruder)
2356
         #if ENABLED(SHOW_TEMP_ADC_VALUES)
2340
         #if ENABLED(SHOW_TEMP_ADC_VALUES)
2357
-          , rawHotendTemp(gcode.target_extruder)
2341
+          , rawHotendTemp(target_extruder)
2358
         #endif
2342
         #endif
2359
         #if NUM_SERIAL > 1
2343
         #if NUM_SERIAL > 1
2360
           , port
2344
           , port
2392
       );
2376
       );
2393
     #endif
2377
     #endif
2394
     SERIAL_PROTOCOLPGM_P(port, " @:");
2378
     SERIAL_PROTOCOLPGM_P(port, " @:");
2395
-    SERIAL_PROTOCOL_P(port, getHeaterPower(gcode.target_extruder));
2379
+    SERIAL_PROTOCOL_P(port, getHeaterPower(target_extruder));
2396
     #if HAS_HEATED_BED
2380
     #if HAS_HEATED_BED
2397
       SERIAL_PROTOCOLPGM_P(port, " B@:");
2381
       SERIAL_PROTOCOLPGM_P(port, " B@:");
2398
       SERIAL_PROTOCOL_P(port, getHeaterPower(-1));
2382
       SERIAL_PROTOCOL_P(port, getHeaterPower(-1));
2414
     void Temperature::auto_report_temperatures() {
2398
     void Temperature::auto_report_temperatures() {
2415
       if (auto_report_temp_interval && ELAPSED(millis(), next_temp_report_ms)) {
2399
       if (auto_report_temp_interval && ELAPSED(millis(), next_temp_report_ms)) {
2416
         next_temp_report_ms = millis() + 1000UL * auto_report_temp_interval;
2400
         next_temp_report_ms = millis() + 1000UL * auto_report_temp_interval;
2417
-        print_heaterstates();
2401
+        print_heater_states(active_extruder);
2418
         SERIAL_EOL();
2402
         SERIAL_EOL();
2419
       }
2403
       }
2420
     }
2404
     }
2480
         }
2464
         }
2481
 
2465
 
2482
         now = millis();
2466
         now = millis();
2483
-        if (ELAPSED(now, next_temp_ms)) { //Print temp & remaining time every 1s while waiting
2467
+        if (ELAPSED(now, next_temp_ms)) { // Print temp & remaining time every 1s while waiting
2484
           next_temp_ms = now + 1000UL;
2468
           next_temp_ms = now + 1000UL;
2485
-          print_heaterstates();
2469
+          print_heater_states(target_extruder);
2486
           #if TEMP_RESIDENCY_TIME > 0
2470
           #if TEMP_RESIDENCY_TIME > 0
2487
             SERIAL_PROTOCOLPGM(" W:");
2471
             SERIAL_PROTOCOLPGM(" W:");
2488
             if (residency_start_ms)
2472
             if (residency_start_ms)
2587
         KEEPALIVE_STATE(NOT_BUSY);
2571
         KEEPALIVE_STATE(NOT_BUSY);
2588
       #endif
2572
       #endif
2589
 
2573
 
2590
-      gcode.target_extruder = active_extruder; // for print_heaterstates
2591
-
2592
       #if ENABLED(PRINTER_EVENT_LEDS)
2574
       #if ENABLED(PRINTER_EVENT_LEDS)
2593
         const float start_temp = degBed();
2575
         const float start_temp = degBed();
2594
         printerEventLEDs.onBedHeatingStart();
2576
         printerEventLEDs.onBedHeatingStart();
2607
         now = millis();
2589
         now = millis();
2608
         if (ELAPSED(now, next_temp_ms)) { //Print Temp Reading every 1 second while heating up.
2590
         if (ELAPSED(now, next_temp_ms)) { //Print Temp Reading every 1 second while heating up.
2609
           next_temp_ms = now + 1000UL;
2591
           next_temp_ms = now + 1000UL;
2610
-          print_heaterstates();
2592
+          print_heater_states(active_extruder);
2611
           #if TEMP_BED_RESIDENCY_TIME > 0
2593
           #if TEMP_BED_RESIDENCY_TIME > 0
2612
             SERIAL_PROTOCOLPGM(" W:");
2594
             SERIAL_PROTOCOLPGM(" W:");
2613
             if (residency_start_ms)
2595
             if (residency_start_ms)

+ 2
- 2
Marlin/src/module/temperature.h 查看文件

601
     #endif // HEATER_IDLE_HANDLER
601
     #endif // HEATER_IDLE_HANDLER
602
 
602
 
603
     #if HAS_TEMP_SENSOR
603
     #if HAS_TEMP_SENSOR
604
-      static void print_heaterstates(
604
+      static void print_heater_states(const uint8_t target_extruder
605
         #if NUM_SERIAL > 1
605
         #if NUM_SERIAL > 1
606
-          const int8_t port = -1
606
+          , const int8_t port = -1
607
         #endif
607
         #endif
608
       );
608
       );
609
       #if ENABLED(AUTO_REPORT_TEMPERATURES)
609
       #if ENABLED(AUTO_REPORT_TEMPERATURES)

+ 6
- 6
Marlin/src/module/tool_change.cpp 查看文件

500
 void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool no_move/*=false*/) {
500
 void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool no_move/*=false*/) {
501
   #if ENABLED(MIXING_EXTRUDER)
501
   #if ENABLED(MIXING_EXTRUDER)
502
 
502
 
503
-    UNUSED(fr_mm_s);
504
-    UNUSED(no_move);
503
+    UNUSED(fr_mm_s); UNUSED(no_move);
504
+
505
     if (tmp_extruder >= MIXING_VIRTUAL_TOOLS)
505
     if (tmp_extruder >= MIXING_VIRTUAL_TOOLS)
506
       return invalid_extruder_error(tmp_extruder);
506
       return invalid_extruder_error(tmp_extruder);
507
 
507
 
512
 
512
 
513
   #elif EXTRUDERS < 2
513
   #elif EXTRUDERS < 2
514
 
514
 
515
-    UNUSED(fr_mm_s);
516
-    UNUSED(no_move);
515
+    UNUSED(fr_mm_s); UNUSED(no_move);
516
+
517
     if (tmp_extruder) invalid_extruder_error(tmp_extruder);
517
     if (tmp_extruder) invalid_extruder_error(tmp_extruder);
518
     return;
518
     return;
519
 
519
 
520
-  #else
520
+  #else // EXTRUDERS > 1
521
 
521
 
522
     planner.synchronize();
522
     planner.synchronize();
523
 
523
 
751
     SERIAL_ECHO_START();
751
     SERIAL_ECHO_START();
752
     SERIAL_ECHOLNPAIR(MSG_ACTIVE_EXTRUDER, int(active_extruder));
752
     SERIAL_ECHOLNPAIR(MSG_ACTIVE_EXTRUDER, int(active_extruder));
753
 
753
 
754
-  #endif // EXTRUDERS <= 1 && (!MIXING_EXTRUDER || MIXING_VIRTUAL_TOOLS <= 1)
754
+  #endif // EXTRUDERS > 1
755
 }
755
 }

正在加载...
取消
保存