浏览代码

Prevent a tool change move out of bounds

Scott Lahteine 6 年前
父节点
当前提交
bc87e97357
共有 1 个文件被更改,包括 29 次插入23 次删除
  1. 29
    23
      Marlin/src/module/tool_change.cpp

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

126
 
126
 
127
 #endif // SWITCHING_NOZZLE
127
 #endif // SWITCHING_NOZZLE
128
 
128
 
129
+inline void fast_line_to_current(const AxisEnum fr_axis) {
130
+  planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[fr_axis], active_extruder);
131
+}
132
+
129
 #if ENABLED(MAGNETIC_PARKING_EXTRUDER)
133
 #if ENABLED(MAGNETIC_PARKING_EXTRUDER)
130
 
134
 
131
   float parkingposx[2] ,           // M951 R L
135
   float parkingposx[2] ,           // M951 R L
308
         if (DEBUGGING(LEVELING)) DEBUG_POS("(1) Raise Z-Axis", current_position);
312
         if (DEBUGGING(LEVELING)) DEBUG_POS("(1) Raise Z-Axis", current_position);
309
       #endif
313
       #endif
310
 
314
 
311
-      planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Z_AXIS], active_extruder);
315
+      fast_line_to_current(Z_AXIS);
312
       planner.synchronize();
316
       planner.synchronize();
313
 
317
 
314
       // STEP 2
318
       // STEP 2
322
         }
326
         }
323
       #endif
327
       #endif
324
 
328
 
325
-      planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[X_AXIS], active_extruder);
329
+      fast_line_to_current(X_AXIS);
326
       planner.synchronize();
330
       planner.synchronize();
327
 
331
 
328
       // STEP 3
332
       // STEP 3
345
         if (DEBUGGING(LEVELING)) DEBUG_POS("Move away from parked extruder", current_position);
349
         if (DEBUGGING(LEVELING)) DEBUG_POS("Move away from parked extruder", current_position);
346
       #endif
350
       #endif
347
 
351
 
348
-      planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[X_AXIS], active_extruder);
352
+      fast_line_to_current(X_AXIS);
349
       planner.synchronize();
353
       planner.synchronize();
350
 
354
 
351
       // STEP 5
355
       // STEP 5
362
       // STEP 6
366
       // STEP 6
363
 
367
 
364
       current_position[X_AXIS] = grabpos + (tmp_extruder ? -10 : 10);
368
       current_position[X_AXIS] = grabpos + (tmp_extruder ? -10 : 10);
365
-      planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[X_AXIS], active_extruder);
369
+      fast_line_to_current(X_AXIS);
366
       current_position[X_AXIS] = grabpos;
370
       current_position[X_AXIS] = grabpos;
367
       #if ENABLED(DEBUG_LEVELING_FEATURE)
371
       #if ENABLED(DEBUG_LEVELING_FEATURE)
368
         if (DEBUGGING(LEVELING)) DEBUG_POS("(6) Unpark extruder", current_position);
372
         if (DEBUGGING(LEVELING)) DEBUG_POS("(6) Unpark extruder", current_position);
369
       #endif
373
       #endif
370
-      planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[X_AXIS]/2, active_extruder);
374
+      planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[X_AXIS] * 0.5, active_extruder);
371
       planner.synchronize();
375
       planner.synchronize();
372
 
376
 
373
       // STEP 7
377
       // STEP 7
382
         if (DEBUGGING(LEVELING)) DEBUG_POS("(7) Move midway between hotends", current_position);
386
         if (DEBUGGING(LEVELING)) DEBUG_POS("(7) Move midway between hotends", current_position);
383
       #endif
387
       #endif
384
 
388
 
385
-      planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[X_AXIS], active_extruder);
389
+      fast_line_to_current(X_AXIS);
386
       planner.synchronize();
390
       planner.synchronize();
387
 
391
 
388
       #if ENABLED(DEBUG_LEVELING_FEATURE)
392
       #if ENABLED(DEBUG_LEVELING_FEATURE)
428
      * 6. Apply the z-offset of the new toolhead
432
      * 6. Apply the z-offset of the new toolhead
429
      */
