My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

menu_probe_offset.cpp 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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_P(PSTR("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. char tmp[20], numstr[10];
  59. // Determine digits needed right of decimal
  60. const uint8_t digs = !UNEAR_ZERO((FINE_MANUAL_MOVE) * 1000 - int((FINE_MANUAL_MOVE) * 1000)) ? 4 :
  61. !UNEAR_ZERO((FINE_MANUAL_MOVE) * 100 - int((FINE_MANUAL_MOVE) * 100)) ? 3 : 2;
  62. sprintf_P(tmp, GET_TEXT(MSG_MOVE_N_MM), dtostrf(FINE_MANUAL_MOVE, 1, digs, numstr));
  63. #if DISABLED(HAS_GRAPHICAL_TFT)
  64. SUBMENU_P(NUL_STR, []{ _goto_manual_move_z(float(FINE_MANUAL_MOVE)); });
  65. MENU_ITEM_ADDON_START(0 + ENABLED(HAS_MARLINUI_HD44780));
  66. lcd_put_u8str(tmp);
  67. MENU_ITEM_ADDON_END();
  68. #else
  69. SUBMENU_P(tmp, []{ _goto_manual_move_z(float(FINE_MANUAL_MOVE)); });
  70. #endif
  71. }
  72. ACTION_ITEM(MSG_BUTTON_DONE, []{
  73. set_offset_and_go_back(calculated_z_offset);
  74. current_position.z = z_offset_ref; // Set Z to z_offset_ref, as we can expect it is at probe height
  75. sync_plan_position();
  76. z_clearance_move(); // Raise Z as if it was homed
  77. });
  78. ACTION_ITEM(MSG_BUTTON_CANCEL, []{
  79. set_offset_and_go_back(z_offset_backup);
  80. // If wizard-homing was done by probe with PROBE_OFFSET_WIZARD_START_Z
  81. #if HOMING_Z_WITH_PROBE && defined(PROBE_OFFSET_WIZARD_START_Z)
  82. set_axis_never_homed(Z_AXIS); // On cancel the Z position needs correction
  83. queue.inject(F("G28Z"));
  84. #else // Otherwise do a Z clearance move like after Homing
  85. z_clearance_move();
  86. #endif
  87. });
  88. END_MENU();
  89. }
  90. void prepare_for_probe_offset_wizard() {
  91. #if defined(PROBE_OFFSET_WIZARD_XY_POS) || !HOMING_Z_WITH_PROBE
  92. if (ui.should_draw()) MenuItem_static::draw(1, GET_TEXT(MSG_PROBE_WIZARD_PROBING));
  93. if (ui.wait_for_move) return;
  94. #ifndef PROBE_OFFSET_WIZARD_XY_POS
  95. #define PROBE_OFFSET_WIZARD_XY_POS XY_CENTER
  96. #endif
  97. // Get X and Y from configuration, or use center
  98. constexpr xy_pos_t wizard_pos = PROBE_OFFSET_WIZARD_XY_POS;
  99. // Probe for Z reference
  100. ui.wait_for_move = true;
  101. z_offset_ref = probe.probe_at_point(wizard_pos, PROBE_PT_RAISE, 0, true);
  102. ui.wait_for_move = false;
  103. // Stow the probe, as the last call to probe.probe_at_point(...) left
  104. // the probe deployed if it was successful.
  105. probe.stow();
  106. #else
  107. if (ui.wait_for_move) return;
  108. #endif
  109. // Move Nozzle to Probing/Homing Position
  110. ui.wait_for_move = true;
  111. current_position += probe.offset_xy;
  112. line_to_current_position(MMM_TO_MMS(XY_PROBE_FEEDRATE));
  113. ui.synchronize(GET_TEXT(MSG_PROBE_WIZARD_MOVING));
  114. ui.wait_for_move = false;
  115. SET_SOFT_ENDSTOP_LOOSE(true); // Disable soft endstops for free Z movement
  116. // Go to Calibration Menu
  117. ui.goto_screen(probe_offset_wizard_menu);
  118. ui.defer_status_screen();
  119. }
  120. void goto_probe_offset_wizard() {
  121. ui.defer_status_screen();
  122. set_all_unhomed();
  123. // Store probe.offset.z for Case: Cancel
  124. z_offset_backup = probe.offset.z;
  125. #ifdef PROBE_OFFSET_WIZARD_START_Z
  126. probe.offset.z = PROBE_OFFSET_WIZARD_START_Z;
  127. #endif
  128. // Store Bed-Leveling-State and disable
  129. #if HAS_LEVELING
  130. leveling_was_active = planner.leveling_active;
  131. set_bed_leveling_enabled(false);
  132. #endif
  133. // Home all axes
  134. queue.inject_P(G28_STR);
  135. ui.goto_screen([]{
  136. _lcd_draw_homing();
  137. if (all_axes_homed()) {
  138. z_offset_ref = 0; // Set Z Value for Wizard Position to 0
  139. ui.goto_screen(prepare_for_probe_offset_wizard);
  140. ui.defer_status_screen();
  141. }
  142. });
  143. }
  144. #endif // PROBE_OFFSET_WIZARD