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 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. void _goto_manual_move_z(const_float_t);
  37. // Global storage
  38. float z_offset_backup, calculated_z_offset, z_offset_ref;
  39. inline void z_clearance_move() {
  40. do_z_clearance(Z_POST_CLEARANCE);
  41. }
  42. void set_offset_and_go_back(const_float_t z) {
  43. probe.offset.z = z;
  44. SET_SOFT_ENDSTOP_LOOSE(false);
  45. TERN_(HAS_LEVELING, set_bed_leveling_enabled(leveling_was_active));
  46. ui.goto_previous_screen_no_defer();
  47. }
  48. void probe_offset_wizard_menu() {
  49. START_MENU();
  50. calculated_z_offset = probe.offset.z + current_position.z - z_offset_ref;
  51. if (LCD_HEIGHT >= 4)
  52. STATIC_ITEM(MSG_MOVE_NOZZLE_TO_BED, SS_CENTER|SS_INVERT);
  53. STATIC_ITEM_F(F("Z"), SS_CENTER, ftostr42_52(current_position.z));
  54. STATIC_ITEM(MSG_ZPROBE_ZOFFSET, SS_LEFT, ftostr42_52(calculated_z_offset));
  55. SUBMENU(MSG_MOVE_1MM, []{ _goto_manual_move_z( 1); });
  56. SUBMENU(MSG_MOVE_01MM, []{ _goto_manual_move_z( 0.1f); });
  57. if ((FINE_MANUAL_MOVE) > 0.0f && (FINE_MANUAL_MOVE) < 0.1f)
  58. SUBMENU_f(F(STRINGIFY(FINE_MANUAL_MOVE)), MSG_MOVE_N_MM, []{ _goto_manual_move_z(float(FINE_MANUAL_MOVE)); });
  59. ACTION_ITEM(MSG_BUTTON_DONE, []{
  60. set_offset_and_go_back(calculated_z_offset);
  61. current_position.z = z_offset_ref; // Set Z to z_offset_ref, as we can expect it is at probe height
  62. sync_plan_position();
  63. z_clearance_move(); // Raise Z as if it was homed
  64. });
  65. ACTION_ITEM(MSG_BUTTON_CANCEL, []{
  66. set_offset_and_go_back(z_offset_backup);
  67. // If wizard-homing was done by probe with PROBE_OFFSET_WIZARD_START_Z
  68. #if HOMING_Z_WITH_PROBE && defined(PROBE_OFFSET_WIZARD_START_Z)
  69. set_axis_never_homed(Z_AXIS); // On cancel the Z position needs correction
  70. queue.inject(F("G28Z"));
  71. #else // Otherwise do a Z clearance move like after Homing
  72. z_clearance_move();
  73. #endif
  74. });
  75. END_MENU();
  76. }
  77. void prepare_for_probe_offset_wizard() {
  78. #if defined(PROBE_OFFSET_WIZARD_XY_POS) || !HOMING_Z_WITH_PROBE
  79. if (ui.should_draw()) MenuItem_static::draw(1, GET_TEXT_F(MSG_PROBE_WIZARD_PROBING));
  80. if (ui.wait_for_move) return;
  81. #ifndef PROBE_OFFSET_WIZARD_XY_POS
  82. #define PROBE_OFFSET_WIZARD_XY_POS XY_CENTER
  83. #endif
  84. // Get X and Y from configuration, or use center
  85. constexpr xy_pos_t wizard_pos = PROBE_OFFSET_WIZARD_XY_POS;
  86. // Probe for Z reference
  87. ui.wait_for_move = true;
  88. z_offset_ref = probe.probe_at_point(wizard_pos, PROBE_PT_RAISE, 0, true);
  89. ui.wait_for_move = false;
  90. // Stow the probe, as the last call to probe.probe_at_point(...) left
  91. // the probe deployed if it was successful.
  92. probe.stow();
  93. #else
  94. if (ui.wait_for_move) return;
  95. #endif
  96. // Move Nozzle to Probing/Homing Position
  97. ui.wait_for_move = true;
  98. current_position += probe.offset_xy;
  99. line_to_current_position(MMM_TO_MMS(XY_PROBE_FEEDRATE));
  100. ui.synchronize(GET_TEXT_F(MSG_PROBE_WIZARD_MOVING));
  101. ui.wait_for_move = false;
  102. SET_SOFT_ENDSTOP_LOOSE(true); // Disable soft endstops for free Z movement
  103. // Go to Calibration Menu
  104. ui.goto_screen(probe_offset_wizard_menu);
  105. ui.defer_status_screen();
  106. }
  107. void goto_probe_offset_wizard() {
  108. ui.defer_status_screen();
  109. set_all_unhomed();
  110. // Store probe.offset.z for Case: Cancel
  111. z_offset_backup = probe.offset.z;
  112. #ifdef PROBE_OFFSET_WIZARD_START_Z
  113. probe.offset.z = PROBE_OFFSET_WIZARD_START_Z;
  114. #endif
  115. // Store Bed-Leveling-State and disable
  116. #if HAS_LEVELING
  117. leveling_was_active = planner.leveling_active;
  118. set_bed_leveling_enabled(false);
  119. #endif
  120. // Home all axes
  121. queue.inject_P(G28_STR);
  122. ui.goto_screen([]{
  123. _lcd_draw_homing();
  124. if (all_axes_homed()) {
  125. z_offset_ref = 0; // Set Z Value for Wizard Position to 0
  126. ui.goto_screen(prepare_for_probe_offset_wizard);
  127. ui.defer_status_screen();
  128. }
  129. });
  130. }
  131. #endif // PROBE_OFFSET_WIZARD