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_motion.cpp 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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. // Motion Menu
  24. //
  25. #include "../../inc/MarlinConfigPre.h"
  26. #if HAS_MARLINUI_MENU
  27. #define LARGE_AREA_TEST ((X_BED_SIZE) >= 1000 || (Y_BED_SIZE) >= 1000 || (Z_MAX_POS) >= 1000)
  28. #include "menu_item.h"
  29. #include "menu_addon.h"
  30. #include "../../module/motion.h"
  31. #include "../../gcode/parser.h" // for inch support
  32. #include "../../module/temperature.h"
  33. #if ENABLED(DELTA)
  34. #include "../../module/delta.h"
  35. #endif
  36. #if HAS_LEVELING
  37. #include "../../module/planner.h"
  38. #include "../../feature/bedlevel/bedlevel.h"
  39. #endif
  40. //
  41. // "Motion" > "Move Axis" submenu
  42. //
  43. void lcd_move_axis(const AxisEnum axis) {
  44. if (ui.use_click()) return ui.goto_previous_screen_no_defer();
  45. if (ui.encoderPosition && !ui.manual_move.processing) {
  46. // Get motion limit from software endstops, if any
  47. float min, max;
  48. soft_endstop.get_manual_axis_limits(axis, min, max);
  49. // Delta limits XY based on the current offset from center
  50. // This assumes the center is 0,0
  51. #if ENABLED(DELTA)
  52. if (axis != Z_AXIS) {
  53. max = SQRT(sq((float)(DELTA_PRINTABLE_RADIUS)) - sq(current_position[Y_AXIS - axis])); // (Y_AXIS - axis) == the other axis
  54. min = -max;
  55. }
  56. #endif
  57. // Get the new position
  58. const float diff = float(int32_t(ui.encoderPosition)) * ui.manual_move.menu_scale;
  59. (void)ui.manual_move.apply_diff(axis, diff, min, max);
  60. ui.manual_move.soon(axis);
  61. ui.refresh(LCDVIEW_REDRAW_NOW);
  62. }
  63. ui.encoderPosition = 0;
  64. if (ui.should_draw()) {
  65. const float pos = ui.manual_move.axis_value(axis);
  66. if (parser.using_inch_units()) {
  67. const float imp_pos = LINEAR_UNIT(pos);
  68. MenuEditItemBase::draw_edit_screen(GET_TEXT_F(MSG_MOVE_N), ftostr63(imp_pos));
  69. }
  70. else
  71. MenuEditItemBase::draw_edit_screen(GET_TEXT_F(MSG_MOVE_N), ui.manual_move.menu_scale >= 0.1f ? (LARGE_AREA_TEST ? ftostr51sign(pos) : ftostr41sign(pos)) : ftostr63(pos));
  72. }
  73. }
  74. // Move Z easy accessor
  75. void lcd_move_z() { lcd_move_axis(Z_AXIS); }
  76. #if E_MANUAL
  77. static void lcd_move_e(TERN_(MULTI_E_MANUAL, const int8_t eindex=active_extruder)) {
  78. if (ui.use_click()) return ui.goto_previous_screen_no_defer();
  79. if (ui.encoderPosition) {
  80. if (!ui.manual_move.processing) {
  81. const float diff = float(int32_t(ui.encoderPosition)) * ui.manual_move.menu_scale;
  82. TERN(IS_KINEMATIC, ui.manual_move.offset, current_position.e) += diff;
  83. ui.manual_move.soon(E_AXIS OPTARG(MULTI_E_MANUAL, eindex));
  84. ui.refresh(LCDVIEW_REDRAW_NOW);
  85. }
  86. ui.encoderPosition = 0;
  87. }
  88. if (ui.should_draw()) {
  89. TERN_(MULTI_E_MANUAL, MenuItemBase::init(eindex));
  90. MenuEditItemBase::draw_edit_screen(
  91. GET_TEXT_F(TERN(MULTI_E_MANUAL, MSG_MOVE_EN, MSG_MOVE_E)),
  92. ftostr41sign(current_position.e
  93. PLUS_TERN0(IS_KINEMATIC, ui.manual_move.offset)
  94. MINUS_TERN0(MANUAL_E_MOVES_RELATIVE, ui.manual_move.e_origin)
  95. )
  96. );
  97. } // should_draw
  98. }
  99. #endif // E_MANUAL
  100. #if EITHER(PROBE_OFFSET_WIZARD, X_AXIS_TWIST_COMPENSATION)
  101. void _goto_manual_move_z(const_float_t scale) {
  102. ui.manual_move.menu_scale = scale;
  103. ui.goto_screen(lcd_move_z);
  104. }
  105. #endif
  106. //
  107. // "Motion" > "Move Xmm" > "Move XYZ" submenu
  108. //
  109. #ifndef FINE_MANUAL_MOVE
  110. #define FINE_MANUAL_MOVE 0.025
  111. #endif
  112. void _goto_manual_move(const_float_t scale) {
  113. ui.defer_status_screen();
  114. ui.manual_move.menu_scale = scale;
  115. ui.goto_screen(ui.manual_move.screen_ptr);
  116. thermalManager.set_menu_cold_override(true);
  117. }
  118. void _menu_move_distance(const AxisEnum axis, const screenFunc_t func, const int8_t eindex=active_extruder) {
  119. ui.manual_move.screen_ptr = func;
  120. START_MENU();
  121. if (LCD_HEIGHT >= 4) {
  122. if (axis < NUM_AXES)
  123. STATIC_ITEM_N(axis, MSG_MOVE_N, SS_DEFAULT|SS_INVERT);
  124. else {
  125. TERN_(MANUAL_E_MOVES_RELATIVE, ui.manual_move.e_origin = current_position.e);
  126. STATIC_ITEM_N(eindex, MSG_MOVE_EN, SS_DEFAULT|SS_INVERT);
  127. }
  128. }
  129. BACK_ITEM(MSG_MOVE_AXIS);
  130. if (parser.using_inch_units()) {
  131. if (LARGE_AREA_TEST) SUBMENU(MSG_MOVE_1IN, []{ _goto_manual_move(IN_TO_MM(1.000f)); });
  132. SUBMENU(MSG_MOVE_01IN, []{ _goto_manual_move(IN_TO_MM(0.100f)); });
  133. SUBMENU(MSG_MOVE_001IN, []{ _goto_manual_move(IN_TO_MM(0.010f)); });
  134. SUBMENU(MSG_MOVE_0001IN, []{ _goto_manual_move(IN_TO_MM(0.001f)); });
  135. }
  136. else {
  137. if (LARGE_AREA_TEST) SUBMENU(MSG_MOVE_100MM, []{ _goto_manual_move(100); });
  138. SUBMENU(MSG_MOVE_10MM, []{ _goto_manual_move(10); });
  139. SUBMENU(MSG_MOVE_1MM, []{ _goto_manual_move( 1); });
  140. SUBMENU(MSG_MOVE_01MM, []{ _goto_manual_move( 0.1f); });
  141. if (axis == Z_AXIS && (FINE_MANUAL_MOVE) > 0.0f && (FINE_MANUAL_MOVE) < 0.1f)
  142. SUBMENU_f(F(STRINGIFY(FINE_MANUAL_MOVE)), MSG_MOVE_N_MM, []{ _goto_manual_move(float(FINE_MANUAL_MOVE)); });
  143. }
  144. END_MENU();
  145. }
  146. #if E_MANUAL
  147. inline void _goto_menu_move_distance_e() {
  148. ui.goto_screen([]{ _menu_move_distance(E_AXIS, []{ lcd_move_e(); }); });
  149. }
  150. inline void _menu_move_distance_e_maybe() {
  151. if (thermalManager.tooColdToExtrude(active_extruder)) {
  152. ui.goto_screen([]{
  153. MenuItem_confirm::select_screen(
  154. GET_TEXT_F(MSG_BUTTON_PROCEED), GET_TEXT_F(MSG_BACK),
  155. _goto_menu_move_distance_e, nullptr,
  156. GET_TEXT_F(MSG_HOTEND_TOO_COLD), (const char *)nullptr, F("!")
  157. );
  158. });
  159. }
  160. else
  161. _goto_menu_move_distance_e();
  162. }
  163. #endif
  164. void menu_move() {
  165. START_MENU();
  166. BACK_ITEM(MSG_MOTION);
  167. #if BOTH(HAS_SOFTWARE_ENDSTOPS, SOFT_ENDSTOPS_MENU_ITEM)
  168. EDIT_ITEM(bool, MSG_LCD_SOFT_ENDSTOPS, &soft_endstop._enabled);
  169. #endif
  170. // Move submenu for each axis
  171. if (NONE(IS_KINEMATIC, NO_MOTION_BEFORE_HOMING) || all_axes_homed()) {
  172. if (TERN1(DELTA, current_position.z <= delta_clip_start_height)) {
  173. SUBMENU_N(X_AXIS, MSG_MOVE_N, []{ _menu_move_distance(X_AXIS, []{ lcd_move_axis(X_AXIS); }); });
  174. #if HAS_Y_AXIS
  175. SUBMENU_N(Y_AXIS, MSG_MOVE_N, []{ _menu_move_distance(Y_AXIS, []{ lcd_move_axis(Y_AXIS); }); });
  176. #endif
  177. }
  178. else {
  179. #if ENABLED(DELTA)
  180. ACTION_ITEM(MSG_FREE_XY, []{ line_to_z(delta_clip_start_height); ui.synchronize(); });
  181. #endif
  182. }
  183. #if HAS_Z_AXIS
  184. #define _AXIS_MOVE(N) SUBMENU_N(N, MSG_MOVE_N, []{ _menu_move_distance(AxisEnum(N), []{ lcd_move_axis(AxisEnum(N)); }); });
  185. REPEAT_S(2, NUM_AXES, _AXIS_MOVE);
  186. #endif
  187. }
  188. else
  189. GCODES_ITEM(MSG_AUTO_HOME, FPSTR(G28_STR));
  190. #if ANY(SWITCHING_EXTRUDER, SWITCHING_NOZZLE, MAGNETIC_SWITCHING_TOOLHEAD)
  191. #if EXTRUDERS >= 4
  192. switch (active_extruder) {
  193. case 0: GCODES_ITEM_N(1, MSG_SELECT_E, F("T1")); break;
  194. case 1: GCODES_ITEM_N(0, MSG_SELECT_E, F("T0")); break;
  195. case 2: GCODES_ITEM_N(3, MSG_SELECT_E, F("T3")); break;
  196. case 3: GCODES_ITEM_N(2, MSG_SELECT_E, F("T2")); break;
  197. #if EXTRUDERS == 6
  198. case 4: GCODES_ITEM_N(5, MSG_SELECT_E, F("T5")); break;
  199. case 5: GCODES_ITEM_N(4, MSG_SELECT_E, F("T4")); break;
  200. #endif
  201. }
  202. #elif EXTRUDERS == 3
  203. if (active_extruder < 2) {
  204. if (active_extruder)
  205. GCODES_ITEM_N(0, MSG_SELECT_E, F("T0"));
  206. else
  207. GCODES_ITEM_N(1, MSG_SELECT_E, F("T1"));
  208. }
  209. #else
  210. if (active_extruder)
  211. GCODES_ITEM_N(0, MSG_SELECT_E, F("T0"));
  212. else
  213. GCODES_ITEM_N(1, MSG_SELECT_E, F("T1"));
  214. #endif
  215. #elif ENABLED(DUAL_X_CARRIAGE)
  216. if (active_extruder)
  217. GCODES_ITEM_N(0, MSG_SELECT_E, F("T0"));
  218. else
  219. GCODES_ITEM_N(1, MSG_SELECT_E, F("T1"));
  220. #endif
  221. #if E_MANUAL
  222. // The current extruder
  223. SUBMENU(MSG_MOVE_E, _menu_move_distance_e_maybe);
  224. #define SUBMENU_MOVE_E(N) SUBMENU_N(N, MSG_MOVE_EN, []{ _menu_move_distance(E_AXIS, []{ lcd_move_e(N); }, N); });
  225. #if EITHER(SWITCHING_EXTRUDER, SWITCHING_NOZZLE)
  226. // ...and the non-switching
  227. #if E_MANUAL == 7 || E_MANUAL == 5 || E_MANUAL == 3
  228. SUBMENU_MOVE_E(E_MANUAL - 1);
  229. #endif
  230. #elif MULTI_E_MANUAL
  231. // Independent extruders with one E stepper per hotend
  232. REPEAT(E_MANUAL, SUBMENU_MOVE_E);
  233. #endif
  234. #endif // E_MANUAL
  235. END_MENU();
  236. }
  237. #define _HOME_ITEM(N) GCODES_ITEM_N(N##_AXIS, MSG_AUTO_HOME_A, F("G28" STR_##N));
  238. #if ENABLED(INDIVIDUAL_AXIS_HOMING_SUBMENU)
  239. //
  240. // "Motion" > "Homing" submenu
  241. //
  242. void menu_home() {
  243. START_MENU();
  244. BACK_ITEM(MSG_MOTION);
  245. GCODES_ITEM(MSG_AUTO_HOME, FPSTR(G28_STR));
  246. MAIN_AXIS_MAP(_HOME_ITEM);
  247. END_MENU();
  248. }
  249. #endif
  250. #if ENABLED(AUTO_BED_LEVELING_UBL)
  251. void _lcd_ubl_level_bed();
  252. #elif ENABLED(LCD_BED_LEVELING)
  253. void menu_bed_leveling();
  254. #endif
  255. #if ENABLED(ASSISTED_TRAMMING_WIZARD)
  256. void goto_tramming_wizard();
  257. #endif
  258. void menu_motion() {
  259. START_MENU();
  260. //
  261. // ^ Main
  262. //
  263. BACK_ITEM(MSG_MAIN);
  264. //
  265. // Move Axis
  266. //
  267. if (TERN1(DELTA, all_axes_homed()))
  268. SUBMENU(MSG_MOVE_AXIS, menu_move);
  269. //
  270. // Auto Home
  271. //
  272. #if ENABLED(INDIVIDUAL_AXIS_HOMING_SUBMENU)
  273. SUBMENU(MSG_HOMING, menu_home);
  274. #else
  275. GCODES_ITEM(MSG_AUTO_HOME, FPSTR(G28_STR));
  276. #if ENABLED(INDIVIDUAL_AXIS_HOMING_MENU)
  277. MAIN_AXIS_MAP(_HOME_ITEM);
  278. #endif
  279. #endif
  280. //
  281. // Auto-calibration
  282. //
  283. #if ENABLED(CALIBRATION_GCODE)
  284. GCODES_ITEM(MSG_AUTO_CALIBRATE, F("G425"));
  285. #endif
  286. //
  287. // Auto Z-Align
  288. //
  289. #if EITHER(Z_STEPPER_AUTO_ALIGN, MECHANICAL_GANTRY_CALIBRATION)
  290. GCODES_ITEM(MSG_AUTO_Z_ALIGN, F("G34"));
  291. #endif
  292. //
  293. // Probe Deploy/Stow
  294. //
  295. #if ENABLED(PROBE_DEPLOY_STOW_MENU)
  296. GCODES_ITEM(MSG_MANUAL_DEPLOY, F("M401"));
  297. GCODES_ITEM(MSG_MANUAL_STOW, F("M402"));
  298. #endif
  299. //
  300. // Assisted Bed Tramming
  301. //
  302. #if ENABLED(ASSISTED_TRAMMING_WIZARD)
  303. SUBMENU(MSG_TRAMMING_WIZARD, goto_tramming_wizard);
  304. #endif
  305. //
  306. // Level Bed
  307. //
  308. #if ENABLED(AUTO_BED_LEVELING_UBL)
  309. SUBMENU(MSG_UBL_LEVEL_BED, _lcd_ubl_level_bed);
  310. #elif ENABLED(LCD_BED_LEVELING)
  311. if (!g29_in_progress)
  312. SUBMENU(MSG_BED_LEVELING, menu_bed_leveling);
  313. #elif HAS_LEVELING && DISABLED(SLIM_LCD_MENUS)
  314. #if DISABLED(PROBE_MANUALLY)
  315. GCODES_ITEM(MSG_LEVEL_BED, F("G29N"));
  316. #endif
  317. if (all_axes_homed() && leveling_is_valid()) {
  318. bool show_state = planner.leveling_active;
  319. EDIT_ITEM(bool, MSG_BED_LEVELING, &show_state, _lcd_toggle_bed_leveling);
  320. }
  321. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  322. editable.decimal = planner.z_fade_height;
  323. EDIT_ITEM_FAST(float3, MSG_Z_FADE_HEIGHT, &editable.decimal, 0, 100, []{ set_z_fade_height(editable.decimal); });
  324. #endif
  325. #endif
  326. #if ENABLED(LCD_BED_TRAMMING) && DISABLED(LCD_BED_LEVELING)
  327. SUBMENU(MSG_BED_TRAMMING, _lcd_level_bed_corners);
  328. #endif
  329. #if ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST)
  330. GCODES_ITEM(MSG_M48_TEST, F("G28O\nM48 P10"));
  331. #endif
  332. //
  333. // Disable Steppers
  334. //
  335. GCODES_ITEM(MSG_DISABLE_STEPPERS, F("M84"));
  336. END_MENU();
  337. }
  338. #endif // HAS_MARLINUI_MENU