Selaa lähdekoodia

Validate defined probe points (#20572)

Jason Smith 4 vuotta sitten
vanhempi
commit
81d7bd8f41
No account linked to committer's email address

+ 3
- 3
Marlin/Configuration_adv.h Näytä tiedosto

@@ -801,10 +801,10 @@
801 801
 //#define ASSISTED_TRAMMING
802 802
 #if ENABLED(ASSISTED_TRAMMING)
803 803
 
804
-  // Define positions for probing points, use the hotend as reference not the sensor.
805
-  #define TRAMMING_POINT_XY { {  20, 20 }, { 200,  20 }, { 200, 200 }, { 20, 200 } }
804
+  // Define positions for probe points.
805
+  #define TRAMMING_POINT_XY { {  20, 20 }, { 180,  20 }, { 180, 180 }, { 20, 180 } }
806 806
 
807
-  // Define positions names for probing points.
807
+  // Define position names for probe points.
808 808
   #define TRAMMING_POINT_NAME_1 "Front-Left"
809 809
   #define TRAMMING_POINT_NAME_2 "Front-Right"
810 810
   #define TRAMMING_POINT_NAME_3 "Back-Right"

+ 5
- 0
Marlin/src/feature/tramming.h Näytä tiedosto

@@ -21,6 +21,7 @@
21 21
  */
22 22
 
23 23
 #include "../inc/MarlinConfigPre.h"
24
+#include "../module/probe.h"
24 25
 
25 26
 #if !WITHIN(TRAMMING_SCREW_THREAD, 30, 51) || TRAMMING_SCREW_THREAD % 10 > 1
26 27
   #error "TRAMMING_SCREW_THREAD must be equal to 30, 31, 40, 41, 50, or 51."
@@ -31,6 +32,10 @@ constexpr xy_pos_t screws_tilt_adjust_pos[] = TRAMMING_POINT_XY;
31 32
 #define G35_PROBE_COUNT COUNT(screws_tilt_adjust_pos)
32 33
 static_assert(G35_PROBE_COUNT >= 3, "TRAMMING_POINT_XY requires at least 3 XY positions.");
33 34
 
35
+#define VALIDATE_TRAMMING_POINT(N) static_assert(N >= G35_PROBE_COUNT || Probe::build_time::can_reach(screws_tilt_adjust_pos[N]), \
36
+  "TRAMMING_POINT_XY point " STRINGIFY(N) " is not reachable with the default NOZZLE_TO_PROBE offset and PROBING_MARGIN.")
37
+VALIDATE_TRAMMING_POINT(0); VALIDATE_TRAMMING_POINT(1); VALIDATE_TRAMMING_POINT(2); VALIDATE_TRAMMING_POINT(3); VALIDATE_TRAMMING_POINT(4);
38
+
34 39
 extern const char point_name_1[], point_name_2[], point_name_3[]
35 40
   #ifdef TRAMMING_POINT_NAME_4
36 41
     , point_name_4[]

+ 3
- 19
Marlin/src/feature/z_stepper_align.cpp Näytä tiedosto

@@ -54,25 +54,9 @@ void ZStepperAlign::reset_to_default() {
54 54
       #endif
55 55
     );
56 56
 
