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.

menu_probe_offset.cpp 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. //
  23. // Calibrate Probe offset menu.
  24. //
  25. #include "../../inc/MarlinConfigPre.h"
  26. #if ENABLED(PROBE_OFFSET_WIZARD)
  27. #include "menu_item.h"
  28. #include "menu_addon.h"
  29. #include "../../gcode/queue.h"
  30. #include "../../module/motion.h"
  31. #include "../../module/planner.h"
  32. #include "../../module/probe.h"
  33. #if HAS_LEVELING
  34. #include "../../feature/bedlevel/bedlevel.h"
  35. #endif
  36. // Global storage
  37. float z_offset_backup, calculated_z_offset, z_offset_ref;
  38. TERN_(HAS_LEVELING, bool leveling_was_active);
  39. inline void z_clearance_move() {
  40. do_z_clearance(
  41. #ifdef Z_AFTER_HOMING
  42. Z_AFTER_HOMING
  43. #elif defined(Z_HOMING_HEIGHT)
  44. Z_HOMING_HEIGHT
  45. #else
  46. 10
  47. #endif
  48. );
  49. }
  50. void set_offset_and_go_back(const float &z) {
  51. probe.offset.z = z;
  52. SET_SOFT_ENDSTOP_LOOSE(false);
  53. TERN_(HAS_LEVELING, set_bed_leveling_enabled(leveling_was_active));
  54. ui.goto_previous_screen_no_defer();
  55. }
  56. void _goto_manual_move_z(const float scale) {
  57. ui.manual_move.menu_scale = scale;
  58. ui.goto_screen(lcd_move_z);
  59. }
  60. void probe_offset_wizard_menu() {
  61. START_MENU();
  62. calculated_z_offset = probe.offset.z + current_position.z - z_offset_ref;
  63. if (LCD_HEIGHT >= 4)
  64. STATIC_ITEM(MSG_MOVE_NOZZLE_TO_BED, SS_CENTER|SS_INVERT);
  65. STATIC_ITEM_P(PSTR("Z="), SS_CENTER, ftostr42_52(current_position.z));
  66. STATIC_ITEM(MSG_ZPROBE_ZOFFSET, SS_LEFT, ftostr42_52(calculated_z_offset));
  67. SUBMENU(MSG_MOVE_1MM, []{ _goto_manual_move_z( 1); });
  68. SUBMENU(MSG_MOVE_01MM, []{ _goto_manual_move_z( 0.1f); });
  69. if ((SHORT_MANUAL_Z_MOVE) > 0.0f && (SHORT_MANUAL_Z_MOVE) < 0.1f) {
  70. char tmp[20], numstr[10];
  71. // Determine digits needed right of decimal
  72. const uint8_t digs = !UNEAR_ZERO((SHORT_MANUAL_Z_MOVE) * 1000 - int((SHORT_MANUAL_Z_MOVE) * 1000)) ? 4 :
  73. !UNEAR_ZERO((SHORT_MANUAL_Z_MOVE) * 100 - int((SHORT_MANUAL_Z_MOVE) * 100)) ? 3 : 2;
  74. sprintf_P(tmp, GET_TEXT(MSG_MOVE_Z_DIST), dtostrf(SHORT_MANUAL_Z_MOVE, 1, digs, numstr));
  75. #if DISABLED(HAS_GRAPHICAL_TFT)
  76. extern const char NUL_STR[];
  77. SUBMENU_P(NUL_STR, []{ _goto_manual_move_z(float(SHORT_MANUAL_Z_MOVE)); });
  78. MENU_ITEM_ADDON_START(0 + ENABLED(HAS_MARLINUI_HD44780));
  79. lcd_put_u8str(tmp);
  80. MENU_ITEM_ADDON_END();
  81. #else
  82. SUBMENU_P(tmp, []{ _goto_manual_move_z(float(SHORT_MANUAL_Z_MOVE)); });
  83. #endif
  84. }
  85. ACTION_ITEM(MSG_BUTTON_DONE, []{
  86. set_offset_and_go_back(calculated_z_offset);
  87. current_position.z = z_offset_ref; // Set Z to z_offset_ref, as we can expect it is at probe height
  88. sync_plan_position();
  89. z_clearance_move(); // Raise Z as if it was homed
  90. });
  91. ACTION_ITEM(MSG_BUTTON_CANCEL, []{
  92. set_offset_and_go_back(z_offset_backup);
  93. // If wizard-homing was done by probe with PROBE_OFFSET_WIZARD_START_Z
  94. #if HOMING_Z_WITH_PROBE && defined(PROBE_OFFSET_WIZARD_START_Z)
  95. set_axis_never_homed(Z_AXIS); // On cancel the Z position needs correction
  96. queue.inject_P(PSTR("G28Z"));
  97. #else // Otherwise do a Z clearance move like after Homing
  98. z_clearance_move();
  99. #endif
  100. });
  101. END_MENU();
  102. }
  103. void prepare_for_probe_offset_wizard() {
  104. if (ui.wait_for_move) return;
  105. #if defined(PROBE_OFFSET_WIZARD_XY_POS) || !HOMING_Z_WITH_PROBE
  106. if (ui.should_draw()) MenuItem_static::draw(1, GET_TEXT(MSG_PROBE_WIZARD_PROBING));
  107. #ifndef PROBE_OFFSET_WIZARD_XY_POS
  108. #define PROBE_OFFSET_WIZARD_XY_POS XY_CENTER
  109. #endif
  110. // Get X and Y from configuration, or use center
  111. constexpr xy_pos_t wizard_pos = PROBE_OFFSET_WIZARD_XY_POS;
  112. // Probe for Z reference
  113. ui.wait_for_move = true;
  114. z_offset_ref = probe.probe_at_point(wizard_pos, PROBE_PT_RAISE, 0, true);
  115. ui.wait_for_move = false;
  116. #endif
  117. // Move Nozzle to Probing/Homing Position
  118. ui.wait_for_move = true;
  119. current_position += probe.offset_xy;
  120. line_to_current_position(MMM_TO_MMS(HOMING_FEEDRATE_XY));
  121. ui.synchronize(GET_TEXT(MSG_PROBE_WIZARD_MOVING));
  122. ui.wait_for_move = false;
  123. // Go to Calibration Menu
  124. ui.goto_screen(probe_offset_wizard_menu);
  125. ui.defer_status_screen();
  126. }
  127. void goto_probe_offset_wizard() {
  128. ui.defer_status_screen();
  129. set_all_unhomed();
  130. // Store probe.offset.z for Case: Cancel
  131. z_offset_backup = probe.offset.z;
  132. #ifdef PROBE_OFFSET_WIZARD_START_Z
  133. probe.offset.z = PROBE_OFFSET_WIZARD_START_Z;
  134. #endif
  135. // Store Bed-Leveling-State and disable
  136. #if HAS_LEVELING
  137. leveling_was_active = planner.leveling_active;
  138. set_bed_leveling_enabled(false);
  139. #endif
  140. // Home all axes
  141. queue.inject_P(G28_STR);
  142. ui.goto_screen([]{
  143. _lcd_draw_homing();
  144. if (all_axes_homed()) {
  145. SET_SOFT_ENDSTOP_LOOSE(true); // Disable soft endstops for free Z movement
  146. z_offset_ref = 0; // Set Z Value for Wizard Position to 0
  147. ui.goto_screen(prepare_for_probe_offset_wizard);
  148. ui.defer_status_screen();
  149. }
  150. });
  151. }
  152. #endif // PROBE_OFFSET_WIZARD