Parcourir la source

Add position_is_reachable, use in home_z_safely

Scott Lahteine il y a 8 ans
Parent
révision
786d1afb72
1 fichiers modifiés avec 23 ajouts et 9 suppressions
  1. 23
    9
      Marlin/Marlin_main.cpp

+ 23
- 9
Marlin/Marlin_main.cpp Voir le fichier

@@ -2451,6 +2451,20 @@ void unknown_command_error() {
2451 2451
 
2452 2452
 #endif //HOST_KEEPALIVE_FEATURE
2453 2453
 
2454
+bool position_is_reachable(float target[XYZ]) {
2455
+  float dx = RAW_X_POSITION(target[X_AXIS]),
2456
+        dy = RAW_Y_POSITION(target[Y_AXIS]);
2457
+
2458
+  #if ENABLED(DELTA)
2459
+    return HYPOT2(dx, dy) <= sq(DELTA_PRINTABLE_RADIUS);
2460
+  #else
2461
+    float dz = RAW_Z_POSITION(target[Z_AXIS]);
2462
+    return  dx >= X_MIN_POS - 0.0001 && dx <= X_MAX_POS + 0.0001
2463
+         && dy >= Y_MIN_POS - 0.0001 && dy <= Y_MAX_POS + 0.0001
2464
+         && dz >= Z_MIN_POS - 0.0001 && dz <= Z_MAX_POS + 0.0001;
2465
+  #endif
2466
+}
2467
+
2454 2468
 /**
2455 2469
  * G0, G1: Coordinated movement of X Y Z E axes
2456 2470
  */
@@ -2770,21 +2784,21 @@ inline void gcode_G4() {
2770 2784
     /**
2771 2785
      * Move the Z probe (or just the nozzle) to the safe homing point
2772 2786
      */
2773
-    float cpx = Z_SAFE_HOMING_X_POINT, cpy = Z_SAFE_HOMING_Y_POINT;
2787
+    destination[X_AXIS] = LOGICAL_X_POSITION(Z_SAFE_HOMING_X_POINT);
2788
+    destination[Y_AXIS] = LOGICAL_Y_POSITION(Z_SAFE_HOMING_Y_POINT);
2789
+    destination[Z_AXIS] = current_position[Z_AXIS]; // Z is already at the right height
2790
+
2774 2791
     #if HAS_BED_PROBE
2775
-      cpx -= X_PROBE_OFFSET_FROM_EXTRUDER;
2776
-      cpy -= Y_PROBE_OFFSET_FROM_EXTRUDER;
2792
+      destination[X_AXIS] -= X_PROBE_OFFSET_FROM_EXTRUDER;
2793
+      destination[Y_AXIS] -= Y_PROBE_OFFSET_FROM_EXTRUDER;
2777 2794
     #endif
2778 2795
 
2779 2796
     #if ENABLED(DEBUG_LEVELING_FEATURE)
2780
-      if (DEBUGGING(LEVELING)) {
2781
-        SERIAL_ECHOPAIR("Z_SAFE_HOMING X:", cpx);
2782
-        SERIAL_ECHOLNPAIR(" Y:", cpy);
2783
-      }
2797
+      if (DEBUGGING(LEVELING)) DEBUG_POS("Z_SAFE_HOMING", destination);
2784 2798
     #endif
2785 2799
 
2786
-    if (cpx >= X_MIN_POS && cpx <= X_MAX_POS && cpy >= Y_MIN_POS && cpy <= Y_MAX_POS) {
2787
-      do_blocking_move_to_xy(LOGICAL_X_POSITION(destination[X_AXIS]), LOGICAL_Y_POSITION(destination[Y_AXIS]));
2800
+    if (position_is_reachable(destination)) {
2801
+      do_blocking_move_to_xy(destination[X_AXIS], destination[Y_AXIS]);
2788 2802
       HOMEAXIS(Z);
2789 2803
     }
2790 2804
     else {

Chargement…
Annuler
Enregistrer