Browse Source

Fix probe with multi-endstops (#16793)

Robert Stein 4 years ago
parent
commit
3a3429b1ef
No account linked to committer's email address
1 changed files with 50 additions and 61 deletions
  1. 50
    61
      Marlin/src/module/endstops.cpp

+ 50
- 61
Marlin/src/module/endstops.cpp View File

529
   // With Dual X, endstops are only checked in the homing direction for the active extruder
529
   // With Dual X, endstops are only checked in the homing direction for the active extruder
530
   #if ENABLED(DUAL_X_CARRIAGE)
530
   #if ENABLED(DUAL_X_CARRIAGE)
531
     #define E0_ACTIVE stepper.movement_extruder() == 0
531
     #define E0_ACTIVE stepper.movement_extruder() == 0
532
-    #define X_MIN_TEST ((X_HOME_DIR < 0 && E0_ACTIVE) || (X2_HOME_DIR < 0 && !E0_ACTIVE))
533
-    #define X_MAX_TEST ((X_HOME_DIR > 0 && E0_ACTIVE) || (X2_HOME_DIR > 0 && !E0_ACTIVE))
532
+    #define X_MIN_TEST() ((X_HOME_DIR < 0 && E0_ACTIVE) || (X2_HOME_DIR < 0 && !E0_ACTIVE))
533
+    #define X_MAX_TEST() ((X_HOME_DIR > 0 && E0_ACTIVE) || (X2_HOME_DIR > 0 && !E0_ACTIVE))
534
   #else
534
   #else
535
-    #define X_MIN_TEST true
536
-    #define X_MAX_TEST true
535
+    #define X_MIN_TEST() true
536
+    #define X_MAX_TEST() true
537
   #endif
537
   #endif
538
 
538
 
539
   // Use HEAD for core axes, AXIS for others
539
   // Use HEAD for core axes, AXIS for others
690
   #define _ENDSTOP_HIT(AXIS, MINMAX) SBI(hit_state, _ENDSTOP(AXIS, MINMAX))
690
   #define _ENDSTOP_HIT(AXIS, MINMAX) SBI(hit_state, _ENDSTOP(AXIS, MINMAX))
691
 
691
 
692
   // Call the endstop triggered routine for single endstops
692
   // Call the endstop triggered routine for single endstops
693
-  #define PROCESS_ENDSTOP(AXIS,MINMAX) do { \
693
+  #define PROCESS_ENDSTOP(AXIS, MINMAX) do { \
694
     if (TEST_ENDSTOP(_ENDSTOP(AXIS, MINMAX))) { \
694
     if (TEST_ENDSTOP(_ENDSTOP(AXIS, MINMAX))) { \
695
       _ENDSTOP_HIT(AXIS, MINMAX); \
695
       _ENDSTOP_HIT(AXIS, MINMAX); \
696
       planner.endstop_triggered(_AXIS(AXIS)); \
696
       planner.endstop_triggered(_AXIS(AXIS)); \
698
   }while(0)
698
   }while(0)
699
 
699
 
700
   // Call the endstop triggered routine for dual endstops
700
   // Call the endstop triggered routine for dual endstops
701
-  #define PROCESS_DUAL_ENDSTOP(AXIS1, AXIS2, MINMAX) do { \
702
-    const byte dual_hit = TEST_ENDSTOP(_ENDSTOP(AXIS1, MINMAX)) | (TEST_ENDSTOP(_ENDSTOP(AXIS2, MINMAX)) << 1); \
701
+  #define PROCESS_DUAL_ENDSTOP(A, MINMAX) do { \
702
+    const byte dual_hit = TEST_ENDSTOP(_ENDSTOP(A, MINMAX)) | (TEST_ENDSTOP(_ENDSTOP(A##2, MINMAX)) << 1); \
703
     if (dual_hit) { \
703
     if (dual_hit) { \
704
-      _ENDSTOP_HIT(AXIS1, MINMAX); \
704
+      _ENDSTOP_HIT(A, MINMAX); \
705
       /* if not performing home or if both endstops were trigged during homing... */ \
705
       /* if not performing home or if both endstops were trigged during homing... */ \
706
       if (!stepper.separate_multi_axis || dual_hit == 0b11) \
706
       if (!stepper.separate_multi_axis || dual_hit == 0b11) \
707
-        planner.endstop_triggered(_AXIS(AXIS1)); \
707
+        planner.endstop_triggered(_AXIS(A)); \
708
     } \
708
     } \
709
   }while(0)
709
   }while(0)
710
 
710
 
711
-  #define PROCESS_TRIPLE_ENDSTOP(AXIS1, AXIS2, AXIS3, MINMAX) do { \
712
-    const byte triple_hit = TEST_ENDSTOP(_ENDSTOP(AXIS1, MINMAX)) | (TEST_ENDSTOP(_ENDSTOP(AXIS2, MINMAX)) << 1) | (TEST_ENDSTOP(_ENDSTOP(AXIS3, MINMAX)) << 2); \
711
+  #define PROCESS_TRIPLE_ENDSTOP(A, MINMAX) do { \
712
+    const byte triple_hit = TEST_ENDSTOP(_ENDSTOP(A, MINMAX)) | (TEST_ENDSTOP(_ENDSTOP(A##2, MINMAX)) << 1) | (TEST_ENDSTOP(_ENDSTOP(A##3, MINMAX)) << 2); \
713
     if (triple_hit) { \
713
     if (triple_hit) { \
714
-      _ENDSTOP_HIT(AXIS1, MINMAX); \
714
+      _ENDSTOP_HIT(A, MINMAX); \
715
       /* if not performing home or if both endstops were trigged during homing... */ \
715
       /* if not performing home or if both endstops were trigged during homing... */ \
716
       if (!stepper.separate_multi_axis || triple_hit == 0b111) \
716
       if (!stepper.separate_multi_axis || triple_hit == 0b111) \
717
-        planner.endstop_triggered(_AXIS(AXIS1)); \
717
+        planner.endstop_triggered(_AXIS(A)); \
718
     } \
718
     } \
719
   }while(0)
719
   }while(0)
720
 
720
 
721
-  #define PROCESS_QUAD_ENDSTOP(AXIS1, AXIS2, AXIS3, AXIS4, MINMAX) do { \
722
-    const byte quad_hit = TEST_ENDSTOP(_ENDSTOP(AXIS1, MINMAX)) | (TEST_ENDSTOP(_ENDSTOP(AXIS2, MINMAX)) << 1) | (TEST_ENDSTOP(_ENDSTOP(AXIS3, MINMAX)) << 2) | (TEST_ENDSTOP(_ENDSTOP(AXIS4, MINMAX)) << 3); \
721
+  #define PROCESS_QUAD_ENDSTOP(A, MINMAX) do { \
722
+    const byte quad_hit = TEST_ENDSTOP(_ENDSTOP(A, MINMAX)) | (TEST_ENDSTOP(_ENDSTOP(A##2, MINMAX)) << 1) | (TEST_ENDSTOP(_ENDSTOP(A##3, MINMAX)) << 2) | (TEST_ENDSTOP(_ENDSTOP(A##4, MINMAX)) << 3); \
723
     if (quad_hit) { \
723
     if (quad_hit) { \
724
-      _ENDSTOP_HIT(AXIS1, MINMAX); \
724
+      _ENDSTOP_HIT(A, MINMAX); \
725
       /* if not performing home or if both endstops were trigged during homing... */ \
725
       /* if not performing home or if both endstops were trigged during homing... */ \
726
       if (!stepper.separate_multi_axis || quad_hit == 0b1111) \
726
       if (!stepper.separate_multi_axis || quad_hit == 0b1111) \
727
-        planner.endstop_triggered(_AXIS(AXIS1)); \
727
+        planner.endstop_triggered(_AXIS(A)); \
728
     } \
728
     } \
729
   }while(0)
729
   }while(0)
730
 
730
 
731
+  #if ENABLED(X_DUAL_ENDSTOPS)
732
+    #define PROCESS_ENDSTOP_X(MINMAX) PROCESS_DUAL_ENDSTOP(X, MINMAX)
733
+  #else
734
+    #define PROCESS_ENDSTOP_X(MINMAX) if (X_##MINMAX##_TEST()) PROCESS_ENDSTOP(X, MINMAX)
735
+  #endif
736
+
737
+  #if ENABLED(Y_DUAL_ENDSTOPS)
738
+    #define PROCESS_ENDSTOP_Y(MINMAX) PROCESS_DUAL_ENDSTOP(Y, MINMAX)
739
+  #else
740
+    #define PROCESS_ENDSTOP_Y(MINMAX) PROCESS_ENDSTOP(Y, MINMAX)
741
+  #endif
742
+
743
+  #if DISABLED(Z_MULTI_ENDSTOPS)
744
+    #define PROCESS_ENDSTOP_Z(MINMAX) PROCESS_ENDSTOP(Z, MINMAX)
745
+  #elif NUM_Z_STEPPER_DRIVERS == 4
746
+    #define PROCESS_ENDSTOP_Z(MINMAX) PROCESS_QUAD_ENDSTOP(Z, MINMAX)
747
+  #elif NUM_Z_STEPPER_DRIVERS == 3
748
+    #define PROCESS_ENDSTOP_Z(MINMAX) PROCESS_TRIPLE_ENDSTOP(Z, MINMAX)
749
+  #else
750
+    #define PROCESS_ENDSTOP_Z(MINMAX) PROCESS_DUAL_ENDSTOP(Z, MINMAX)
751
+  #endif
752
+
731
   #if ENABLED(G38_PROBE_TARGET) && PIN_EXISTS(Z_MIN_PROBE) && !(CORE_IS_XY || CORE_IS_XZ)
753
   #if ENABLED(G38_PROBE_TARGET) && PIN_EXISTS(Z_MIN_PROBE) && !(CORE_IS_XY || CORE_IS_XZ)
732
     #if ENABLED(G38_PROBE_AWAY)
754
     #if ENABLED(G38_PROBE_AWAY)
733
       #define _G38_OPEN_STATE (G38_move >= 4)
755
       #define _G38_OPEN_STATE (G38_move >= 4)
747
   if (stepper.axis_is_moving(X_AXIS)) {
769
   if (stepper.axis_is_moving(X_AXIS)) {
748
     if (stepper.motor_direction(X_AXIS_HEAD)) { // -direction
770
     if (stepper.motor_direction(X_AXIS_HEAD)) { // -direction
749
       #if HAS_X_MIN || (X_SPI_SENSORLESS && X_HOME_DIR < 0)
771
       #if HAS_X_MIN || (X_SPI_SENSORLESS && X_HOME_DIR < 0)
750
-        #if ENABLED(X_DUAL_ENDSTOPS)
751
-          PROCESS_DUAL_ENDSTOP(X, X2, MIN);
752
-        #else
753
-          if (X_MIN_TEST) PROCESS_ENDSTOP(X, MIN);
754
-        #endif
772
+        PROCESS_ENDSTOP_X(MIN);
755
       #endif
773
       #endif
756
     }
774
     }
757
     else { // +direction
775
     else { // +direction
758
       #if HAS_X_MAX || (X_SPI_SENSORLESS && X_HOME_DIR > 0)
776
       #if HAS_X_MAX || (X_SPI_SENSORLESS && X_HOME_DIR > 0)
759
-        #if ENABLED(X_DUAL_ENDSTOPS)
760
-          PROCESS_DUAL_ENDSTOP(X, X2, MAX);
761
-        #else
762
-          if (X_MAX_TEST) PROCESS_ENDSTOP(X, MAX);
763
-        #endif
777
+        PROCESS_ENDSTOP_X(MAX);
764
       #endif
778
       #endif
765
     }
779
     }
766
   }
780
   }
768
   if (stepper.axis_is_moving(Y_AXIS)) {
782
   if (stepper.axis_is_moving(Y_AXIS)) {
769
     if (stepper.motor_direction(Y_AXIS_HEAD)) { // -direction
783
     if (stepper.motor_direction(Y_AXIS_HEAD)) { // -direction
770
       #if HAS_Y_MIN || (Y_SPI_SENSORLESS && Y_HOME_DIR < 0)
784
       #if HAS_Y_MIN || (Y_SPI_SENSORLESS && Y_HOME_DIR < 0)
771
-        #if ENABLED(Y_DUAL_ENDSTOPS)
772
-          PROCESS_DUAL_ENDSTOP(Y, Y2, MIN);
773
-        #else
774
-          PROCESS_ENDSTOP(Y, MIN);
775
-        #endif
785
+        PROCESS_ENDSTOP_Y(MIN);
776
       #endif
786
       #endif
777
     }
787
     }
778
     else { // +direction
788
     else { // +direction
779
       #if HAS_Y_MAX || (Y_SPI_SENSORLESS && Y_HOME_DIR > 0)
789
       #if HAS_Y_MAX || (Y_SPI_SENSORLESS && Y_HOME_DIR > 0)
780
-        #if ENABLED(Y_DUAL_ENDSTOPS)
781
-          PROCESS_DUAL_ENDSTOP(Y, Y2, MAX);
782
-        #else
783
-          PROCESS_ENDSTOP(Y, MAX);
784
-        #endif
790
+        PROCESS_ENDSTOP_Y(MAX);
785
       #endif
791
       #endif
786
     }
792
     }
787
   }
793
   }
788
 
794
 
789
   if (stepper.axis_is_moving(Z_AXIS)) {
795
   if (stepper.axis_is_moving(Z_AXIS)) {
790
     if (stepper.motor_direction(Z_AXIS_HEAD)) { // Z -direction. Gantry down, bed up.
796
     if (stepper.motor_direction(Z_AXIS_HEAD)) { // Z -direction. Gantry down, bed up.
797
+
791
       #if HAS_Z_MIN || (Z_SPI_SENSORLESS && Z_HOME_DIR < 0)
798
       #if HAS_Z_MIN || (Z_SPI_SENSORLESS && Z_HOME_DIR < 0)
792
-        #if ENABLED(Z_MULTI_ENDSTOPS)
793
-          #if NUM_Z_STEPPER_DRIVERS == 4
794
-            PROCESS_QUAD_ENDSTOP(Z, Z2, Z3, Z4, MIN);
795
-          #elif NUM_Z_STEPPER_DRIVERS == 3
796
-            PROCESS_TRIPLE_ENDSTOP(Z, Z2, Z3, MIN);
797
-          #else
798
-            PROCESS_DUAL_ENDSTOP(Z, Z2, MIN);
799
-          #endif
800
-        #else
799
+        if (true
801
           #if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
800
           #if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
802
-            if (z_probe_enabled) PROCESS_ENDSTOP(Z, MIN);
801
+            && z_probe_enabled
803
           #elif HAS_CUSTOM_PROBE_PIN
802
           #elif HAS_CUSTOM_PROBE_PIN
804
-            if (!z_probe_enabled) PROCESS_ENDSTOP(Z, MIN);
805
-          #else
806
-            PROCESS_ENDSTOP(Z, MIN);
803
+            && !z_probe_enabled
807
           #endif
804
           #endif
808
-        #endif
805
+        ) PROCESS_ENDSTOP_Z(MIN);
809
       #endif
806
       #endif
810
 
807
 
811
       // When closing the gap check the enabled probe
808
       // When closing the gap check the enabled probe
816
     else { // Z +direction. Gantry up, bed down.
813
     else { // Z +direction. Gantry up, bed down.
817
       #if HAS_Z_MAX || (Z_SPI_SENSORLESS && Z_HOME_DIR > 0)
814
       #if HAS_Z_MAX || (Z_SPI_SENSORLESS && Z_HOME_DIR > 0)
818
         #if ENABLED(Z_MULTI_ENDSTOPS)
815
         #if ENABLED(Z_MULTI_ENDSTOPS)
819
-          #if NUM_Z_STEPPER_DRIVERS == 4
820
-            PROCESS_QUAD_ENDSTOP(Z, Z2, Z3, Z4, MAX);
821
-          #elif NUM_Z_STEPPER_DRIVERS == 3
822
-            PROCESS_TRIPLE_ENDSTOP(Z, Z2, Z3, MAX);
823
-          #else
824
-            PROCESS_DUAL_ENDSTOP(Z, Z2, MAX);
825
-          #endif
826
-        #elif !HAS_CUSTOM_PROBE_PIN || Z_MAX_PIN != Z_MIN_PROBE_PIN
827
-          // If this pin is not hijacked for the bed probe
828
-          // then it belongs to the Z endstop
816
+          PROCESS_ENDSTOP_Z(MAX);
817
+        #elif !HAS_CUSTOM_PROBE_PIN || Z_MAX_PIN != Z_MIN_PROBE_PIN  // No probe or probe is Z_MIN || Probe is not Z_MAX
829
           PROCESS_ENDSTOP(Z, MAX);
818
           PROCESS_ENDSTOP(Z, MAX);
830
         #endif
819
         #endif
831
       #endif
820
       #endif

Loading…
Cancel
Save