57
-    constexpr xyz_pos_t dpo = NOZZLE_TO_PROBE_OFFSET;
58
-
59
-    #define LTEST(N) (xy_init[N].x >= _MAX(X_MIN_BED + PROBING_MARGIN_LEFT,  X_MIN_POS + dpo.x) - 0.00001f)
60
-    #define RTEST(N) (xy_init[N].x <= _MIN(X_MAX_BED - PROBING_MARGIN_RIGHT, X_MAX_POS + dpo.x) + 0.00001f)
61
-    #define FTEST(N) (xy_init[N].y >= _MAX(Y_MIN_BED + PROBING_MARGIN_FRONT, Y_MIN_POS + dpo.y) - 0.00001f)
62
-    #define BTEST(N) (xy_init[N].y <= _MIN(Y_MAX_BED - PROBING_MARGIN_BACK,  Y_MAX_POS + dpo.y) + 0.00001f)
63
-
64
-    static_assert(LTEST(0) && RTEST(0), "The 1st Z_STEPPER_ALIGN_XY X is unreachable with the default probe X offset.");
65
-    static_assert(FTEST(0) && BTEST(0), "The 1st Z_STEPPER_ALIGN_XY Y is unreachable with the default probe Y offset.");
66
-    static_assert(LTEST(1) && RTEST(1), "The 2nd Z_STEPPER_ALIGN_XY X is unreachable with the default probe X offset.");
67
-    static_assert(FTEST(1) && BTEST(1), "The 2nd Z_STEPPER_ALIGN_XY Y is unreachable with the default probe Y offset.");
68
-    #if NUM_Z_STEPPER_DRIVERS >= 3
69
-      static_assert(LTEST(2) && RTEST(2), "The 3rd Z_STEPPER_ALIGN_XY X is unreachable with the default probe X offset.");
70
-      static_assert(FTEST(2) && BTEST(2), "The 3rd Z_STEPPER_ALIGN_XY Y is unreachable with the default probe Y offset.");
71
-      #if NUM_Z_STEPPER_DRIVERS >= 4
72
-        static_assert(LTEST(3) && RTEST(3), "The 4th Z_STEPPER_ALIGN_XY X is unreachable with the default probe X offset.");
73
-        static_assert(FTEST(3) && BTEST(3), "The 4th Z_STEPPER_ALIGN_XY Y is unreachable with the default probe Y offset.");
74
-      #endif
75
-    #endif
57
+    #define VALIDATE_ALIGN_POINT(N) static_assert(N >= NUM_Z_STEPPER_DRIVERS || Probe::build_time::can_reach(xy_init[N]), \
58
+      "Z_STEPPER_ALIGN_XY point " STRINGIFY(N) " is not reachable with the default NOZZLE_TO_PROBE offset and PROBING_MARGIN.")
59
+    VALIDATE_ALIGN_POINT(0); VALIDATE_ALIGN_POINT(1); VALIDATE_ALIGN_POINT(2); VALIDATE_ALIGN_POINT(3);
76 60
 
77 61
   #else // !defined(Z_STEPPER_ALIGN_XY)
78 62
 

+ 5
- 0
Marlin/src/lcd/menu/menu_bed_corners.cpp Näytä tiedosto

@@ -77,6 +77,11 @@ constexpr xy_pos_t lf { (X_MIN_BED) + inset_lfrb[0], (Y_MIN_BED) + inset_lfrb[1]
77 77
  */
78 78
 #if ENABLED(LEVEL_CORNERS_USE_PROBE)
79 79
 
80
+  #define VALIDATE_POINT(X, Y, STR) static_assert(Probe::build_time::can_reach((X), (Y)), \
81
+    "LEVEL_CORNERS_INSET_LFRB " STR " inset is not reachable with the default NOZZLE_TO_PROBE offset and PROBING_MARGIN.")
82
+  VALIDATE_POINT(lf.x, Y_CENTER, "left"); VALIDATE_POINT(X_CENTER, lf.y, "front");
83
+  VALIDATE_POINT(rb.x, Y_CENTER, "right"); VALIDATE_POINT(X_CENTER, rb.y, "back");
84
+
80 85
   void _lcd_draw_probing() {
81 86
     if (ui.should_draw()) MenuItem_static::draw((LCD_HEIGHT - 1) / 2, GET_TEXT(MSG_PROBING_MESH));
82 87
   }

+ 63
- 31
Marlin/src/module/probe.h Näytä tiedosto

@@ -62,12 +62,12 @@ public:
62 62
       #if HAS_PROBE_XY_OFFSET
63 63
         // Return true if the both nozzle and the probe can reach the given point.
