My Marlin configs for Fabrikator Mini and CTC i3 Pro B
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

menu_x_twist.cpp 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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_F(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_F(MSG_YES), GET_TEXT_F(MSG_NO)
  58. , []{
  59. probe.offset.z = z_offset;
  60. ui.goto_screen(xatc_wizard_done);
  61. }
  62. , xatc_wizard_done
  63. , GET_TEXT_F(MSG_XATC_UPDATE_Z_OFFSET)
  64. , ftostr42_52(z_offset), F("?")
  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_F(F("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. // Determine digits needed right of decimal
  90. const uint8_t digs = !UNEAR_ZERO((FINE_MANUAL_MOVE) * 1000 - int((FINE_MANUAL_MOVE) * 1000)) ? 4 :
  91. !UNEAR_ZERO((FINE_MANUAL_MOVE) * 100 - int((FINE_MANUAL_MOVE) * 100)) ? 3 : 2;
  92. SUBMENU_f(F(STRINGIFY(FINE_MANUAL_MOVE)), MSG_MOVE_N_MM, []{ _goto_manual_move_z(float(FINE_MANUAL_MOVE)); });
  93. }
  94. ACTION_ITEM(MSG_BUTTON_DONE, xatc_wizard_set_offset_and_go_to_next_point);
  95. END_MENU();
  96. }
  97. //
  98. // Step 5: Display "Next point: 1 / 9" while waiting for move to finish
  99. //
  100. void xatc_wizard_moving() {
  101. if (ui.should_draw()) {
  102. char msg[10];
  103. sprintf_P(msg, PSTR("%i / %u"), manual_probe_index + 1, XATC_MAX_POINTS);
  104. MenuEditItemBase::draw_edit_screen(GET_TEXT_F(MSG_LEVEL_BED_NEXT_POINT), msg);
  105. }
  106. ui.refresh(LCDVIEW_CALL_NO_REDRAW);
  107. if (!ui.wait_for_move) ui.goto_screen(xatc_wizard_menu);
  108. }
  109. //
  110. // Step 4: Initiate a move to the next point
  111. //
  112. void xatc_wizard_goto_next_point() {
  113. if (manual_probe_index < XATC_MAX_POINTS) {
  114. const float x = xatc.start + manual_probe_index * xatc.spacing;
  115. // Avoid probing outside the round or hexagonal area
  116. if (!TERN0(IS_KINEMATIC, !probe.can_reach(x, XATC_Y_POSITION))) {
  117. ui.wait_for_move = true;
  118. ui.goto_screen(xatc_wizard_moving);
  119. // Deploy certain probes before starting probing
  120. TERN_(BLTOUCH, do_z_clearance(Z_CLEARANCE_DEPLOY_PROBE));
  121. xatc.set_enabled(false);
  122. measured_z = probe.probe_at_point(x, XATC_Y_POSITION, PROBE_PT_STOW);
  123. xatc.set_enabled(true);
  124. current_position += probe.offset_xy;
  125. current_position.z = (XATC_START_Z) - probe.offset.z + measured_z;
  126. line_to_current_position(MMM_TO_MMS(XY_PROBE_FEEDRATE));
  127. ui.wait_for_move = false;
  128. }
  129. else
  130. manual_probe_index++; // Go to next point
  131. }
  132. else {
  133. // Compute the z-offset by averaging the values found with this wizard
  134. z_offset = 0;
  135. LOOP_L_N(i, XATC_MAX_POINTS) z_offset += xatc.z_offset[i];
  136. z_offset /= XATC_MAX_POINTS;
  137. // Subtract the average from the values found with this wizard.
  138. // This way they are indipendent from the z-offset
  139. LOOP_L_N(i, XATC_MAX_POINTS) xatc.z_offset[i] -= z_offset;
  140. ui.goto_screen(xatc_wizard_update_z_offset);
  141. }
  142. }
  143. //
  144. // Step 3: Display "Click to Begin", wait for click
  145. // Move to the first probe position
  146. //
  147. void xatc_wizard_homing_done() {
  148. if (ui.should_draw()) {
  149. MenuItem_static::draw(1, GET_TEXT_F(MSG_LEVEL_BED_WAITING));
  150. // Color UI needs a control to detect a touch
  151. #if BOTH(TOUCH_SCREEN, HAS_GRAPHICAL_TFT)
  152. touch.add_control(CLICK, 0, 0, TFT_WIDTH, TFT_HEIGHT);
  153. #endif
  154. }
  155. if (ui.use_click()) {
  156. xatc.reset();
  157. SET_SOFT_ENDSTOP_LOOSE(true); // Disable soft endstops for free Z movement
  158. ui.goto_screen(xatc_wizard_goto_next_point);
  159. }
  160. }
  161. //
  162. // Step 2: Display "Homing XYZ" - Wait for homing to finish
  163. //
  164. void xatc_wizard_homing() {
  165. _lcd_draw_homing();
  166. if (all_axes_homed())
  167. ui.goto_screen(xatc_wizard_homing_done);
  168. }
  169. //
  170. // Step 1: Prepare for the wizard...
  171. //
  172. void xatc_wizard_continue() {
  173. // Store Bed-Leveling-State and disable
  174. #if HAS_LEVELING
  175. leveling_was_active = planner.leveling_active;
  176. set_bed_leveling_enabled(false);
  177. #endif
  178. // Home all axes
  179. ui.defer_status_screen();
  180. set_all_unhomed();
  181. ui.goto_screen(xatc_wizard_homing);
  182. queue.inject_P(G28_STR);
  183. }
  184. #endif // X_AXIS_TWIST_COMPENSATION