433
      */
430
 
434
 
431
-    // STEP 1
435
+    // 1. Raise Z to give enough clearance
432
 
436
 
433
     #if ENABLED(DEBUG_LEVELING_FEATURE)
437
     #if ENABLED(DEBUG_LEVELING_FEATURE)
434
       if (DEBUGGING(LEVELING)) DEBUG_POS("Starting Toolhead change", current_position);
438
       if (DEBUGGING(LEVELING)) DEBUG_POS("Starting Toolhead change", current_position);
440
       if (DEBUGGING(LEVELING)) DEBUG_POS("(1) Raise Z-Axis", current_position);
444
       if (DEBUGGING(LEVELING)) DEBUG_POS("(1) Raise Z-Axis", current_position);
441
     #endif
445
     #endif
442
 
446
 
443
-    planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Z_AXIS], active_extruder);
447
+    fast_line_to_current(Z_AXIS);
444
     planner.synchronize();
448
     planner.synchronize();
445
 
449
 
446
-    // STEP 2
450
+    // 2. Move to switch position of current toolhead
447
 
451
 
448
     current_position[X_AXIS] = placexpos;
452
     current_position[X_AXIS] = placexpos;
449
 
453
 
454
       }
458
       }
455
     #endif
459
     #endif
456
 
460
 
457
-    planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[X_AXIS], active_extruder);
461
+    fast_line_to_current(X_AXIS);
458
     planner.synchronize();
462
     planner.synchronize();
459
 
463
 
460
     current_position[Y_AXIS] = SWITCHING_TOOLHEAD_Y_POS - SWITCHING_TOOLHEAD_Y_SECURITY;
464
     current_position[Y_AXIS] = SWITCHING_TOOLHEAD_Y_POS - SWITCHING_TOOLHEAD_Y_SECURITY;
463
       if (DEBUGGING(LEVELING)) DEBUG_POS("Move Y SwitchPos + Security", current_position);
467
       if (DEBUGGING(LEVELING)) DEBUG_POS("Move Y SwitchPos + Security", current_position);
464
     #endif
468
     #endif
465
 
469
 
466
-    planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Y_AXIS], active_extruder);
470
+    fast_line_to_current(Y_AXIS);
467
     planner.synchronize();
471
     planner.synchronize();
468
 
472
 
469
-    // STEP 3
473
+    // 3. Unlock tool and drop it in the dock
470
 
474
 
471
     #if ENABLED(DEBUG_LEVELING_FEATURE)
475
     #if ENABLED(DEBUG_LEVELING_FEATURE)
472
       if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("(3) Unlock and Place Toolhead");
476
       if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("(3) Unlock and Place Toolhead");
490
       if (DEBUGGING(LEVELING)) DEBUG_POS("Move back Y clear", current_position);
494
       if (DEBUGGING(LEVELING)) DEBUG_POS("Move back Y clear", current_position);
491
     #endif
495
     #endif
492
 
496
 
493
-    planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Y_AXIS], active_extruder); // move away from docked toolhead
497
+    fast_line_to_current(Y_AXIS); // move away from docked toolhead
494
     planner.synchronize();
498
     planner.synchronize();
495
 
499
 
496
-    // STEP 4
500
+    // 4. Move to the new toolhead
497
 
501
 
498
     #if ENABLED(DEBUG_LEVELING_FEATURE)
502
     #if ENABLED(DEBUG_LEVELING_FEATURE)
499
       if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("(4) Move to new toolhead position");
503
       if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("(4) Move to new toolhead position");
505
       if (DEBUGGING(LEVELING)) DEBUG_POS("Move to new toolhead X", current_position);
509
       if (DEBUGGING(LEVELING)) DEBUG_POS("Move to new toolhead X", current_position);
506
     #endif
510
     #endif
507
 
511
 
508
-    planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[X_AXIS], active_extruder);
512
+    fast_line_to_current(X_AXIS);
509
     planner.synchronize();
513
     planner.synchronize();
510
     current_position[Y_AXIS] = SWITCHING_TOOLHEAD_Y_POS - SWITCHING_TOOLHEAD_Y_SECURITY;