64 64
         // Note: This won't work on SCARA since the probe offset rotates with the arm.
65
-        static inline bool can_reach(const float &rx, const float &ry) {
65
+        static bool can_reach(const float &rx, const float &ry) {
66 66
           return position_is_reachable(rx - offset_xy.x, ry - offset_xy.y) // The nozzle can go where it needs to go?
67 67
               && position_is_reachable(rx, ry, ABS(PROBING_MARGIN));       // Can the nozzle also go near there?
68 68
         }
69 69
       #else
70
-        FORCE_INLINE static bool can_reach(const float &rx, const float &ry) {
70
+        static bool can_reach(const float &rx, const float &ry) {
71 71
           return position_is_reachable(rx, ry, PROBING_MARGIN);
72 72
         }
73 73
       #endif
@@ -81,7 +81,7 @@ public:
81 81
        * Example: For a probe offset of -10,+10, then for the probe to reach 0,0 the
82 82
        *          nozzle must be be able to reach +10,-10.
83 83
        */
84
-      static inline bool can_reach(const float &rx, const float &ry) {
84
+      static bool can_reach(const float &rx, const float &ry) {
85 85
         return position_is_reachable(rx - offset_xy.x, ry - offset_xy.y)
86 86
             && WITHIN(rx, min_x() - fslop, max_x() + fslop)
87 87
             && WITHIN(ry, min_y() - fslop, max_y() + fslop);
@@ -89,13 +89,13 @@ public:
89 89
 
90 90
     #endif
91 91
 
92
-    static inline void move_z_after_probing() {
92
+    static void move_z_after_probing() {
93 93
       #ifdef Z_AFTER_PROBING
94 94
         do_z_clearance(Z_AFTER_PROBING, true, true, true); // Move down still permitted
95 95
       #endif
96 96
     }
97 97
     static float probe_at_point(const float &rx, const float &ry, const ProbePtRaise raise_after=PROBE_PT_NONE, const uint8_t verbose_level=0, const bool probe_relative=true, const bool sanity_check=true);
98
-    static inline float probe_at_point(const xy_pos_t &pos, const ProbePtRaise raise_after=PROBE_PT_NONE, const uint8_t verbose_level=0, const bool probe_relative=true, const bool sanity_check=true) {
98
+    static float probe_at_point(const xy_pos_t &pos, const ProbePtRaise raise_after=PROBE_PT_NONE, const uint8_t verbose_level=0, const bool probe_relative=true, const bool sanity_check=true) {
99 99
       return probe_at_point(pos.x, pos.y, raise_after, verbose_level, probe_relative, sanity_check);
100 100
     }
101 101
 
@@ -105,21 +105,21 @@ public:
105 105
 
106 106
     static bool set_deployed(const bool) { return false; }
107 107
 
108
-    FORCE_INLINE static bool can_reach(const float &rx, const float &ry) { return position_is_reachable(rx, ry); }
108
+    static bool can_reach(const float &rx, const float &ry) { return position_is_reachable(rx, ry); }
109 109
 
110 110
   #endif
111 111
 
112
-  static inline void move_z_after_homing() {
112
+  static void move_z_after_homing() {
113 113
     #ifdef Z_AFTER_HOMING
114 114
       do_z_clearance(Z_AFTER_HOMING, true, true, true);
115
-    #elif BOTH(Z_AFTER_PROBING,HAS_BED_PROBE)
115
+    #elif BOTH(Z_AFTER_PROBING, HAS_BED_PROBE)
116 116
       move_z_after_probing();
117 117
     #endif
118 118
   }
119 119
 
120
-  FORCE_INLINE static bool can_reach(const xy_pos_t &pos) { return can_reach(pos.x, pos.y); }
120
+  static bool can_reach(const xy_pos_t &pos) { return can_reach(pos.x, pos.y); }
121 121
 
122
-  FORCE_INLINE static bool good_bounds(const xy_pos_t &lf, const xy_pos_t &rb) {
122
+  static bool good_bounds(const xy_pos_t &lf, const xy_pos_t &rb) {
123 123
     return (
124 124
       #if IS_KINEMATIC
125 125
         can_reach(lf.x, 0) && can_reach(rb.x, 0) && can_reach(0, lf.y) && can_reach(0, rb.y)
@@ -137,8 +137,8 @@ public:
137 137
     static constexpr xy_pos_t offset_xy = xy_pos_t({ 0, 0 });   // See #16767
138 138
   #endif
139 139
 
140
-  static inline bool deploy() { return set_deployed(true); }
141
-  static inline bool stow() { return set_deployed(false); }
140
+  static bool deploy() { return set_deployed(true); }
141
+  static bool stow()   { return set_deployed(false); }
142 142
 
143 143
   #if HAS_BED_PROBE || HAS_LEVELING
144 144
     #if IS_KINEMATIC
@@ -146,41 +146,73 @@ public:
146 146
         TERN_(DELTA, DELTA_PRINTABLE_RADIUS)
147 147
         TERN_(IS_SCARA, SCARA_PRINTABLE_RADIUS)
148 148
       );
149
-      static inline float probe_radius() {
150
-        return printable_radius - _MAX(PROBING_MARGIN, HYPOT(offset_xy.x, offset_xy.y));
149
+      static constexpr float probe_radius(const xy_pos_t &probe_offset_xy = offset_xy) {
150
+        return printable_radius - _MAX(PROBING_MARGIN, HYPOT(probe_offset_xy.x, probe_offset_xy.y));
151 151
       }
152 152
     #endif
153 153
 
154
-    static inline float min_x() {
154
+    static constexpr float _min_x(const xy_pos_t &probe_offset_xy = offset_xy) {
155 155
       return TERN(IS_KINEMATIC,
156
-        (X_CENTER) - probe_radius(),
157
-        _MAX((X_MIN_BED) + (PROBING_MARGIN_LEFT), (X_MIN_POS) + offset_xy.x)
158
-      ) - TERN0(NOZZLE_AS_PROBE, TERN0(HAS_HOME_OFFSET, home_offset.x));
156
+        (X_CENTER) - probe_radius(probe_offset_xy),
157
+        _MAX((X_MIN_BED) + (PROBING_MARGIN_LEFT), (X_MIN_POS) + probe_offset_xy.x)
158
+      );
159 159
     }
160
-    static inline float max_x() {
160
+    static constexpr float _max_x(const xy_pos_t &probe_offset_xy = offset_xy) {
161 161
       return TERN(IS_KINEMATIC,
162
-        (X_CENTER) + probe_radius(),
163
-        _MIN((X_MAX_BED) - (PROBING_MARGIN_RIGHT), (X_MAX_POS) + offset_xy.x)
164
-      ) - TERN0(NOZZLE_AS_PROBE, TERN0(HAS_HOME_OFFSET, home_offset.x));
162
+        (X_CENTER) + probe_radius(probe_offset_xy),
163
+        _MIN((X_MAX_BED) - (PROBING_MARGIN_RIGHT), (X_MAX_POS) + probe_offset_xy.x)
164
+      );
165 165
     }
166
-    static inline float min_y() {
166
+    static constexpr float _min_y(const xy_pos_t &probe_offset_xy = offset_xy) {
167 167
       return TERN(IS_KINEMATIC,
168
-        (Y_CENTER) - probe_radius(),
169
-        _MAX((Y_MIN_BED) + (PROBING_MARGIN_FRONT), (Y_MIN_POS) + offset_xy.y)
170
-      ) - TERN0(NOZZLE_AS_PROBE, TERN0(HAS_HOME_OFFSET, home_offset.y));
168
+        (Y_CENTER) - probe_radius(probe_offset_xy),
169
+        _MAX((Y_MIN_BED) + (PROBING_MARGIN_FRONT), (Y_MIN_POS) + probe_offset_xy.y)
170
+      );
171 171
     }
172
-    static inline float max_y() {
172
+    static constexpr float _max_y(const xy_pos_t &probe_offset_xy = offset_xy) {
173 173
       return TERN(IS_KINEMATIC,
174
-        (Y_CENTER) + probe_radius(),
175
-        _MIN((Y_MAX_BED) - (PROBING_MARGIN_BACK), (Y_MAX_POS) + offset_xy.y)
176
-      ) - TERN0(NOZZLE_AS_PROBE, TERN0(HAS_HOME_OFFSET, home_offset.y));
174
+        (Y_CENTER) + probe_radius(probe_offset_xy),
175
+        _MIN((Y_MAX_BED) - (PROBING_MARGIN_BACK), (Y_MAX_POS) + probe_offset_xy.y)
176
+      );
177 177
     }
178 178
 
179
+    static float min_x() { return _min_x() - TERN0(NOZZLE_AS_PROBE, TERN0(HAS_HOME_OFFSET, home_offset.x)); }
180
+    static float max_x() { return _max_x() - TERN0(NOZZLE_AS_PROBE, TERN0(HAS_HOME_OFFSET, home_offset.x)); }
181
+    static float min_y() { return _min_y() - TERN0(NOZZLE_AS_PROBE, TERN0(HAS_HOME_OFFSET, home_offset.y)); }
182
+    static float max_y() { return _max_y() - TERN0(NOZZLE_AS_PROBE, TERN0(HAS_HOME_OFFSET, home_offset.y)); }
183
+
184
+    // constexpr helpers used in build-time static_asserts, relying on default probe offsets.
185
+    class build_time {
186
+      static constexpr xyz_pos_t default_probe_xyz_offset =
187
+        #if HAS_BED_PROBE
188
+          NOZZLE_TO_PROBE_OFFSET
189
+        #else
190
+          { 0 }
191
+        #endif
192
+      ;
193
+      static constexpr xy_pos_t default_probe_xy_offset = { default_probe_xyz_offset.x,  default_probe_xyz_offset.y };
194
+
195
+    public:
196
+      static constexpr bool can_reach(float x, float y) {
197
+        #if IS_KINEMATIC
198
+          return HYPOT2(x, y) <= sq(probe_radius(default_probe_xy_offset));
199
+        #else
200
+          return WITHIN(x, _min_x(default_probe_xy_offset) - fslop, _max_x(default_probe_xy_offset) + fslop)
201
+              && WITHIN(y, _min_y(default_probe_xy_offset) - fslop, _max_y(default_probe_xy_offset) + fslop);
202
+        #endif
203
+      }
204
+
205
+      static constexpr bool can_reach(const xy_pos_t &point) { return can_reach(point.x, point.y); }
206
+    };
207
+
179 208
     #if NEEDS_THREE_PROBE_POINTS
180 209
       // Retrieve three points to probe the bed. Any type exposing set(X,Y) may be used.
181 210
       template <typename T>
182
-      static inline void get_three_points(T points[3]) {
211
+      static void get_three_points(T points[3]) {
183 212
         #if HAS_FIXED_3POINT
213
+          #define VALIDATE_PROBE_PT(N) static_assert(Probe::build_time::can_reach(xy_pos_t{PROBE_PT_##N##_X, PROBE_PT_##N##_Y}), \
214
+            "PROBE_PT_" STRINGIFY(N) "_(X|Y) is unreachable using default NOZZLE_TO_PROBE_OFFSET and PROBING_MARGIN");
215
+          VALIDATE_PROBE_PT(1); VALIDATE_PROBE_PT(2); VALIDATE_PROBE_PT(3);
184 216
           points[0].set(PROBE_PT_1_X, PROBE_PT_1_Y);
185 217
           points[1].set(PROBE_PT_2_X, PROBE_PT_2_Y);
186 218
           points[2].set(PROBE_PT_3_X, PROBE_PT_3_Y);

Loading…
Peruuta
Tallenna