Browse Source

Fix single nozzle temp change, do slower extra prime (#14696)

InsanityAutomation 6 years ago
parent
commit
dc6fa04f68
2 changed files with 96 additions and 92 deletions
  1. 13
    13
      Marlin/src/gcode/feature/advance/M900.cpp
  2. 83
    79
      Marlin/src/module/tool_change.cpp

+ 13
- 13
Marlin/src/gcode/feature/advance/M900.cpp View File

44
 void GcodeSuite::M900() {
44
 void GcodeSuite::M900() {
45
 
45
 
46
   #if EXTRUDERS < 2
46
   #if EXTRUDERS < 2
47
-    constexpr uint8_t tmp_extruder = 0;
47
+    constexpr uint8_t tool_index = 0;
48
   #else
48
   #else
49
-    const uint8_t tmp_extruder = parser.intval('T', active_extruder);
50
-    if (tmp_extruder >= EXTRUDERS) {
49
+    const uint8_t tool_index = parser.intval('T', active_extruder);
50
+    if (tool_index >= EXTRUDERS) {
51
       SERIAL_ECHOLNPGM("?T value out of range.");
51
       SERIAL_ECHOLNPGM("?T value out of range.");
52
       return;
52
       return;
53
     }
53
     }
55
 
55
 
56
   #if ENABLED(EXTRA_LIN_ADVANCE_K)
56
   #if ENABLED(EXTRA_LIN_ADVANCE_K)
57
 
57
 
58
-    bool ext_slot = TEST(lin_adv_slot, tmp_extruder);
58
+    bool ext_slot = TEST(lin_adv_slot, tool_index);
59
 
59
 
60
     if (parser.seenval('S')) {
60
     if (parser.seenval('S')) {
61
       const bool slot = parser.value_bool();
61
       const bool slot = parser.value_bool();
62
       if (ext_slot != slot) {
62
       if (ext_slot != slot) {
63
         ext_slot = slot;
63
         ext_slot = slot;
64
-        SET_BIT_TO(lin_adv_slot, tmp_extruder, slot);
64
+        SET_BIT_TO(lin_adv_slot, tool_index, slot);
65
         planner.synchronize();
65
         planner.synchronize();
66
-        const float temp = planner.extruder_advance_K[tmp_extruder];
67
-        planner.extruder_advance_K[tmp_extruder] = saved_extruder_advance_K[tmp_extruder];
68
-        saved_extruder_advance_K[tmp_extruder] = temp;
66
+        const float temp = planner.extruder_advance_K[tool_index];
67
+        planner.extruder_advance_K[tool_index] = saved_extruder_advance_K[tool_index];
68
+        saved_extruder_advance_K[tool_index] = temp;
69
       }
69
       }
70
     }
70
     }
71
 
71
 
73
       const float newK = parser.value_float();
73
       const float newK = parser.value_float();
74
       if (WITHIN(newK, 0, 10)) {
74
       if (WITHIN(newK, 0, 10)) {
75
         if (ext_slot)
75
         if (ext_slot)
76
-          saved_extruder_advance_K[tmp_extruder] = newK;
76
+          saved_extruder_advance_K[tool_index] = newK;
77
         else {
77
         else {
78
           planner.synchronize();
78
           planner.synchronize();
79
-          planner.extruder_advance_K[tmp_extruder] = newK;
79
+          planner.extruder_advance_K[tool_index] = newK;
80
         }
80
         }
81
       }
81
       }
82
       else
82
       else
87
       const float newL = parser.value_float();
87
       const float newL = parser.value_float();
88
       if (WITHIN(newL, 0, 10)) {
88
       if (WITHIN(newL, 0, 10)) {
89
         if (!ext_slot)
89
         if (!ext_slot)
90
-          saved_extruder_advance_K[tmp_extruder] = newL;
90
+          saved_extruder_advance_K[tool_index] = newL;
91
         else {
91
         else {
92
           planner.synchronize();
92
           planner.synchronize();
93
-          planner.extruder_advance_K[tmp_extruder] = newL;
93
+          planner.extruder_advance_K[tool_index] = newL;
94
         }
94
         }
95
       }
95
       }
96
       else
96
       else
117
       const float newK = parser.value_float();
117
       const float newK = parser.value_float();
118
       if (WITHIN(newK, 0, 10)) {
118
       if (WITHIN(newK, 0, 10)) {
119
         planner.synchronize();
119
         planner.synchronize();
120
-        planner.extruder_advance_K[tmp_extruder] = newK;
120
+        planner.extruder_advance_K[tool_index] = newK;
121
       }
121
       }
122
       else
122
       else
123
         SERIAL_ECHOLNPGM("?K value out of range (0-10).");
123
         SERIAL_ECHOLNPGM("?K value out of range (0-10).");

+ 83
- 79
Marlin/src/module/tool_change.cpp View File

146
         parkingtraveldistance,    // M951 D
146
         parkingtraveldistance,    // M951 D
147
         compensationmultiplier;
147
         compensationmultiplier;
148
 
148
 
149
-  inline void magnetic_parking_extruder_tool_change(const uint8_t tmp_extruder) {
149
+  inline void magnetic_parking_extruder_tool_change(const uint8_t new_tool) {
150
 
150
 
151
     const float oldx = current_position[X_AXIS],
151
     const float oldx = current_position[X_AXIS],
152
-                grabpos = mpe_settings.parking_xpos[tmp_extruder] + (tmp_extruder ? mpe_settings.grab_distance : -mpe_settings.grab_distance),
152
+                grabpos = mpe_settings.parking_xpos[new_tool] + (new_tool ? mpe_settings.grab_distance : -mpe_settings.grab_distance),
153
                 offsetcompensation =
153
                 offsetcompensation =
154
                   #if HAS_HOTEND_OFFSET
154
                   #if HAS_HOTEND_OFFSET
155
                     hotend_offset[X_AXIS][active_extruder] * mpe_settings.compensation_factor
155
                     hotend_offset[X_AXIS][active_extruder] * mpe_settings.compensation_factor
174
 
174
 
175
     // STEP 1
175
     // STEP 1
176
 
176
 
177
-    current_position[X_AXIS] = mpe_settings.parking_xpos[tmp_extruder] + offsetcompensation;
177
+    current_position[X_AXIS] = mpe_settings.parking_xpos[new_tool] + offsetcompensation;
178
 
178
 
179
     if (DEBUGGING(LEVELING)) {
179
     if (DEBUGGING(LEVELING)) {
180
-      DEBUG_ECHOPAIR("(1) Move extruder ", int(tmp_extruder));
180
+      DEBUG_ECHOPAIR("(1) Move extruder ", int(new_tool));
181
       DEBUG_POS(" to new extruder ParkPos", current_position);
181
       DEBUG_POS(" to new extruder ParkPos", current_position);
182
     }
182
     }
183
 
183
 
184
-    planner.buffer_line(current_position, mpe_settings.fast_feedrate, tmp_extruder);
184
+    planner.buffer_line(current_position, mpe_settings.fast_feedrate, new_tool);
185
     planner.synchronize();
185
     planner.synchronize();
186
 
186
 
187
     // STEP 2
187
     // STEP 2
189
     current_position[X_AXIS] = grabpos + offsetcompensation;
189
     current_position[X_AXIS] = grabpos + offsetcompensation;
190
 
190
 
191
     if (DEBUGGING(LEVELING)) {
191
     if (DEBUGGING(LEVELING)) {
192
-      DEBUG_ECHOPAIR("(2) Couple extruder ", int(tmp_extruder));
192
+      DEBUG_ECHOPAIR("(2) Couple extruder ", int(new_tool));
193
       DEBUG_POS(" to new extruder GrabPos", current_position);
193
       DEBUG_POS(" to new extruder GrabPos", current_position);
194
     }
194
     }
195
 
195
 
196
-    planner.buffer_line(current_position, mpe_settings.slow_feedrate, tmp_extruder);
196
+    planner.buffer_line(current_position, mpe_settings.slow_feedrate, new_tool);
197
     planner.synchronize();
197
     planner.synchronize();
198
 
198
 
199
     // Delay before moving tool, to allow magnetic coupling
199
     // Delay before moving tool, to allow magnetic coupling
201
 
201
 
202
     // STEP 3
202
     // STEP 3
203
 
203
 
204
-    current_position[X_AXIS] = mpe_settings.parking_xpos[tmp_extruder] + offsetcompensation;
204
+    current_position[X_AXIS] = mpe_settings.parking_xpos[new_tool] + offsetcompensation;
205
     if (DEBUGGING(LEVELING)) {
205
     if (DEBUGGING(LEVELING)) {
206
-      DEBUG_ECHOPAIR("(3) Move extruder ", int(tmp_extruder));
206
+      DEBUG_ECHOPAIR("(3) Move extruder ", int(new_tool));
207
       DEBUG_POS(" back to new extruder ParkPos", current_position);
207
       DEBUG_POS(" back to new extruder ParkPos", current_position);
208
     }
208
     }
209
 
209
 
210
-    planner.buffer_line(current_position, mpe_settings.slow_feedrate, tmp_extruder);
210
+    planner.buffer_line(current_position, mpe_settings.slow_feedrate, new_tool);
211
     planner.synchronize();
211
     planner.synchronize();
212
 
212
 
213
     // STEP 4
213
     // STEP 4
214
 
214
 
215
     current_position[X_AXIS] = mpe_settings.parking_xpos[active_extruder] + (active_extruder == 0 ? MPE_TRAVEL_DISTANCE : -MPE_TRAVEL_DISTANCE) + offsetcompensation;
215
     current_position[X_AXIS] = mpe_settings.parking_xpos[active_extruder] + (active_extruder == 0 ? MPE_TRAVEL_DISTANCE : -MPE_TRAVEL_DISTANCE) + offsetcompensation;
216
     if (DEBUGGING(LEVELING)) {
216
     if (DEBUGGING(LEVELING)) {
217
-      DEBUG_ECHOPAIR("(4) Move extruder ", int(tmp_extruder));
217
+      DEBUG_ECHOPAIR("(4) Move extruder ", int(new_tool));
218
       DEBUG_POS(" close to old extruder ParkPos", current_position);
218
       DEBUG_POS(" close to old extruder ParkPos", current_position);
219
     }
219
     }
220
 
220
 
221
-    planner.buffer_line(current_position, mpe_settings.fast_feedrate, tmp_extruder);
221
+    planner.buffer_line(current_position, mpe_settings.fast_feedrate, new_tool);
222
     planner.synchronize();
222
     planner.synchronize();
223
 
223
 
224
     // STEP 5
224
     // STEP 5
226
     current_position[X_AXIS] = mpe_settings.parking_xpos[active_extruder] + offsetcompensation;
226
     current_position[X_AXIS] = mpe_settings.parking_xpos[active_extruder] + offsetcompensation;
227
 
227
 
228
     if (DEBUGGING(LEVELING)) {
228
     if (DEBUGGING(LEVELING)) {
229
-      DEBUG_ECHOPAIR("(5) Park extruder ", int(tmp_extruder));
229
+      DEBUG_ECHOPAIR("(5) Park extruder ", int(new_tool));
230
       DEBUG_POS(" at old extruder ParkPos", current_position);
230
       DEBUG_POS(" at old extruder ParkPos", current_position);
231
     }
231
     }
232
 
232
 
233
-    planner.buffer_line(current_position, mpe_settings.slow_feedrate, tmp_extruder);
233
+    planner.buffer_line(current_position, mpe_settings.slow_feedrate, new_tool);
234
     planner.synchronize();
234
     planner.synchronize();
235
 
235
 
236
     // STEP 6
236
     // STEP 6
238
     current_position[X_AXIS] = oldx;
238
     current_position[X_AXIS] = oldx;
239
 
239
 
240
     if (DEBUGGING(LEVELING)) {
240
     if (DEBUGGING(LEVELING)) {
241
-      DEBUG_ECHOPAIR("(6) Move extruder ", int(tmp_extruder));
241
+      DEBUG_ECHOPAIR("(6) Move extruder ", int(new_tool));
242
       DEBUG_POS(" to starting position", current_position);
242
       DEBUG_POS(" to starting position", current_position);
243
     }
243
     }
244
 
244
 
245
-    planner.buffer_line(current_position, mpe_settings.fast_feedrate, tmp_extruder);
245
+    planner.buffer_line(current_position, mpe_settings.fast_feedrate, new_tool);
246
     planner.synchronize();
246
     planner.synchronize();
247
 
247
 
248
     if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Autopark done.");
248
     if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Autopark done.");
269
     #endif
269
     #endif
270
   }
270
   }
271
 
271
 
272
-  inline void parking_extruder_tool_change(const uint8_t tmp_extruder, bool no_move) {
272
+  inline void parking_extruder_tool_change(const uint8_t new_tool, bool no_move) {
273
     if (!no_move) {
273
     if (!no_move) {
274
 
274
 
275
       constexpr float parkingposx[] = PARKING_EXTRUDER_PARKING_X;
275
       constexpr float parkingposx[] = PARKING_EXTRUDER_PARKING_X;
281
       #endif
281
       #endif
282
 
282
 
283
       const float midpos = (parkingposx[0] + parkingposx[1]) * 0.5 + x_offset,
283
       const float midpos = (parkingposx[0] + parkingposx[1]) * 0.5 + x_offset,
284
-                  grabpos = parkingposx[tmp_extruder] + (tmp_extruder ? PARKING_EXTRUDER_GRAB_DISTANCE : -(PARKING_EXTRUDER_GRAB_DISTANCE)) + x_offset;
284
+                  grabpos = parkingposx[new_tool] + (new_tool ? PARKING_EXTRUDER_GRAB_DISTANCE : -(PARKING_EXTRUDER_GRAB_DISTANCE)) + x_offset;
285
 
285
 
286
       /**
286
       /**
287
        * 1. Move to park position of old extruder
287
        * 1. Move to park position of old extruder
325
       #if ENABLED(PARKING_EXTRUDER_SOLENOIDS_INVERT)
325
       #if ENABLED(PARKING_EXTRUDER_SOLENOIDS_INVERT)
326
         pe_activate_solenoid(active_extruder); // Just save power for inverted magnets
326
         pe_activate_solenoid(active_extruder); // Just save power for inverted magnets
327
       #endif
327
       #endif
328
-      pe_activate_solenoid(tmp_extruder);
328
+      pe_activate_solenoid(new_tool);
329
 
329
 
330
       // STEP 5
330
       // STEP 5
331
 
331
 
332
-      current_position[X_AXIS] = grabpos + (tmp_extruder ? -10 : 10);
332
+      current_position[X_AXIS] = grabpos + (new_tool ? -10 : 10);
333
       fast_line_to_current(X_AXIS);
333
       fast_line_to_current(X_AXIS);
334
 
334
 
335
       current_position[X_AXIS] = grabpos;
335
       current_position[X_AXIS] = grabpos;
343
 
343
 
344
       current_position[X_AXIS] = midpos
344
       current_position[X_AXIS] = midpos
345
         #if HAS_HOTEND_OFFSET
345
         #if HAS_HOTEND_OFFSET
346
-          - hotend_offset[X_AXIS][tmp_extruder]
346
+          - hotend_offset[X_AXIS][new_tool]
347
         #endif
347
         #endif
348
       ;
348
       ;
349
       if (DEBUGGING(LEVELING)) {
349
       if (DEBUGGING(LEVELING)) {
357
     }
357
     }
358
     else { // nomove == true
358
     else { // nomove == true
359
       // Only engage magnetic field for new extruder
359
       // Only engage magnetic field for new extruder
360
-      pe_activate_solenoid(tmp_extruder);
360
+      pe_activate_solenoid(new_tool);
361
       #if ENABLED(PARKING_EXTRUDER_SOLENOIDS_INVERT)
361
       #if ENABLED(PARKING_EXTRUDER_SOLENOIDS_INVERT)
362
         pe_activate_solenoid(active_extruder); // Just save power for inverted magnets
362
         pe_activate_solenoid(active_extruder); // Just save power for inverted magnets
363
       #endif
363
       #endif
368
 
368
 
369
 #if ENABLED(SWITCHING_TOOLHEAD)
369
 #if ENABLED(SWITCHING_TOOLHEAD)
370
 
370
 
371
-  inline void switching_toolhead_tool_change(const uint8_t tmp_extruder, bool no_move/*=false*/) {
371
+  inline void switching_toolhead_tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
372
     if (no_move) return;
372
     if (no_move) return;
373
 
373
 
374
     constexpr uint16_t angles[2] = SWITCHING_TOOLHEAD_SERVO_ANGLES;
374
     constexpr uint16_t angles[2] = SWITCHING_TOOLHEAD_SERVO_ANGLES;
375
 
375
 
376
     constexpr float toolheadposx[] = SWITCHING_TOOLHEAD_X_POS;
376
     constexpr float toolheadposx[] = SWITCHING_TOOLHEAD_X_POS;
377
     const float placexpos = toolheadposx[active_extruder],
377
     const float placexpos = toolheadposx[active_extruder],
378
-                grabxpos = toolheadposx[tmp_extruder];
378
+                grabxpos = toolheadposx[new_tool];
379
 
379
 
380
     /**
380
     /**
381
      * 1. Move to switch position of current toolhead
381
      * 1. Move to switch position of current toolhead
464
 
464
 
465
 #elif ENABLED(MAGNETIC_SWITCHING_TOOLHEAD)
465
 #elif ENABLED(MAGNETIC_SWITCHING_TOOLHEAD)
466
 
466
 
467
-  inline void magnetic_switching_toolhead_tool_change(const uint8_t tmp_extruder, bool no_move/*=false*/) {
467
+  inline void magnetic_switching_toolhead_tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
468
     if (no_move) return;
468
     if (no_move) return;
469
 
469
 
470
     constexpr float toolheadposx[] = SWITCHING_TOOLHEAD_X_POS,
470
     constexpr float toolheadposx[] = SWITCHING_TOOLHEAD_X_POS,
472
 
472
 
473
     const float placexpos = toolheadposx[active_extruder],
473
     const float placexpos = toolheadposx[active_extruder],
474
                 placexclear = toolheadclearx[active_extruder],
474
                 placexclear = toolheadclearx[active_extruder],
475
-                grabxpos = toolheadposx[tmp_extruder],
476
-                grabxclear = toolheadclearx[tmp_extruder];
475
+                grabxpos = toolheadposx[new_tool],
476
+                grabxclear = toolheadclearx[new_tool];
477
 
477
 
478
     /**
478
     /**
479
      * 1. Move to switch position of current toolhead
479
      * 1. Move to switch position of current toolhead
564
     #if ENABLED(PRIME_BEFORE_REMOVE) && (SWITCHING_TOOLHEAD_PRIME_MM || SWITCHING_TOOLHEAD_RETRACT_MM)
564
     #if ENABLED(PRIME_BEFORE_REMOVE) && (SWITCHING_TOOLHEAD_PRIME_MM || SWITCHING_TOOLHEAD_RETRACT_MM)
565
       #if SWITCHING_TOOLHEAD_PRIME_MM
565
       #if SWITCHING_TOOLHEAD_PRIME_MM
566
         current_position[E_AXIS] += SWITCHING_TOOLHEAD_PRIME_MM;
566
         current_position[E_AXIS] += SWITCHING_TOOLHEAD_PRIME_MM;
567
-        planner.buffer_line(current_position, MMM_TO_MMS(SWITCHING_TOOLHEAD_PRIME_FEEDRATE), tmp_extruder);
567
+        planner.buffer_line(current_position, MMM_TO_MMS(SWITCHING_TOOLHEAD_PRIME_FEEDRATE), new_tool);
568
       #endif
568
       #endif
569
       #if SWITCHING_TOOLHEAD_RETRACT_MM
569
       #if SWITCHING_TOOLHEAD_RETRACT_MM
570
         current_position[E_AXIS] -= SWITCHING_TOOLHEAD_RETRACT_MM;
570
         current_position[E_AXIS] -= SWITCHING_TOOLHEAD_RETRACT_MM;
571
-        planner.buffer_line(current_position, MMM_TO_MMS(SWITCHING_TOOLHEAD_RETRACT_FEEDRATE), tmp_extruder);
571
+        planner.buffer_line(current_position, MMM_TO_MMS(SWITCHING_TOOLHEAD_RETRACT_FEEDRATE), new_tool);
572
       #endif
572
       #endif
573
     #else
573
     #else
574
       planner.synchronize();
574
       planner.synchronize();
595
   inline void est_deactivate_solenoid() { OUT_WRITE(SOL0_PIN, LOW); }
595
   inline void est_deactivate_solenoid() { OUT_WRITE(SOL0_PIN, LOW); }
596
   void est_init() { est_activate_solenoid(); }
596
   void est_init() { est_activate_solenoid(); }
597
 
597
 
598
-  inline void em_switching_toolhead_tool_change(const uint8_t tmp_extruder, bool no_move) {
598
+  inline void em_switching_toolhead_tool_change(const uint8_t new_tool, bool no_move) {
599
     if (no_move) return;
599
     if (no_move) return;
600
 
600
 
601
     constexpr float toolheadposx[] = SWITCHING_TOOLHEAD_X_POS;
601
     constexpr float toolheadposx[] = SWITCHING_TOOLHEAD_X_POS;
602
     const float placexpos = toolheadposx[active_extruder],
602
     const float placexpos = toolheadposx[active_extruder],
603
-                grabxpos = toolheadposx[tmp_extruder];
603
+                grabxpos = toolheadposx[new_tool];
604
 
604
 
605
     /**
605
     /**
606
      * 1. Raise Z-Axis to give enough clearance
606
      * 1. Raise Z-Axis to give enough clearance
688
     // 9. Apply Z hotend offset to current position
688
     // 9. Apply Z hotend offset to current position
689
 
689
 
690
     if (DEBUGGING(LEVELING)) DEBUG_POS("(9) Applying Z-offset", current_position);
690
     if (DEBUGGING(LEVELING)) DEBUG_POS("(9) Applying Z-offset", current_position);
691
-    current_position[Z_AXIS] += hotend_offset[Z_AXIS][active_extruder] - hotend_offset[Z_AXIS][tmp_extruder];
691
+    current_position[Z_AXIS] += hotend_offset[Z_AXIS][active_extruder] - hotend_offset[Z_AXIS][new_tool];
692
 
692
 
693
     if (DEBUGGING(LEVELING)) DEBUG_POS("EMST Tool-Change done.", current_position);
693
     if (DEBUGGING(LEVELING)) DEBUG_POS("EMST Tool-Change done.", current_position);
694
   }
694
   }
703
 
703
 
704
 #if ENABLED(DUAL_X_CARRIAGE)
704
 #if ENABLED(DUAL_X_CARRIAGE)
705
 
705
 
706
-  inline void dualx_tool_change(const uint8_t tmp_extruder, bool &no_move) {
706
+  inline void dualx_tool_change(const uint8_t new_tool, bool &no_move) {
707
     if (DEBUGGING(LEVELING)) {
707
     if (DEBUGGING(LEVELING)) {
708
       DEBUG_ECHOPGM("Dual X Carriage Mode ");
708
       DEBUG_ECHOPGM("Dual X Carriage Mode ");
709
       switch (dual_x_carriage_mode) {
709
       switch (dual_x_carriage_mode) {
728
     }
728
     }
729
 
729
 
730
     // Activate the new extruder ahead of calling set_axis_is_at_home!
730
     // Activate the new extruder ahead of calling set_axis_is_at_home!
731
-    active_extruder = tmp_extruder;
731
+    active_extruder = new_tool;
732
 
732
 
733
     // This function resets the max/min values - the current position may be overwritten below.
733
     // This function resets the max/min values - the current position may be overwritten below.
734
     set_axis_is_at_home(X_AXIS);
734
     set_axis_is_at_home(X_AXIS);
764
  * Perform a tool-change, which may result in moving the
764
  * Perform a tool-change, which may result in moving the
765
  * previous tool out of the way and the new tool into place.
765
  * previous tool out of the way and the new tool into place.
766
  */
766
  */
767
-void tool_change(const uint8_t tmp_extruder, bool no_move/*=false*/) {
767
+void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
768
 
768
 
769
   #if ENABLED(MAGNETIC_SWITCHING_TOOLHEAD)
769
   #if ENABLED(MAGNETIC_SWITCHING_TOOLHEAD)
770
-    if (tmp_extruder == active_extruder) return;
770
+    if (new_tool == active_extruder) return;
771
   #endif
771
   #endif
772
 
772
 
773
+  const uint8_t old_tool = active_extruder;
774
+
773
   #if ENABLED(MIXING_EXTRUDER)
775
   #if ENABLED(MIXING_EXTRUDER)
774
 
776
 
775
     UNUSED(no_move);
777
     UNUSED(no_move);
776
 
778
 
777
-    if (tmp_extruder >= MIXING_VIRTUAL_TOOLS)
778
-      return invalid_extruder_error(tmp_extruder);
779
+    if (new_tool >= MIXING_VIRTUAL_TOOLS)
780
+      return invalid_extruder_error(new_tool);
779
 
781
 
780
     #if MIXING_VIRTUAL_TOOLS > 1
782
     #if MIXING_VIRTUAL_TOOLS > 1
781
       // T0-Tnnn: Switch virtual tool by changing the index to the mix
783
       // T0-Tnnn: Switch virtual tool by changing the index to the mix
782
-      mixer.T(tmp_extruder);
784
+      mixer.T(new_tool);
783
     #endif
785
     #endif
784
 
786
 
785
   #elif ENABLED(PRUSA_MMU2)
787
   #elif ENABLED(PRUSA_MMU2)
786
 
788
 
787
     UNUSED(no_move);
789
     UNUSED(no_move);
788
 
790
 
789
-    mmu2.tool_change(tmp_extruder);
791
+    mmu2.tool_change(new_tool);
790
 
792
 
791
   #elif EXTRUDERS < 2
793
   #elif EXTRUDERS < 2
792
 
794
 
793
     UNUSED(no_move);
795
     UNUSED(no_move);
794
 
796
 
795
-    if (tmp_extruder) invalid_extruder_error(tmp_extruder);
797
+    if (new_tool) invalid_extruder_error(new_tool);
796
     return;
798
     return;
797
 
799
 
798
   #else // EXTRUDERS > 1
800
   #else // EXTRUDERS > 1
800
     planner.synchronize();
802
     planner.synchronize();
801
 
803
 
802
     #if ENABLED(DUAL_X_CARRIAGE)  // Only T0 allowed if the Printer is in DXC_DUPLICATION_MODE or DXC_MIRRORED_MODE
804
     #if ENABLED(DUAL_X_CARRIAGE)  // Only T0 allowed if the Printer is in DXC_DUPLICATION_MODE or DXC_MIRRORED_MODE
803
-      if (tmp_extruder != 0 && dxc_is_duplicating())
804
-         return invalid_extruder_error(tmp_extruder);
805
+      if (new_tool != 0 && dxc_is_duplicating())
806
+         return invalid_extruder_error(new_tool);
805
     #endif
807
     #endif
806
 
808
 
807
-    if (tmp_extruder >= EXTRUDERS)
808
-      return invalid_extruder_error(tmp_extruder);
809
+    if (new_tool >= EXTRUDERS)
810
+      return invalid_extruder_error(new_tool);
809
 
811
 
810
     if (!no_move && !all_axes_homed()) {
812
     if (!no_move && !all_axes_homed()) {
811
       no_move = true;
813
       no_move = true;
827
     #if ENABLED(TOOLCHANGE_FILAMENT_SWAP)
829
     #if ENABLED(TOOLCHANGE_FILAMENT_SWAP)
828
       const bool should_swap = can_move_away && toolchange_settings.swap_length;
830
       const bool should_swap = can_move_away && toolchange_settings.swap_length;
829
       #if ENABLED(PREVENT_COLD_EXTRUSION)
831
       #if ENABLED(PREVENT_COLD_EXTRUSION)
830
-        const bool too_cold = !DEBUGGING(DRYRUN) && (thermalManager.targetTooColdToExtrude(active_extruder) || thermalManager.targetTooColdToExtrude(tmp_extruder));
832
+        const bool too_cold = !DEBUGGING(DRYRUN) && (thermalManager.targetTooColdToExtrude(old_tool) || thermalManager.targetTooColdToExtrude(new_tool));
831
       #else
833
       #else
832
         constexpr bool too_cold = false;
834
         constexpr bool too_cold = false;
833
       #endif
835
       #endif
835
         if (too_cold) {
837
         if (too_cold) {
836
           SERIAL_ECHO_MSG(MSG_ERR_HOTEND_TOO_COLD);
838
           SERIAL_ECHO_MSG(MSG_ERR_HOTEND_TOO_COLD);
837
           #if ENABLED(SINGLENOZZLE)
839
           #if ENABLED(SINGLENOZZLE)
838
-            active_extruder = tmp_extruder;
840
+            active_extruder = new_tool;
839
             return;
841
             return;
840
           #endif
842
           #endif
841
         }
843
         }
843
           #if ENABLED(ADVANCED_PAUSE_FEATURE)
845
           #if ENABLED(ADVANCED_PAUSE_FEATURE)
844
             do_pause_e_move(-toolchange_settings.swap_length, MMM_TO_MMS(toolchange_settings.retract_speed));
846
             do_pause_e_move(-toolchange_settings.swap_length, MMM_TO_MMS(toolchange_settings.retract_speed));
845
           #else
847
           #else
846
-            current_position[E_AXIS] -= toolchange_settings.swap_length / planner.e_factor[active_extruder];
847
-            planner.buffer_line(current_position, MMM_TO_MMS(toolchange_settings.retract_speed), active_extruder);
848
+            current_position[E_AXIS] -= toolchange_settings.swap_length / planner.e_factor[old_tool];
849
+            planner.buffer_line(current_position, MMM_TO_MMS(toolchange_settings.retract_speed), old_tool);
848
             planner.synchronize();
850
             planner.synchronize();
849
           #endif
851
           #endif
850
         }
852
         }
856
       TEMPORARY_BED_LEVELING_STATE(false);
858
       TEMPORARY_BED_LEVELING_STATE(false);
857
     #endif
859
     #endif
858
 
860
 
859
-    if (tmp_extruder != active_extruder) {
861
+    if (new_tool != old_tool) {
860
 
862
 
861
       #if SWITCHING_NOZZLE_TWO_SERVOS
863
       #if SWITCHING_NOZZLE_TWO_SERVOS
862
-        raise_nozzle(active_extruder);
864
+        raise_nozzle(old_tool);
863
       #endif
865
       #endif
864
 
866
 
865
       REMEMBER(fr, feedrate_mm_s, XY_PROBE_FEEDRATE_MM_S);
867
       REMEMBER(fr, feedrate_mm_s, XY_PROBE_FEEDRATE_MM_S);
866
 
868
 
867
       #if HAS_SOFTWARE_ENDSTOPS
869
       #if HAS_SOFTWARE_ENDSTOPS
868
         #if HAS_HOTEND_OFFSET
870
         #if HAS_HOTEND_OFFSET
869
-          #define _EXT_ARGS , active_extruder, tmp_extruder
871
+          #define _EXT_ARGS , old_tool, new_tool
870
         #else
872
         #else
871
           #define _EXT_ARGS
873
           #define _EXT_ARGS
872
         #endif
874
         #endif
891
             current_position[X_AXIS] = toolchange_settings.change_point.x;
893
             current_position[X_AXIS] = toolchange_settings.change_point.x;
892
             current_position[Y_AXIS] = toolchange_settings.change_point.y;
894
             current_position[Y_AXIS] = toolchange_settings.change_point.y;
893
           #endif
895
           #endif
894
-          planner.buffer_line(current_position, feedrate_mm_s, active_extruder);
896
+          planner.buffer_line(current_position, feedrate_mm_s, old_tool);
895
           planner.synchronize();
897
           planner.synchronize();
896
         }
898
         }
897
       #endif
899
       #endif
900
         #if ENABLED(DUAL_X_CARRIAGE)
902
         #if ENABLED(DUAL_X_CARRIAGE)
901
           constexpr float xdiff = 0;
903
           constexpr float xdiff = 0;
902
         #else
904
         #else
903
-          const float xdiff = hotend_offset[X_AXIS][tmp_extruder] - hotend_offset[X_AXIS][active_extruder];
905
+          const float xdiff = hotend_offset[X_AXIS][new_tool] - hotend_offset[X_AXIS][old_tool];
904
         #endif
906
         #endif
905
-        const float ydiff = hotend_offset[Y_AXIS][tmp_extruder] - hotend_offset[Y_AXIS][active_extruder],
906
-                    zdiff = hotend_offset[Z_AXIS][tmp_extruder] - hotend_offset[Z_AXIS][active_extruder];
907
+        const float ydiff = hotend_offset[Y_AXIS][new_tool] - hotend_offset[Y_AXIS][old_tool],
908
+                    zdiff = hotend_offset[Z_AXIS][new_tool] - hotend_offset[Z_AXIS][old_tool];
907
       #else
909
       #else
908
         constexpr float xdiff = 0, ydiff = 0, zdiff = 0;
910
         constexpr float xdiff = 0, ydiff = 0, zdiff = 0;
909
       #endif
911
       #endif
910
 
912
 
911
       #if ENABLED(DUAL_X_CARRIAGE)
913
       #if ENABLED(DUAL_X_CARRIAGE)
912
-        dualx_tool_change(tmp_extruder, no_move);
914
+        dualx_tool_change(new_tool, no_move);
913
       #elif ENABLED(PARKING_EXTRUDER)                                   // Dual Parking extruder
915
       #elif ENABLED(PARKING_EXTRUDER)                                   // Dual Parking extruder
914
-        parking_extruder_tool_change(tmp_extruder, no_move);
916
+        parking_extruder_tool_change(new_tool, no_move);
915
       #elif ENABLED(MAGNETIC_PARKING_EXTRUDER)                          // Magnetic Parking extruder
917
       #elif ENABLED(MAGNETIC_PARKING_EXTRUDER)                          // Magnetic Parking extruder
916
-        magnetic_parking_extruder_tool_change(tmp_extruder);
918
+        magnetic_parking_extruder_tool_change(new_tool);
917
       #elif ENABLED(SWITCHING_TOOLHEAD)                                 // Switching Toolhead
919
       #elif ENABLED(SWITCHING_TOOLHEAD)                                 // Switching Toolhead
918
-        switching_toolhead_tool_change(tmp_extruder, no_move);
920
+        switching_toolhead_tool_change(new_tool, no_move);
919
       #elif ENABLED(MAGNETIC_SWITCHING_TOOLHEAD)                        // Magnetic Switching Toolhead
921
       #elif ENABLED(MAGNETIC_SWITCHING_TOOLHEAD)                        // Magnetic Switching Toolhead
920
-        magnetic_switching_toolhead_tool_change(tmp_extruder, no_move);
922
+        magnetic_switching_toolhead_tool_change(new_tool, no_move);
921
       #elif ENABLED(ELECTROMAGNETIC_SWITCHING_TOOLHEAD)                 // Magnetic Switching ToolChanger
923
       #elif ENABLED(ELECTROMAGNETIC_SWITCHING_TOOLHEAD)                 // Magnetic Switching ToolChanger
922
-        em_switching_toolhead_tool_change(tmp_extruder, no_move);
924
+        em_switching_toolhead_tool_change(new_tool, no_move);
923
       #elif ENABLED(SWITCHING_NOZZLE) && !SWITCHING_NOZZLE_TWO_SERVOS   // Switching Nozzle (single servo)
925
       #elif ENABLED(SWITCHING_NOZZLE) && !SWITCHING_NOZZLE_TWO_SERVOS   // Switching Nozzle (single servo)
924
         // Raise by a configured distance to avoid workpiece, except with
926
         // Raise by a configured distance to avoid workpiece, except with
925
         // SWITCHING_NOZZLE_TWO_SERVOS, as both nozzles will lift instead.
927
         // SWITCHING_NOZZLE_TWO_SERVOS, as both nozzles will lift instead.
928
           NOMORE(current_position[Z_AXIS], soft_endstop[Z_AXIS].max);
930
           NOMORE(current_position[Z_AXIS], soft_endstop[Z_AXIS].max);
929
         #endif
931
         #endif
930
         if (!no_move) fast_line_to_current(Z_AXIS);
932
         if (!no_move) fast_line_to_current(Z_AXIS);
931
-        move_nozzle_servo(tmp_extruder);
933
+        move_nozzle_servo(new_tool);
932
       #endif
934
       #endif
933
 
935
 
934
       if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Offset Tool XY by { ", xdiff, ", ", ydiff, ", ", zdiff, " }");
936
       if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Offset Tool XY by { ", xdiff, ", ", ydiff, ", ", zdiff, " }");
939
       current_position[Z_AXIS] += zdiff;
941
       current_position[Z_AXIS] += zdiff;
940
 
942
 
941
       // Set the new active extruder if not already done in tool specific function above
943
       // Set the new active extruder if not already done in tool specific function above
942
-      active_extruder = tmp_extruder;
944
+      active_extruder = new_tool;
943
 
945
 
944
       // Tell the planner the new "current position"
946
       // Tell the planner the new "current position"
945
       sync_plan_position();
947
       sync_plan_position();
956
 
958
 
957
         #if ENABLED(SINGLENOZZLE)
959
         #if ENABLED(SINGLENOZZLE)
958
           #if FAN_COUNT > 0
960
           #if FAN_COUNT > 0
959
-            singlenozzle_fan_speed[active_extruder] = thermalManager.fan_speed[0];
960
-            thermalManager.fan_speed[0] = singlenozzle_fan_speed[tmp_extruder];
961
+            singlenozzle_fan_speed[old_tool] = thermalManager.fan_speed[0];
962
+            thermalManager.fan_speed[0] = singlenozzle_fan_speed[new_tool];
961
           #endif
963
           #endif
962
 
964
 
963
-          singlenozzle_temp[active_extruder] = thermalManager.temp_hotend[0].target;
964
-          if (singlenozzle_temp[tmp_extruder] && singlenozzle_temp[tmp_extruder] != singlenozzle_temp[active_extruder]) {
965
-            thermalManager.setTargetHotend(singlenozzle_temp[tmp_extruder], 0);
965
+          singlenozzle_temp[old_tool] = thermalManager.temp_hotend[0].target;
966
+          if (singlenozzle_temp[new_tool] && singlenozzle_temp[new_tool] != singlenozzle_temp[old_tool]) {
967
+            thermalManager.setTargetHotend(singlenozzle_temp[new_tool], 0);
966
             #if HAS_DISPLAY
968
             #if HAS_DISPLAY
967
               thermalManager.set_heating_message(0);
969
               thermalManager.set_heating_message(0);
968
             #endif
970
             #endif
969
             (void)thermalManager.wait_for_hotend(0, false);  // Wait for heating or cooling
971
             (void)thermalManager.wait_for_hotend(0, false);  // Wait for heating or cooling
970
           }
972
           }
971
-          active_extruder = tmp_extruder;
972
         #endif
973
         #endif
973
 
974
 
974
         #if ENABLED(TOOLCHANGE_FILAMENT_SWAP)
975
         #if ENABLED(TOOLCHANGE_FILAMENT_SWAP)
975
           if (should_swap && !too_cold) {
976
           if (should_swap && !too_cold) {
976
             #if ENABLED(ADVANCED_PAUSE_FEATURE)
977
             #if ENABLED(ADVANCED_PAUSE_FEATURE)
977
-              do_pause_e_move(toolchange_settings.swap_length + toolchange_settings.extra_prime, MMM_TO_MMS(toolchange_settings.prime_speed));
978
+              do_pause_e_move(toolchange_settings.swap_length, MMM_TO_MMS(toolchange_settings.prime_speed));
979
+              do_pause_e_move(toolchange_settings.extra_prime, ADVANCED_PAUSE_PURGE_FEEDRATE);
978
             #else
980
             #else
979
-              current_position[E_AXIS] += (toolchange_settings.swap_length + toolchange_settings.extra_prime) / planner.e_factor[tmp_extruder];
980
-              planner.buffer_line(current_position, MMM_TO_MMS(toolchange_settings.prime_speed), tmp_extruder);
981
+              current_position[E_AXIS] += toolchange_settings.swap_length / planner.e_factor[new_tool];
982
+              planner.buffer_line(current_position, MMM_TO_MMS(toolchange_settings.prime_speed), new_tool);
983
+              current_position[E_AXIS] += toolchange_settings.extra_prime / planner.e_factor[new_tool];
984
+              planner.buffer_line(current_position, MMM_TO_MMS(toolchange_settings.prime_speed * 0.2f), new_tool);
981
             #endif
985
             #endif
982
             planner.synchronize();
986
             planner.synchronize();
983
             planner.set_e_position_mm((destination[E_AXIS] = current_position[E_AXIS] = current_position[E_AXIS] - (TOOLCHANGE_FIL_EXTRA_PRIME)));
987
             planner.set_e_position_mm((destination[E_AXIS] = current_position[E_AXIS] = current_position[E_AXIS] - (TOOLCHANGE_FIL_EXTRA_PRIME)));
989
           // If the original position is within tool store area, go to X origin at once
993
           // If the original position is within tool store area, go to X origin at once
990
           if (destination[Y_AXIS] < SWITCHING_TOOLHEAD_Y_POS + SWITCHING_TOOLHEAD_Y_CLEAR) {
994
           if (destination[Y_AXIS] < SWITCHING_TOOLHEAD_Y_POS + SWITCHING_TOOLHEAD_Y_CLEAR) {
991
             current_position[X_AXIS] = 0;
995
             current_position[X_AXIS] = 0;
992
-            planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[X_AXIS], active_extruder);
996
+            planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[X_AXIS], new_tool);
993
             planner.synchronize();
997
             planner.synchronize();
994
           }
998
           }
995
         #else
999
         #else
1022
       #endif
1026
       #endif
1023
 
1027
 
1024
       #if ENABLED(PRUSA_MMU2)
1028
       #if ENABLED(PRUSA_MMU2)
1025
-        mmu2.tool_change(tmp_extruder);
1029
+        mmu2.tool_change(new_tool);
1026
       #endif
1030
       #endif
1027
 
1031
 
1028
       #if SWITCHING_NOZZLE_TWO_SERVOS
1032
       #if SWITCHING_NOZZLE_TWO_SERVOS
1029
-        lower_nozzle(active_extruder);
1033
+        lower_nozzle(new_tool);
1030
       #endif
1034
       #endif
1031
 
1035
 
1032
-    } // (tmp_extruder != active_extruder)
1036
+    } // (new_tool != old_tool)
1033
 
1037
 
1034
     planner.synchronize();
1038
     planner.synchronize();
1035
 
1039
 
1039
     #endif
1043
     #endif
1040
 
1044
 
1041
     #if ENABLED(MK2_MULTIPLEXER)
1045
     #if ENABLED(MK2_MULTIPLEXER)
1042
-      if (tmp_extruder >= E_STEPPERS) return invalid_extruder_error(tmp_extruder);
1043
-      select_multiplexed_stepper(tmp_extruder);
1046
+      if (new_tool >= E_STEPPERS) return invalid_extruder_error(new_tool);
1047
+      select_multiplexed_stepper(new_tool);
1044
     #endif
1048
     #endif
1045
 
1049
 
1046
     #if DO_SWITCH_EXTRUDER
1050
     #if DO_SWITCH_EXTRUDER

Loading…
Cancel
Save