My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

probe.h 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. /**
  24. * module/probe.h - Move, deploy, enable, etc.
  25. */
  26. #include "../inc/MarlinConfig.h"
  27. #include "motion.h"
  28. #if HAS_BED_PROBE
  29. enum ProbePtRaise : uint8_t {
  30. PROBE_PT_NONE, // No raise or stow after run_z_probe
  31. PROBE_PT_STOW, // Do a complete stow after run_z_probe
  32. PROBE_PT_RAISE, // Raise to "between" clearance after run_z_probe
  33. PROBE_PT_BIG_RAISE // Raise to big clearance after run_z_probe
  34. };
  35. #endif
  36. class Probe {
  37. public:
  38. #if HAS_BED_PROBE
  39. static xyz_pos_t offset;
  40. static bool set_deployed(const bool deploy);
  41. #if IS_KINEMATIC
  42. #if HAS_PROBE_XY_OFFSET
  43. // Return true if the both nozzle and the probe can reach the given point.
  44. // Note: This won't work on SCARA since the probe offset rotates with the arm.
  45. static inline bool can_reach(const float &rx, const float &ry) {
  46. return position_is_reachable(rx - offset_xy.x, ry - offset_xy.y) // The nozzle can go where it needs to go?
  47. && position_is_reachable(rx, ry, ABS(PROBING_MARGIN)); // Can the nozzle also go near there?
  48. }
  49. #else
  50. FORCE_INLINE static bool can_reach(const float &rx, const float &ry) {
  51. return position_is_reachable(rx, ry, PROBING_MARGIN);
  52. }
  53. #endif
  54. #else
  55. /**
  56. * Return whether the given position is within the bed, and whether the nozzle
  57. * can reach the position required to put the probe at the given position.
  58. *
  59. * Example: For a probe offset of -10,+10, then for the probe to reach 0,0 the
  60. * nozzle must be be able to reach +10,-10.
  61. */
  62. static inline bool can_reach(const float &rx, const float &ry) {
  63. return position_is_reachable(rx - offset_xy.x, ry - offset_xy.y)
  64. && WITHIN(rx, min_x() - fslop, max_x() + fslop)
  65. && WITHIN(ry, min_y() - fslop, max_y() + fslop);
  66. }
  67. #endif
  68. static inline void move_z_after_probing() {
  69. #ifdef Z_AFTER_PROBING
  70. do_z_clearance(Z_AFTER_PROBING, true, true, true); // Move down still permitted
  71. #endif
  72. }
  73. 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);
  74. 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) {
  75. return probe_at_point(pos.x, pos.y, raise_after, verbose_level, probe_relative, sanity_check);
  76. }
  77. #else
  78. static constexpr xyz_pos_t offset = xyz_pos_t({ 0, 0, 0 }); // See #16767
  79. static bool set_deployed(const bool) { return false; }
  80. FORCE_INLINE static bool can_reach(const float &rx, const float &ry) { return position_is_reachable(rx, ry); }
  81. #endif
  82. static inline void move_z_after_homing() {
  83. #ifdef Z_AFTER_HOMING
  84. do_z_clearance(Z_AFTER_HOMING, true, true, true);
  85. #elif BOTH(Z_AFTER_PROBING,HAS_BED_PROBE)
  86. move_z_after_probing();
  87. #endif
  88. }
  89. FORCE_INLINE static bool can_reach(const xy_pos_t &pos) { return can_reach(pos.x, pos.y); }
  90. FORCE_INLINE static bool good_bounds(const xy_pos_t &lf, const xy_pos_t &rb) {
  91. return (
  92. #if IS_KINEMATIC
  93. can_reach(lf.x, 0) && can_reach(rb.x, 0) && can_reach(0, lf.y) && can_reach(0, rb.y)
  94. #else
  95. can_reach(lf) && can_reach(rb)
  96. #endif
  97. );
  98. }
  99. // Use offset_xy for read only access
  100. // More optimal the XY offset is known to always be zero.
  101. #if HAS_PROBE_XY_OFFSET
  102. static const xyz_pos_t &offset_xy;
  103. #else
  104. static constexpr xy_pos_t offset_xy = xy_pos_t({ 0, 0 }); // See #16767
  105. #endif
  106. static inline bool deploy() { return set_deployed(true); }
  107. static inline bool stow() { return set_deployed(false); }
  108. #if HAS_BED_PROBE || HAS_LEVELING
  109. #if IS_KINEMATIC
  110. static constexpr float printable_radius = (
  111. #if ENABLED(DELTA)
  112. DELTA_PRINTABLE_RADIUS
  113. #elif IS_SCARA
  114. SCARA_PRINTABLE_RADIUS
  115. #endif
  116. );
  117. static inline float probe_radius() {
  118. return printable_radius - _MAX(PROBING_MARGIN, HYPOT(offset_xy.x, offset_xy.y));
  119. }
  120. #endif
  121. static inline float min_x() {
  122. return (
  123. #if IS_KINEMATIC
  124. (X_CENTER) - probe_radius()
  125. #else
  126. _MAX((X_MIN_BED) + (PROBING_MARGIN_LEFT), (X_MIN_POS) + offset_xy.x)
  127. #endif
  128. );
  129. }
  130. static inline float max_x() {
  131. return (
  132. #if IS_KINEMATIC
  133. (X_CENTER) + probe_radius()
  134. #else
  135. _MIN((X_MAX_BED) - (PROBING_MARGIN_RIGHT), (X_MAX_POS) + offset_xy.x)
  136. #endif
  137. );
  138. }
  139. static inline float min_y() {
  140. return (
  141. #if IS_KINEMATIC
  142. (Y_CENTER) - probe_radius()
  143. #else
  144. _MAX((Y_MIN_BED) + (PROBING_MARGIN_FRONT), (Y_MIN_POS) + offset_xy.y)
  145. #endif
  146. );
  147. }
  148. static inline float max_y() {
  149. return (
  150. #if IS_KINEMATIC
  151. (Y_CENTER) + probe_radius()
  152. #else
  153. _MIN((Y_MAX_BED) - (PROBING_MARGIN_BACK), (Y_MAX_POS) + offset_xy.y)
  154. #endif
  155. );
  156. }
  157. #if NEEDS_THREE_PROBE_POINTS
  158. // Retrieve three points to probe the bed. Any type exposing set(X,Y) may be used.
  159. template <typename T>
  160. static inline void get_three_points(T points[3]) {
  161. #if HAS_FIXED_3POINT
  162. points[0].set(PROBE_PT_1_X, PROBE_PT_1_Y);
  163. points[1].set(PROBE_PT_2_X, PROBE_PT_2_Y);
  164. points[2].set(PROBE_PT_3_X, PROBE_PT_3_Y);
  165. #else
  166. #if IS_KINEMATIC
  167. constexpr float SIN0 = 0.0, SIN120 = 0.866025, SIN240 = -0.866025,
  168. COS0 = 1.0, COS120 = -0.5 , COS240 = -0.5;
  169. points[0].set((X_CENTER) + probe_radius() * COS0, (Y_CENTER) + probe_radius() * SIN0);
  170. points[1].set((X_CENTER) + probe_radius() * COS120, (Y_CENTER) + probe_radius() * SIN120);
  171. points[2].set((X_CENTER) + probe_radius() * COS240, (Y_CENTER) + probe_radius() * SIN240);
  172. #else
  173. points[0].set(min_x(), min_y());
  174. points[1].set(max_x(), min_y());
  175. points[2].set((min_x() + max_x()) / 2, max_y());
  176. #endif
  177. #endif
  178. }
  179. #endif
  180. #endif // HAS_BED_PROBE
  181. #if HAS_Z_SERVO_PROBE
  182. static void servo_probe_init();
  183. #endif
  184. #if QUIET_PROBING
  185. static void set_probing_paused(const bool p);
  186. #endif
  187. private:
  188. static bool probe_down_to_z(const float z, const feedRate_t fr_mm_s);
  189. static void do_z_raise(const float z_raise);
  190. static float run_z_probe(const bool sanity_check=true);
  191. };
  192. extern Probe probe;