514
     current_position[Y_AXIS] = SWITCHING_TOOLHEAD_Y_POS - SWITCHING_TOOLHEAD_Y_SECURITY;
511
 
515
 
513
       if (DEBUGGING(LEVELING)) DEBUG_POS("Move Y SwitchPos + Security", current_position);
517
       if (DEBUGGING(LEVELING)) DEBUG_POS("Move Y SwitchPos + Security", current_position);
514
     #endif
518
     #endif
515
 
519
 
516
-    planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Y_AXIS], active_extruder);
520
+    fast_line_to_current(Y_AXIS);
517
     planner.synchronize();
521
     planner.synchronize();
518
 
522
 
519
-    // STEP 5
523
+    // 5. Grab and lock the new toolhead
520
 
524
 
521
     #if ENABLED(DEBUG_LEVELING_FEATURE)
525
     #if ENABLED(DEBUG_LEVELING_FEATURE)
522
       if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("(5) Grab and lock new toolhead ");
526
       if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("(5) Grab and lock new toolhead ");
541
       if (DEBUGGING(LEVELING)) DEBUG_POS("Move back Y clear", current_position);
545
       if (DEBUGGING(LEVELING)) DEBUG_POS("Move back Y clear", current_position);
542
     #endif
546
     #endif
543
 
547
 
544
-    planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Y_AXIS], active_extruder); // move away from docked toolhead
548
+    fast_line_to_current(Y_AXIS); // move away from docked toolhead
545
     planner.synchronize();
549
     planner.synchronize();
546
 
550
 
547
-    // STEP 6
551
+    // 6. Apply the z-offset of the new toolhead
548
 
552
 
549
     #if HAS_HOTEND_OFFSET
553
     #if HAS_HOTEND_OFFSET
550
       current_position[Z_AXIS] += hotend_offset[Z_AXIS][active_extruder] - hotend_offset[Z_AXIS][tmp_extruder];
554
       current_position[Z_AXIS] += hotend_offset[Z_AXIS][active_extruder] - hotend_offset[Z_AXIS][tmp_extruder];
589
     ) {
593
     ) {
590
 
594
 
591
       #if ENABLED(DEBUG_LEVELING_FEATURE)
595
       #if ENABLED(DEBUG_LEVELING_FEATURE)
592
-        if (DEBUGGING(LEVELING)) {
593
-          SERIAL_ECHOLNPAIR("MoveX to ", xhome);
594
-        }
596
+        if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPAIR("MoveX to ", xhome);
595
       #endif
597
       #endif
596
       // Park old head
598
       // Park old head
597
       planner.buffer_line(xhome, current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], planner.settings.max_feedrate_mm_s[X_AXIS], active_extruder);
599
       planner.buffer_line(xhome, current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], planner.settings.max_feedrate_mm_s[X_AXIS], active_extruder);
797
         #if HAS_SOFTWARE_ENDSTOPS
799
         #if HAS_SOFTWARE_ENDSTOPS
798
           NOMORE(current_position[Z_AXIS], soft_endstop_max[Z_AXIS]);
800
           NOMORE(current_position[Z_AXIS], soft_endstop_max[Z_AXIS]);
799
         #endif
801
         #endif
800
-        if (!no_move)planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Z_AXIS], active_extruder);
802
+        if (!no_move) fast_line_to_current(Z_AXIS);
801
         move_nozzle_servo(tmp_extruder);
803
         move_nozzle_servo(tmp_extruder);
802
       #endif
804
       #endif
803
 
805
 
867
           }
869
           }
868
         #endif
870
         #endif
869
 
871
 
872
+        // Prevent a move outside physical bounds
873
+        clamp_to_software_endstops(destination);
874
+
870
         // Move back to the original (or tweaked) position
875
         // Move back to the original (or tweaked) position
871
         do_blocking_move_to(destination);
876
         do_blocking_move_to(destination);
877
+
872
         #if ENABLED(DUAL_X_CARRIAGE)
878
         #if ENABLED(DUAL_X_CARRIAGE)
873
           active_extruder_parked = false;
879
           active_extruder_parked = false;
874
         #endif
880
         #endif

正在加载...
取消
保存