My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

menu_x_twist.cpp 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2021 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. #include "../../inc/MarlinConfigPre.h"
  23. #if ENABLED(X_AXIS_TWIST_COMPENSATION)
  24. #include "menu_item.h"
  25. #include "menu_addon.h"
  26. #include "../../module/planner.h"
  27. #include "../../feature/bedlevel/bedlevel.h"
  28. #include "../../feature/x_twist.h"
  29. #include "../../module/motion.h"
  30. #include "../../gcode/queue.h"
  31. #include "../../module/probe.h"
  32. #ifndef XATC_Y_POSITION
  33. #define XATC_Y_POSITION ((probe.max_y() - probe.min_y())/2)
  34. #endif
  35. void _goto_manual_move_z(const_float_t);
  36. float measured_z, z_offset;
  37. //
  38. // Step 9: X Axis Twist Compensation Wizard is finished.
  39. //
  40. void xatc_wizard_done() {
  41. if (!ui.wait_for_move) {
  42. xatc.print_points();
  43. set_bed_leveling_enabled(leveling_was_active);
  44. SET_SOFT_ENDSTOP_LOOSE(false);
  45. ui.goto_screen(menu_advanced_settings);
  46. }
  47. if (ui.should_draw())
  48. MenuItem_static::draw(LCD_HEIGHT >= 4, GET_TEXT(MSG_XATC_DONE));
  49. ui.refresh(LCDVIEW_CALL_REDRAW_NEXT);
  50. }
  51. void xatc_wizard_goto_next_point();
  52. //
  53. // Step 8: Ask the user if he wants to update the z-offset of the probe
  54. //
  55. void xatc_wizard_update_z_offset() {
  56. MenuItem_confirm::select_screen(
  57. GET_TEXT(MSG_YES), GET_TEXT(MSG_NO)
  58. , []{
  59. probe.offset.z = z_offset;
  60. ui.goto_screen(xatc_wizard_done);
  61. }
  62. , xatc_wizard_done
  63. , GET_TEXT(MSG_XATC_UPDATE_Z_OFFSET)
  64. , ftostr42_52(z_offset), PSTR("?")
  65. );
  66. }
  67. //
  68. // Step 7: Set the Z-offset for this point and go to the next one.
  69. //
  70. void xatc_wizard_set_offset_and_go_to_next_point() {
  71. // Set Z-offset at probed point
  72. xatc.z_offset[manual_probe_index++] = probe.offset.z + current_position.z - measured_z;
  73. // Go to next point
  74. ui.goto_screen(xatc_wizard_goto_next_point);
  75. }
  76. //
  77. // Step 6: Wizard Menu. Move the nozzle down until it touches the bed.
  78. //
  79. void xatc_wizard_menu() {
  80. START_MENU();
  81. float calculated_z_offset = probe.offset.z + current_position.z - measured_z;
  82. if (LCD_HEIGHT >= 4)
  83. STATIC_ITEM(MSG_MOVE_NOZZLE_TO_BED, SS_CENTER|SS_INVERT);
  84. STATIC_ITEM_P(PSTR("Z="), SS_CENTER, ftostr42_52(current_position.z));
  85. STATIC_ITEM(MSG_ZPROBE_ZOFFSET, SS_LEFT, ftostr42_52(calculated_z_offset));
  86. SUBMENU(MSG_MOVE_1MM, []{ _goto_manual_move_z( 1); });
  87. SUBMENU(MSG_MOVE_01MM, []{ _goto_manual_move_z( 0.1f); });
  88. if ((FINE_MANUAL_MOVE) > 0.0f && (FINE_MANUAL_MOVE) < 0.1f) {
  89. char tmp[20], numstr[10];
  90. // Determine digits needed right of decimal
  91. const uint8_t digs = !UNEAR_ZERO((FINE_MANUAL_MOVE) * 1000 - int((FINE_MANUAL_MOVE) * 1000)) ? 4 :
  92. !UNEAR_ZERO((FINE_MANUAL_MOVE) * 100 - int((FINE_MANUAL_MOVE) * 100)) ? 3 : 2;
  93. sprintf_P(tmp, GET_TEXT(MSG_MOVE_N_MM), dtostrf(FINE_MANUAL_MOVE, 1, digs, numstr));
  94. #if DISABLED(HAS_GRAPHICAL_TFT)
  95. SUBMENU_P(NUL_STR, []{ _goto_manual_move_z(float(FINE_MANUAL_MOVE)); });
  96. MENU_ITEM_ADDON_START(0 + ENABLED(HAS_MARLINUI_HD44780));
  97. lcd_put_u8str(tmp);
  98. MENU_ITEM_ADDON_END();
  99. #else
  100. SUBMENU_P(tmp, []{ _goto_manual_move_z(float(FINE_MANUAL_MOVE)); });
  101. #endif
  102. }
  103. ACTION_ITEM(MSG_BUTTON_DONE, xatc_wizard_set_offset_and_go_to_next_point);
  104. END_MENU();
  105. }
  106. //
  107. // Step 5: Display "Next point: 1 / 9" while waiting for move to finish
  108. //
  109. void xatc_wizard_moving() {
  110. if (ui.should_draw()) {
  111. char msg[10];
  112. sprintf_P(msg, PSTR("%i / %u"), manual_probe_index + 1, XATC_MAX_POINTS);
  113. MenuEditItemBase::draw_edit_screen(GET_TEXT(MSG_LEVEL_BED_NEXT_POINT), msg);
  114. }
  115. ui.refresh(LCDVIEW_CALL_NO_REDRAW);
  116. if (!ui.wait_for_move) ui.goto_screen(xatc_wizard_menu);
  117. }
  118. //
  119. // Step 4: Initiate a move to the next point
  120. //
  121. void xatc_wizard_goto_next_point() {
  122. if (manual_probe_index < XATC_MAX_POINTS) {
  123. const float x = xatc.start + manual_probe_index * xatc.spacing;
  124. // Avoid probing outside the round or hexagonal area
  125. if (!TERN0(IS_KINEMATIC, !probe.can_reach(x, XATC_Y_POSITION))) {
  126. ui.wait_for_move = true;
  127. ui.goto_screen(xatc_wizard_moving);
  128. // Deploy certain probes before starting probing
  129. TERN_(BLTOUCH, do_z_clearance(Z_CLEARANCE_DEPLOY_PROBE));
  130. xatc.set_enabled(false);
  131. measured_z = probe.probe_at_point(x, XATC_Y_POSITION, PROBE_PT_STOW);
  132. xatc.set_enabled(true);
  133. current_position += probe.offset_xy;
  134. current_position.z = (XATC_START_Z) - probe.offset.z + measured_z;
  135. line_to_current_position(MMM_TO_MMS(XY_PROBE_FEEDRATE));
  136. ui.wait_for_move = false;
  137. }
  138. else
  139. manual_probe_index++; // Go to next point
  140. }
  141. else {
  142. // Compute the z-offset by averaging the values found with this wizard
  143. z_offset = 0;
  144. LOOP_L_N(i, XATC_MAX_POINTS) z_offset += xatc.z_offset[i];
  145. z_offset /= XATC_MAX_POINTS;
  146. // Subtract the average from the values found with this wizard.
  147. // This way they are indipendent from the z-offset
  148. LOOP_L_N(i, XATC_MAX_POINTS) xatc.z_offset[i] -= z_offset;
  149. ui.goto_screen(xatc_wizard_update_z_offset);
  150. }
  151. }
  152. //
  153. // Step 3: Display "Click to Begin", wait for click
  154. // Move to the first probe position
  155. //
  156. void xatc_wizard_homing_done() {
  157. if (ui.should_draw()) {
  158. MenuItem_static::draw(1, GET_TEXT(MSG_LEVEL_BED_WAITING));
  159. // Color UI needs a control to detect a touch
  160. #if BOTH(TOUCH_SCREEN, HAS_GRAPHICAL_TFT)
  161. touch.add_control(CLICK, 0, 0, TFT_WIDTH, TFT_HEIGHT);
  162. #endif
  163. }
  164. if (ui.use_click()) {
  165. xatc.reset();
  166. SET_SOFT_ENDSTOP_LOOSE(true); // Disable soft endstops for free Z movement
  167. ui.goto_screen(xatc_wizard_goto_next_point);
  168. }
  169. }
  170. //
  171. // Step 2: Display "Homing XYZ" - Wait for homing to finish
  172. //
  173. void xatc_wizard_homing() {
  174. _lcd_draw_homing();
  175. if (all_axes_homed())
  176. ui.goto_screen(xatc_wizard_homing_done);
  177. }
  178. //
  179. // Step 1: Prepare for the wizard...
  180. //
  181. void xatc_wizard_continue() {
  182. // Store Bed-Leveling-State and disable
  183. #if HAS_LEVELING
  184. leveling_was_active = planner.leveling_active;
  185. set_bed_leveling_enabled(false);
  186. #endif
  187. // Home all axes
  188. ui.defer_status_screen();
  189. set_all_unhomed();
  190. ui.goto_screen(xatc_wizard_homing);
  191. queue.inject_P(G28_STR);
  192. }
  193. #endif // X_AXIS_TWIST_COMPENSATION