浏览代码

Fix PARKING_EXTRUDER homing with solenoid (#20473)

zeleps 3 年前
父节点
当前提交
815c636449
没有帐户链接到提交者的电子邮件

+ 11
- 4
Marlin/src/feature/solenoid.cpp 查看文件

@@ -28,22 +28,29 @@
28 28
 
29 29
 #include "../module/motion.h" // for active_extruder
30 30
 
31
-#if ENABLED(MANUAL_SOLENOID_CONTROL)
32
-  #define HAS_SOLENOID(N) HAS_SOLENOID_##N
31
+// PARKING_EXTRUDER options alter the default behavior of solenoids, this ensures compliance of M380-381
32
+
33
+#if ENABLED(PARKING_EXTRUDER)
34
+  #include "../module/tool_change.h"
35
+  #define SOLENOID_MAGNETIZED_STATE (TERN_(PARKING_EXTRUDER_SOLENOIDS_INVERT,!)PARKING_EXTRUDER_SOLENOIDS_PINS_ACTIVE)
33 36
 #else
34
-  #define HAS_SOLENOID(N) (HAS_SOLENOID_##N && EXTRUDERS > N)
37
+  #define SOLENOID_MAGNETIZED_STATE HIGH
35 38
 #endif
36 39
 
40
+#define HAS_SOLENOID(N) (HAS_SOLENOID_##N && TERN(MANUAL_SOLENOID_CONTROL, true, EXTRUDERS > N))
41
+
37 42
 // Used primarily with MANUAL_SOLENOID_CONTROL
38 43
 static void set_solenoid(const uint8_t num, const bool active) {
39
-  const uint8_t value = active ? HIGH : LOW;
44
+  const uint8_t value = active ? SOLENOID_MAGNETIZED_STATE : !SOLENOID_MAGNETIZED_STATE;
40 45
   switch (num) {
41 46
     case 0:
42 47
       OUT_WRITE(SOL0_PIN, value);
48
+      TERN_(PARKING_EXTRUDER, if (!active && active_extruder == 0) parking_extruder_set_parked()); // If active extruder's solenoid is disabled, carriage is considered parked
43 49
       break;
44 50
     #if HAS_SOLENOID(1)
45 51
       case 1:
46 52
         OUT_WRITE(SOL1_PIN, value);
53
+        TERN_(PARKING_EXTRUDER, if (!active && active_extruder == 1) parking_extruder_set_parked()); // If active extruder's solenoid is disabled, carriage is considered parked
47 54
         break;
48 55
     #endif
49 56
     #if HAS_SOLENOID(2)

+ 5
- 1
Marlin/src/gcode/calibrate/G28.cpp 查看文件

@@ -290,6 +290,10 @@ void GcodeSuite::G28() {
290 290
     #if DISABLED(DELTA) || ENABLED(DELTA_HOME_TO_SAFE_ZONE)
291 291
       const uint8_t old_tool_index = active_extruder;
292 292
     #endif
293
+    // PARKING_EXTRUDER homing requires different handling of movement / solenoid activation, depending on the side of homing
294
+    #if ENABLED(PARKING_EXTRUDER)
295
+      const bool pe_final_change_must_unpark = parking_extruder_unpark_after_homing(old_tool_index, X_HOME_DIR + 1 == old_tool_index * 2);
296
+    #endif
293 297
     tool_change(0, true);
294 298
   #endif
295 299
 
@@ -443,7 +447,7 @@ void GcodeSuite::G28() {
443 447
 
444 448
   // Restore the active tool after homing
445 449
   #if HAS_MULTI_HOTEND && (DISABLED(DELTA) || ENABLED(DELTA_HOME_TO_SAFE_ZONE))
446
-    tool_change(old_tool_index, NONE(PARKING_EXTRUDER, DUAL_X_CARRIAGE));   // Do move if one of these
450
+    tool_change(old_tool_index, TERN(PARKING_EXTRUDER, !pe_final_change_must_unpark, DISABLED(DUAL_X_CARRIAGE)));   // Do move if one of these
447 451
   #endif
448 452
 
449 453
   #if HAS_HOMING_CURRENT

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

@@ -61,16 +61,10 @@ void GcodeSuite::T(const int8_t tool_index) {
61 61
     }
62 62
   #endif
63 63
 
64
-  #if EXTRUDERS < 2
65
-
66
-    tool_change(tool_index);
67
-
68
-  #else
69
-
70
-    tool_change(
71
-      tool_index,
72
-      (tool_index == active_extruder) || parser.boolval('S')
73
-    );
74
-
75
-  #endif
64
+  tool_change(tool_index
65
+    #if HAS_MULTI_EXTRUDER
66
+      ,  TERN(PARKING_EXTRUDER, false, tool_index == active_extruder) // For PARKING_EXTRUDER motion is decided in tool_change()
67
+      || parser.boolval('S')
68
+    #endif
69
+  );
76 70
 }

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

@@ -277,6 +277,28 @@ inline void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_a
277 277
     #endif
278 278
   }
279 279
 
280
+  bool extruder_parked = true, do_solenoid_activation = true;
281
+
282
+  // Modifies tool_change() behavior based on homing side
283
+  bool parking_extruder_unpark_after_homing(const uint8_t final_tool, bool homed_towards_final_tool) {
284
+    do_solenoid_activation = false; // Tell parking_extruder_tool_change to skip solenoid activation
285
+
286
+    if (!extruder_parked) return false; // nothing to do
287
+
288
+    if (homed_towards_final_tool) {
289
+      pe_deactivate_solenoid(1 - final_tool);
290
+      DEBUG_ECHOLNPAIR("Disengage magnet", (int)(1 - final_tool));
291
+      pe_activate_solenoid(final_tool);
292
+      DEBUG_ECHOLNPAIR("Engage magnet", (int)final_tool);
293
+      extruder_parked = false;
294
+      return false;
295
+    }
296
+
297
+    return true;
298
+  }
299
+
300
+  void parking_extruder_set_parked() { extruder_parked = true; }
301
+
280 302
   inline void parking_extruder_tool_change(const uint8_t new_tool, bool no_move) {
281 303
     if (!no_move) {
282 304
 
@@ -304,27 +326,30 @@ inline void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_a
304 326
 
305 327
       DEBUG_POS("Start PE Tool-Change", current_position);
306 328
 
307
-      current_position.x = parkingposx[active_extruder] + x_offset;
329
+      // Don't park the active_extruder unless unparked
330
+      if (!extruder_parked) {
331
+        current_position.x = parkingposx[active_extruder] + x_offset;
308 332
 
309
-      DEBUG_ECHOLNPAIR("(1) Park extruder ", int(active_extruder));
310
-      DEBUG_POS("Moving ParkPos", current_position);
333
+        DEBUG_ECHOLNPAIR("(1) Park extruder ", int(active_extruder));
334
+        DEBUG_POS("Moving ParkPos", current_position);
311 335
 
312
-      fast_line_to_current(X_AXIS);
336
+        fast_line_to_current(X_AXIS);
313 337
 
314
-      // STEP 2
338
+        // STEP 2
315 339
 
316
-      planner.synchronize();
317
-      DEBUG_ECHOLNPGM("(2) Disengage magnet");
318
-      pe_deactivate_solenoid(active_extruder);
340
+        planner.synchronize();
341
+        DEBUG_ECHOLNPGM("(2) Disengage magnet");
342
+        pe_deactivate_solenoid(active_extruder);
319 343
 
320
-      // STEP 3
344
+        // STEP 3
321 345
 
322
-      current_position.x += active_extruder ? -10 : 10; // move 10mm away from parked extruder
346
+        current_position.x += active_extruder ? -10 : 10; // move 10mm away from parked extruder
323 347
 
324
-      DEBUG_ECHOLNPGM("(3) Move near new extruder");
325
-      DEBUG_POS("Move away from parked extruder", current_position);
348
+        DEBUG_ECHOLNPGM("(3) Move near new extruder");
349
+        DEBUG_POS("Move away from parked extruder", current_position);
326 350
 
327
-      fast_line_to_current(X_AXIS);
351
+        fast_line_to_current(X_AXIS);
352
+      }
328 353
 
329 354
       // STEP 4
330 355
 
@@ -358,13 +383,16 @@ inline void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_a
358 383
       planner.synchronize(); // Always sync the final move
359 384
 
360 385
       DEBUG_POS("PE Tool-Change done.", current_position);
386
+      extruder_parked = false;
361 387
     }
362
-    else { // nomove == true
388
+    else if (do_solenoid_activation) { // && nomove == true
389
+      // Deactivate old extruder solenoid
390
+      TERN(PARKING_EXTRUDER_SOLENOIDS_INVERT, pe_activate_solenoid, pe_deactivate_solenoid)(active_extruder);
363 391
       // Only engage magnetic field for new extruder
364
-      pe_activate_solenoid(new_tool);
365
-      // Just save power for inverted magnets
366
-      TERN_(PARKING_EXTRUDER_SOLENOIDS_INVERT, pe_activate_solenoid(active_extruder));
392
+      TERN(PARKING_EXTRUDER_SOLENOIDS_INVERT, pe_deactivate_solenoid, pe_activate_solenoid)(new_tool);
367 393
     }
394
+
395
+    do_solenoid_activation = true; // Activate solenoid for subsequent tool_change()
368 396
   }
369 397
 
370 398
 #endif // PARKING_EXTRUDER
@@ -922,7 +950,7 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
922 950
       }
923 951
     #endif
924 952
 
925
-    if (new_tool != old_tool) {
953
+    if (new_tool != old_tool || TERN0(PARKING_EXTRUDER, extruder_parked)) { // PARKING_EXTRUDER may need to attach old_tool when homing
926 954
       destination = current_position;
927 955
 
928 956
       #if BOTH(TOOLCHANGE_FILAMENT_SWAP, HAS_FAN) && TOOLCHANGE_FS_FAN >= 0

+ 3
- 0
Marlin/src/module/tool_change.h 查看文件

@@ -93,6 +93,9 @@
93 93
 
94 94
   void pe_solenoid_init();
95 95
 
96
+  bool parking_extruder_unpark_after_homing(const uint8_t final_tool, bool homed_towards_final_tool);
97
+  void parking_extruder_set_parked();
98
+
96 99
 #elif ENABLED(MAGNETIC_PARKING_EXTRUDER)
97 100
 
98 101
   typedef struct MPESettings {

正在加载...
取消
保存