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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  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. #if ENABLED(MANUAL_E_MOVES_RELATIVE)
  41. float manual_move_e_origin = 0;
  42. #endif
  43. //
  44. // "Motion" > "Move Axis" submenu
  45. //
  46. // TODO: Use substitution here with MSG_MOVE_N
  47. static void _lcd_move_xyz(FSTR_P const name, const AxisEnum axis) {
  48. if (ui.use_click()) return ui.goto_previous_screen_no_defer();
  49. if (ui.encoderPosition && !ui.manual_move.processing) {
  50. // Get motion limit from software endstops, if any
  51. float min, max;
  52. soft_endstop.get_manual_axis_limits(axis, min, max);
  53. // Delta limits XY based on the current offset from center
  54. // This assumes the center is 0,0
  55. #if ENABLED(DELTA)
  56. if (axis != Z_AXIS) {
  57. max = SQRT(sq((float)(DELTA_PRINTABLE_RADIUS)) - sq(current_position[Y_AXIS - axis])); // (Y_AXIS - axis) == the other axis
  58. min = -max;
  59. }
  60. #endif
  61. // Get the new position
  62. const float diff = float(int32_t(ui.encoderPosition)) * ui.manual_move.menu_scale;
  63. (void)ui.manual_move.apply_diff(axis, diff, min, max);
  64. ui.manual_move.soon(axis);
  65. ui.refresh(LCDVIEW_REDRAW_NOW);
  66. }
  67. ui.encoderPosition = 0;
  68. if (ui.should_draw()) {
  69. const float pos = ui.manual_move.axis_value(axis);
  70. if (parser.using_inch_units()) {
  71. const float imp_pos = LINEAR_UNIT(pos);
  72. MenuEditItemBase::draw_edit_screen(name, ftostr63(imp_pos));
  73. }
  74. else
  75. MenuEditItemBase::draw_edit_screen(name, ui.manual_move.menu_scale >= 0.1f ? (LARGE_AREA_TEST ? ftostr51sign(pos) : ftostr41sign(pos)) : ftostr63(pos));
  76. }
  77. }
  78. void lcd_move_x() { _lcd_move_xyz(GET_TEXT_F(MSG_MOVE_X), X_AXIS); }
  79. #if HAS_Y_AXIS
  80. void lcd_move_y() { _lcd_move_xyz(GET_TEXT_F(MSG_MOVE_Y), Y_AXIS); }
  81. #endif
  82. #if HAS_Z_AXIS
  83. void lcd_move_z() { _lcd_move_xyz(GET_TEXT_F(MSG_MOVE_Z), Z_AXIS); }
  84. #endif
  85. #if HAS_I_AXIS
  86. void lcd_move_i() { _lcd_move_xyz(GET_TEXT_F(MSG_MOVE_I), I_AXIS); }
  87. #endif
  88. #if HAS_J_AXIS
  89. void lcd_move_j() { _lcd_move_xyz(GET_TEXT_F(MSG_MOVE_J), J_AXIS); }
  90. #endif
  91. #if HAS_K_AXIS
  92. void lcd_move_k() { _lcd_move_xyz(GET_TEXT_F(MSG_MOVE_K), K_AXIS); }
  93. #endif
  94. #if HAS_U_AXIS
  95. void lcd_move_u() { _lcd_move_xyz(GET_TEXT_F(MSG_MOVE_U), U_AXIS); }
  96. #endif
  97. #if HAS_V_AXIS
  98. void lcd_move_v() { _lcd_move_xyz(GET_TEXT_F(MSG_MOVE_V), V_AXIS); }
  99. #endif
  100. #if HAS_W_AXIS
  101. void lcd_move_w() { _lcd_move_xyz(GET_TEXT_F(MSG_MOVE_W), W_AXIS); }
  102. #endif
  103. #if E_MANUAL
  104. static void lcd_move_e(TERN_(MULTI_E_MANUAL, const int8_t eindex=active_extruder)) {
  105. if (ui.use_click()) return ui.goto_previous_screen_no_defer();
  106. if (ui.encoderPosition) {
  107. if (!ui.manual_move.processing) {
  108. const float diff = float(int32_t(ui.encoderPosition)) * ui.manual_move.menu_scale;
  109. TERN(IS_KINEMATIC, ui.manual_move.offset, current_position.e) += diff;
  110. ui.manual_move.soon(E_AXIS OPTARG(MULTI_E_MANUAL, eindex));
  111. ui.refresh(LCDVIEW_REDRAW_NOW);
  112. }
  113. ui.encoderPosition = 0;
  114. }
  115. if (ui.should_draw()) {
  116. TERN_(MULTI_E_MANUAL, MenuItemBase::init(eindex));
  117. MenuEditItemBase::draw_edit_screen(
  118. GET_TEXT_F(TERN(MULTI_E_MANUAL, MSG_MOVE_EN, MSG_MOVE_E)),
  119. ftostr41sign(current_position.e
  120. PLUS_TERN0(IS_KINEMATIC, ui.manual_move.offset)
  121. MINUS_TERN0(MANUAL_E_MOVES_RELATIVE, manual_move_e_origin)
  122. )
  123. );
  124. } // should_draw
  125. }
  126. #endif // E_MANUAL
  127. #if EITHER(PROBE_OFFSET_WIZARD, X_AXIS_TWIST_COMPENSATION)
  128. void _goto_manual_move_z(const_float_t scale) {
  129. ui.manual_move.menu_scale = scale;
  130. ui.goto_screen(lcd_move_z);
  131. }
  132. #endif
  133. //
  134. // "Motion" > "Move Xmm" > "Move XYZ" submenu
  135. //
  136. #ifndef FINE_MANUAL_MOVE
  137. #define FINE_MANUAL_MOVE 0.025
  138. #endif
  139. screenFunc_t _manual_move_func_ptr;
  140. void _goto_manual_move(const_float_t scale) {
  141. ui.defer_status_screen();
  142. ui.manual_move.menu_scale = scale;
  143. ui.goto_screen(_manual_move_func_ptr);
  144. thermalManager.set_menu_cold_override(true);
  145. }
  146. void _menu_move_distance(const AxisEnum axis, const screenFunc_t func, const int8_t eindex=active_extruder) {
  147. _manual_move_func_ptr = func;
  148. START_MENU();
  149. if (LCD_HEIGHT >= 4) {
  150. switch (axis) {
  151. #define _CASE_MOVE(N) case N##_AXIS: STATIC_ITEM(MSG_MOVE_##N, SS_DEFAULT|SS_INVERT); break;
  152. MAIN_AXIS_MAP(_CASE_MOVE)
  153. default:
  154. TERN_(MANUAL_E_MOVES_RELATIVE, manual_move_e_origin = current_position.e);
  155. STATIC_ITEM(MSG_MOVE_E, SS_DEFAULT|SS_INVERT);
  156. break;
  157. }
  158. }
  159. BACK_ITEM(MSG_MOVE_AXIS);
  160. if (parser.using_inch_units()) {
  161. if (LARGE_AREA_TEST) SUBMENU(MSG_MOVE_1IN, []{ _goto_manual_move(IN_TO_MM(1.000f)); });
  162. SUBMENU(MSG_MOVE_01IN, []{ _goto_manual_move(IN_TO_MM(0.100f)); });
  163. SUBMENU(MSG_MOVE_001IN, []{ _goto_manual_move(IN_TO_MM(0.010f)); });
  164. SUBMENU(MSG_MOVE_0001IN, []{ _goto_manual_move(IN_TO_MM(0.001f)); });
  165. }
  166. else {
  167. if (LARGE_AREA_TEST) SUBMENU(MSG_MOVE_100MM, []{ _goto_manual_move(100); });
  168. SUBMENU(MSG_MOVE_10MM, []{ _goto_manual_move(10); });
  169. SUBMENU(MSG_MOVE_1MM, []{ _goto_manual_move( 1); });
  170. SUBMENU(MSG_MOVE_01MM, []{ _goto_manual_move( 0.1f); });
  171. if (axis == Z_AXIS && (FINE_MANUAL_MOVE) > 0.0f && (FINE_MANUAL_MOVE) < 0.1f)
  172. SUBMENU_f(F(STRINGIFY(FINE_MANUAL_MOVE)), MSG_MOVE_N_MM, []{ _goto_manual_move(float(FINE_MANUAL_MOVE)); });
  173. }
  174. END_MENU();
  175. }
  176. #if E_MANUAL
  177. inline void _goto_menu_move_distance_e() {
  178. ui.goto_screen([]{ _menu_move_distance(E_AXIS, []{ lcd_move_e(); }); });
  179. }
  180. inline void _menu_move_distance_e_maybe() {
  181. if (thermalManager.tooColdToExtrude(active_extruder)) {
  182. ui.goto_screen([]{
  183. MenuItem_confirm::select_screen(
  184. GET_TEXT_F(MSG_BUTTON_PROCEED), GET_TEXT_F(MSG_BACK),
  185. _goto_menu_move_distance_e, nullptr,
  186. GET_TEXT_F(MSG_HOTEND_TOO_COLD), (const char *)nullptr, F("!")
  187. );
  188. });
  189. }
  190. else
  191. _goto_menu_move_distance_e();
  192. }
  193. #endif
  194. void menu_move() {
  195. START_MENU();
  196. BACK_ITEM(MSG_MOTION);
  197. #if BOTH(HAS_SOFTWARE_ENDSTOPS, SOFT_ENDSTOPS_MENU_ITEM)
  198. EDIT_ITEM(bool, MSG_LCD_SOFT_ENDSTOPS, &soft_endstop._enabled);
  199. #endif
  200. if (NONE(IS_KINEMATIC, NO_MOTION_BEFORE_HOMING) || all_axes_homed()) {
  201. if (TERN1(DELTA, current_position.z <= delta_clip_start_height)) {
  202. SUBMENU(MSG_MOVE_X, []{ _menu_move_distance(X_AXIS, lcd_move_x); });
  203. #if HAS_Y_AXIS
  204. SUBMENU(MSG_MOVE_Y, []{ _menu_move_distance(Y_AXIS, lcd_move_y); });
  205. #endif
  206. }
  207. #if ENABLED(DELTA)
  208. else
  209. ACTION_ITEM(MSG_FREE_XY, []{ line_to_z(delta_clip_start_height); ui.synchronize(); });
  210. #endif
  211. #if HAS_Z_AXIS
  212. SUBMENU(MSG_MOVE_Z, []{ _menu_move_distance(Z_AXIS, lcd_move_z); });
  213. #endif
  214. #if HAS_I_AXIS
  215. SUBMENU(MSG_MOVE_I, []{ _menu_move_distance(I_AXIS, lcd_move_i); });
  216. #endif
  217. #if HAS_J_AXIS
  218. SUBMENU(MSG_MOVE_J, []{ _menu_move_distance(J_AXIS, lcd_move_j); });
  219. #endif
  220. #if HAS_K_AXIS
  221. SUBMENU(MSG_MOVE_K, []{ _menu_move_distance(K_AXIS, lcd_move_k); });
  222. #endif
  223. #if HAS_U_AXIS
  224. SUBMENU(MSG_MOVE_U, []{ _menu_move_distance(U_AXIS, lcd_move_u); });
  225. #endif
  226. #if HAS_V_AXIS
  227. SUBMENU(MSG_MOVE_V, []{ _menu_move_distance(V_AXIS, lcd_move_v); });
  228. #endif
  229. #if HAS_W_AXIS
  230. SUBMENU(MSG_MOVE_W, []{ _menu_move_distance(W_AXIS, lcd_move_w); });
  231. #endif
  232. }
  233. else
  234. GCODES_ITEM(MSG_AUTO_HOME, FPSTR(G28_STR));
  235. #if ANY(SWITCHING_EXTRUDER, SWITCHING_NOZZLE, MAGNETIC_SWITCHING_TOOLHEAD)
  236. #if EXTRUDERS >= 4
  237. switch (active_extruder) {
  238. case 0: GCODES_ITEM_N(1, MSG_SELECT_E, F("T1")); break;
  239. case 1: GCODES_ITEM_N(0, MSG_SELECT_E, F("T0")); break;
  240. case 2: GCODES_ITEM_N(3, MSG_SELECT_E, F("T3")); break;
  241. case 3: GCODES_ITEM_N(2, MSG_SELECT_E, F("T2")); break;
  242. #if EXTRUDERS == 6
  243. case 4: GCODES_ITEM_N(5, MSG_SELECT_E, F("T5")); break;
  244. case 5: GCODES_ITEM_N(4, MSG_SELECT_E, F("T4")); break;
  245. #endif
  246. }
  247. #elif EXTRUDERS == 3
  248. if (active_extruder < 2) {
  249. if (active_extruder)
  250. GCODES_ITEM_N(0, MSG_SELECT_E, F("T0"));
  251. else
  252. GCODES_ITEM_N(1, MSG_SELECT_E, F("T1"));
  253. }
  254. #else
  255. if (active_extruder)
  256. GCODES_ITEM_N(0, MSG_SELECT_E, F("T0"));
  257. else
  258. GCODES_ITEM_N(1, MSG_SELECT_E, F("T1"));
  259. #endif
  260. #elif ENABLED(DUAL_X_CARRIAGE)
  261. if (active_extruder)
  262. GCODES_ITEM_N(0, MSG_SELECT_E, F("T0"));
  263. else
  264. GCODES_ITEM_N(1, MSG_SELECT_E, F("T1"));
  265. #endif
  266. #if E_MANUAL
  267. // The current extruder
  268. SUBMENU(MSG_MOVE_E, []{ _menu_move_distance_e_maybe(); });
  269. #define SUBMENU_MOVE_E(N) SUBMENU_N(N, MSG_MOVE_EN, []{ _menu_move_distance(E_AXIS, []{ lcd_move_e(MenuItemBase::itemIndex); }, MenuItemBase::itemIndex); });
  270. #if EITHER(SWITCHING_EXTRUDER, SWITCHING_NOZZLE)
  271. // ...and the non-switching
  272. #if E_MANUAL == 7 || E_MANUAL == 5 || E_MANUAL == 3
  273. SUBMENU_MOVE_E(E_MANUAL - 1);
  274. #endif
  275. #elif MULTI_E_MANUAL
  276. // Independent extruders with one E stepper per hotend
  277. LOOP_L_N(n, E_MANUAL) SUBMENU_MOVE_E(n);
  278. #endif
  279. #endif // E_MANUAL
  280. END_MENU();
  281. }
  282. #if ENABLED(INDIVIDUAL_AXIS_HOMING_SUBMENU)
  283. //
  284. // "Motion" > "Homing" submenu
  285. //
  286. void menu_home() {
  287. START_MENU();
  288. BACK_ITEM(MSG_MOTION);
  289. GCODES_ITEM(MSG_AUTO_HOME, FPSTR(G28_STR));
  290. GCODES_ITEM_N(X_AXIS, MSG_AUTO_HOME_A, F("G28X"));
  291. #if HAS_Y_AXIS
  292. GCODES_ITEM_N(Y_AXIS, MSG_AUTO_HOME_A, F("G28Y"));
  293. #endif
  294. #if HAS_Z_AXIS
  295. GCODES_ITEM_N(Z_AXIS, MSG_AUTO_HOME_A, F("G28Z"));
  296. #endif
  297. #if HAS_I_AXIS
  298. GCODES_ITEM_N(I_AXIS, MSG_AUTO_HOME_A, F("G28" STR_I));
  299. #endif
  300. #if HAS_J_AXIS
  301. GCODES_ITEM_N(J_AXIS, MSG_AUTO_HOME_A, F("G28" STR_J));
  302. #endif
  303. #if HAS_K_AXIS
  304. GCODES_ITEM_N(K_AXIS, MSG_AUTO_HOME_A, F("G28" STR_K));
  305. #endif
  306. #if HAS_U_AXIS
  307. GCODES_ITEM_N(U_AXIS, MSG_AUTO_HOME_A, F("G28" STR_U));
  308. #endif
  309. #if HAS_V_AXIS
  310. GCODES_ITEM_N(V_AXIS, MSG_AUTO_HOME_A, F("G28" STR_V));
  311. #endif
  312. #if HAS_W_AXIS
  313. GCODES_ITEM_N(W_AXIS, MSG_AUTO_HOME_A, F("G28" STR_W));
  314. #endif
  315. END_MENU();
  316. }
  317. #endif
  318. #if ENABLED(AUTO_BED_LEVELING_UBL)
  319. void _lcd_ubl_level_bed();
  320. #elif ENABLED(LCD_BED_LEVELING)
  321. void menu_bed_leveling();
  322. #endif
  323. #if ENABLED(ASSISTED_TRAMMING_WIZARD)
  324. void goto_tramming_wizard();
  325. #endif
  326. void menu_motion() {
  327. START_MENU();
  328. //
  329. // ^ Main
  330. //
  331. BACK_ITEM(MSG_MAIN);
  332. //
  333. // Move Axis
  334. //
  335. if (TERN1(DELTA, all_axes_homed()))
  336. SUBMENU(MSG_MOVE_AXIS, menu_move);
  337. //
  338. // Auto Home
  339. //
  340. #if ENABLED(INDIVIDUAL_AXIS_HOMING_SUBMENU)
  341. SUBMENU(MSG_HOMING, menu_home);
  342. #else
  343. GCODES_ITEM(MSG_AUTO_HOME, FPSTR(G28_STR));
  344. #if ENABLED(INDIVIDUAL_AXIS_HOMING_MENU)
  345. GCODES_ITEM_N(X_AXIS, MSG_AUTO_HOME_A, F("G28X"));
  346. #if HAS_Y_AXIS
  347. GCODES_ITEM_N(Y_AXIS, MSG_AUTO_HOME_A, F("G28Y"));
  348. #endif
  349. #if HAS_Z_AXIS
  350. GCODES_ITEM_N(Z_AXIS, MSG_AUTO_HOME_A, F("G28Z"));
  351. #endif
  352. #if HAS_I_AXIS
  353. GCODES_ITEM_N(I_AXIS, MSG_AUTO_HOME_A, F("G28" STR_I));
  354. #endif
  355. #if HAS_J_AXIS
  356. GCODES_ITEM_N(J_AXIS, MSG_AUTO_HOME_A, F("G28" STR_J));
  357. #endif
  358. #if HAS_K_AXIS
  359. GCODES_ITEM_N(K_AXIS, MSG_AUTO_HOME_A, F("G28" STR_K));
  360. #endif
  361. #if HAS_U_AXIS
  362. GCODES_ITEM_N(U_AXIS, MSG_AUTO_HOME_A, F("G28" STR_U));
  363. #endif
  364. #if HAS_V_AXIS
  365. GCODES_ITEM_N(V_AXIS, MSG_AUTO_HOME_A, F("G28" STR_V));
  366. #endif
  367. #if HAS_W_AXIS
  368. GCODES_ITEM_N(W_AXIS, MSG_AUTO_HOME_A, F("G28" STR_W));
  369. #endif
  370. #endif
  371. #endif
  372. //
  373. // Auto-calibration
  374. //
  375. #if ENABLED(CALIBRATION_GCODE)
  376. GCODES_ITEM(MSG_AUTO_CALIBRATE, F("G425"));
  377. #endif
  378. //
  379. // Auto Z-Align
  380. //
  381. #if EITHER(Z_STEPPER_AUTO_ALIGN, MECHANICAL_GANTRY_CALIBRATION)
  382. GCODES_ITEM(MSG_AUTO_Z_ALIGN, F("G34"));
  383. #endif
  384. //
  385. // Assisted Bed Tramming
  386. //
  387. #if ENABLED(ASSISTED_TRAMMING_WIZARD)
  388. SUBMENU(MSG_TRAMMING_WIZARD, goto_tramming_wizard);
  389. #endif
  390. //
  391. // Level Bed
  392. //
  393. #if ENABLED(AUTO_BED_LEVELING_UBL)
  394. SUBMENU(MSG_UBL_LEVEL_BED, _lcd_ubl_level_bed);
  395. #elif ENABLED(LCD_BED_LEVELING)
  396. if (!g29_in_progress)
  397. SUBMENU(MSG_BED_LEVELING, menu_bed_leveling);
  398. #elif HAS_LEVELING && DISABLED(SLIM_LCD_MENUS)
  399. #if DISABLED(PROBE_MANUALLY)
  400. GCODES_ITEM(MSG_LEVEL_BED, F("G29N"));
  401. #endif
  402. if (all_axes_homed() && leveling_is_valid()) {
  403. bool show_state = planner.leveling_active;
  404. EDIT_ITEM(bool, MSG_BED_LEVELING, &show_state, _lcd_toggle_bed_leveling);
  405. }
  406. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  407. editable.decimal = planner.z_fade_height;
  408. EDIT_ITEM_FAST(float3, MSG_Z_FADE_HEIGHT, &editable.decimal, 0, 100, []{ set_z_fade_height(editable.decimal); });
  409. #endif
  410. #endif
  411. #if ENABLED(LCD_BED_TRAMMING) && DISABLED(LCD_BED_LEVELING)
  412. SUBMENU(MSG_BED_TRAMMING, _lcd_level_bed_corners);
  413. #endif
  414. #if ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST)
  415. GCODES_ITEM(MSG_M48_TEST, F("G28O\nM48 P10"));
  416. #endif
  417. //
  418. // Disable Steppers
  419. //
  420. GCODES_ITEM(MSG_DISABLE_STEPPERS, F("M84"));
  421. END_MENU();
  422. }
  423. #endif // HAS_MARLINUI_MENU