My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

G28.cpp 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  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. #include "../../inc/MarlinConfig.h"
  23. #include "../gcode.h"
  24. #include "../../module/stepper.h"
  25. #include "../../module/endstops.h"
  26. #if HAS_MULTI_HOTEND
  27. #include "../../module/tool_change.h"
  28. #endif
  29. #if HAS_LEVELING
  30. #include "../../feature/bedlevel/bedlevel.h"
  31. #endif
  32. #if ENABLED(SENSORLESS_HOMING)
  33. #include "../../feature/tmc_util.h"
  34. #endif
  35. #include "../../module/probe.h"
  36. #if ENABLED(BLTOUCH)
  37. #include "../../feature/bltouch.h"
  38. #endif
  39. #include "../../lcd/marlinui.h"
  40. #if ENABLED(EXTENSIBLE_UI)
  41. #include "../../lcd/extui/ui_api.h"
  42. #elif ENABLED(DWIN_CREALITY_LCD)
  43. #include "../../lcd/e3v2/creality/dwin.h"
  44. #elif ENABLED(DWIN_LCD_PROUI)
  45. #include "../../lcd/e3v2/proui/dwin.h"
  46. #endif
  47. #if ENABLED(LASER_FEATURE)
  48. #include "../../feature/spindle_laser.h"
  49. #endif
  50. #define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE)
  51. #include "../../core/debug_out.h"
  52. #if ENABLED(QUICK_HOME)
  53. static void quick_home_xy() {
  54. // Pretend the current position is 0,0
  55. current_position.set(0.0, 0.0);
  56. sync_plan_position();
  57. const int x_axis_home_dir = TOOL_X_HOME_DIR(active_extruder);
  58. // Use a higher diagonal feedrate so axes move at homing speed
  59. const float minfr = _MIN(homing_feedrate(X_AXIS), homing_feedrate(Y_AXIS)),
  60. fr_mm_s = HYPOT(minfr, minfr);
  61. #if ENABLED(SENSORLESS_HOMING)
  62. sensorless_t stealth_states {
  63. NUM_AXIS_LIST(
  64. TERN0(X_SENSORLESS, tmc_enable_stallguard(stepperX)),
  65. TERN0(Y_SENSORLESS, tmc_enable_stallguard(stepperY)),
  66. false, false, false, false
  67. )
  68. , TERN0(X2_SENSORLESS, tmc_enable_stallguard(stepperX2))
  69. , TERN0(Y2_SENSORLESS, tmc_enable_stallguard(stepperY2))
  70. };
  71. #endif
  72. do_blocking_move_to_xy(1.5 * max_length(X_AXIS) * x_axis_home_dir, 1.5 * max_length(Y_AXIS) * Y_HOME_DIR, fr_mm_s);
  73. endstops.validate_homing_move();
  74. current_position.set(0.0, 0.0);
  75. #if ENABLED(SENSORLESS_HOMING) && DISABLED(ENDSTOPS_ALWAYS_ON_DEFAULT)
  76. TERN_(X_SENSORLESS, tmc_disable_stallguard(stepperX, stealth_states.x));
  77. TERN_(X2_SENSORLESS, tmc_disable_stallguard(stepperX2, stealth_states.x2));
  78. TERN_(Y_SENSORLESS, tmc_disable_stallguard(stepperY, stealth_states.y));
  79. TERN_(Y2_SENSORLESS, tmc_disable_stallguard(stepperY2, stealth_states.y2));
  80. #endif
  81. }
  82. #endif // QUICK_HOME
  83. #if ENABLED(Z_SAFE_HOMING)
  84. inline void home_z_safely() {
  85. DEBUG_SECTION(log_G28, "home_z_safely", DEBUGGING(LEVELING));
  86. // Disallow Z homing if X or Y homing is needed
  87. if (homing_needed_error(_BV(X_AXIS) | _BV(Y_AXIS))) return;
  88. sync_plan_position();
  89. /**
  90. * Move the Z probe (or just the nozzle) to the safe homing point
  91. * (Z is already at the right height)
  92. */
  93. constexpr xy_float_t safe_homing_xy = { Z_SAFE_HOMING_X_POINT, Z_SAFE_HOMING_Y_POINT };
  94. #if HAS_HOME_OFFSET
  95. xy_float_t okay_homing_xy = safe_homing_xy;
  96. okay_homing_xy -= home_offset;
  97. #else
  98. constexpr xy_float_t okay_homing_xy = safe_homing_xy;
  99. #endif
  100. destination.set(okay_homing_xy, current_position.z);
  101. TERN_(HOMING_Z_WITH_PROBE, destination -= probe.offset_xy);
  102. if (position_is_reachable(destination)) {
  103. if (DEBUGGING(LEVELING)) DEBUG_POS("home_z_safely", destination);
  104. // Free the active extruder for movement
  105. TERN_(DUAL_X_CARRIAGE, idex_set_parked(false));
  106. TERN_(SENSORLESS_HOMING, safe_delay(500)); // Short delay needed to settle
  107. do_blocking_move_to_xy(destination);
  108. homeaxis(Z_AXIS);
  109. }
  110. else {
  111. LCD_MESSAGE(MSG_ZPROBE_OUT);
  112. SERIAL_ECHO_MSG(STR_ZPROBE_OUT_SER);
  113. }
  114. }
  115. #endif // Z_SAFE_HOMING
  116. #if ENABLED(IMPROVE_HOMING_RELIABILITY)
  117. motion_state_t begin_slow_homing() {
  118. motion_state_t motion_state{0};
  119. motion_state.acceleration.set(planner.settings.max_acceleration_mm_per_s2[X_AXIS],
  120. planner.settings.max_acceleration_mm_per_s2[Y_AXIS]
  121. OPTARG(DELTA, planner.settings.max_acceleration_mm_per_s2[Z_AXIS])
  122. );
  123. planner.settings.max_acceleration_mm_per_s2[X_AXIS] = 100;
  124. planner.settings.max_acceleration_mm_per_s2[Y_AXIS] = 100;
  125. TERN_(DELTA, planner.settings.max_acceleration_mm_per_s2[Z_AXIS] = 100);
  126. #if HAS_CLASSIC_JERK
  127. motion_state.jerk_state = planner.max_jerk;
  128. planner.max_jerk.set(0, 0 OPTARG(DELTA, 0));
  129. #endif
  130. planner.refresh_acceleration_rates();
  131. return motion_state;
  132. }
  133. void end_slow_homing(const motion_state_t &motion_state) {
  134. planner.settings.max_acceleration_mm_per_s2[X_AXIS] = motion_state.acceleration.x;
  135. planner.settings.max_acceleration_mm_per_s2[Y_AXIS] = motion_state.acceleration.y;
  136. TERN_(DELTA, planner.settings.max_acceleration_mm_per_s2[Z_AXIS] = motion_state.acceleration.z);
  137. TERN_(HAS_CLASSIC_JERK, planner.max_jerk = motion_state.jerk_state);
  138. planner.refresh_acceleration_rates();
  139. }
  140. #endif // IMPROVE_HOMING_RELIABILITY
  141. /**
  142. * G28: Home all axes according to settings
  143. *
  144. * Parameters
  145. *
  146. * None Home to all axes with no parameters.
  147. * With QUICK_HOME enabled XY will home together, then Z.
  148. *
  149. * L<bool> Force leveling state ON (if possible) or OFF after homing (Requires RESTORE_LEVELING_AFTER_G28 or ENABLE_LEVELING_AFTER_G28)
  150. * O Home only if the position is not known and trusted
  151. * R<linear> Raise by n mm/inches before homing
  152. *
  153. * Cartesian/SCARA parameters
  154. *
  155. * X Home to the X endstop
  156. * Y Home to the Y endstop
  157. * Z Home to the Z endstop
  158. */
  159. void GcodeSuite::G28() {
  160. DEBUG_SECTION(log_G28, "G28", DEBUGGING(LEVELING));
  161. if (DEBUGGING(LEVELING)) log_machine_info();
  162. /*
  163. * Set the laser power to false to stop the planner from processing the current power setting.
  164. */
  165. #if ENABLED(LASER_FEATURE)
  166. planner.laser_inline.status.isPowered = false;
  167. #endif
  168. #if ENABLED(DUAL_X_CARRIAGE)
  169. bool IDEX_saved_duplication_state = extruder_duplication_enabled;
  170. DualXMode IDEX_saved_mode = dual_x_carriage_mode;
  171. #endif
  172. #if ENABLED(MARLIN_DEV_MODE)
  173. if (parser.seen_test('S')) {
  174. LOOP_NUM_AXES(a) set_axis_is_at_home((AxisEnum)a);
  175. sync_plan_position();
  176. SERIAL_ECHOLNPGM("Simulated Homing");
  177. report_current_position();
  178. return;
  179. }
  180. #endif
  181. // Home (O)nly if position is unknown
  182. if (!axes_should_home() && parser.seen_test('O')) {
  183. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("> homing not needed, skip");
  184. return;
  185. }
  186. #if ENABLED(FULL_REPORT_TO_HOST_FEATURE)
  187. const M_StateEnum old_grblstate = M_State_grbl;
  188. set_and_report_grblstate(M_HOMING);
  189. #endif
  190. TERN_(HAS_DWIN_E3V2_BASIC, DWIN_HomingStart());
  191. TERN_(EXTENSIBLE_UI, ExtUI::onHomingStart());
  192. planner.synchronize(); // Wait for planner moves to finish!
  193. SET_SOFT_ENDSTOP_LOOSE(false); // Reset a leftover 'loose' motion state
  194. // Disable the leveling matrix before homing
  195. #if CAN_SET_LEVELING_AFTER_G28
  196. const bool leveling_restore_state = parser.boolval('L', TERN1(RESTORE_LEVELING_AFTER_G28, planner.leveling_active));
  197. #endif
  198. // Cancel any prior G29 session
  199. TERN_(PROBE_MANUALLY, g29_in_progress = false);
  200. // Disable leveling before homing
  201. TERN_(HAS_LEVELING, set_bed_leveling_enabled(false));
  202. // Reset to the XY plane
  203. TERN_(CNC_WORKSPACE_PLANES, workspace_plane = PLANE_XY);
  204. // Count this command as movement / activity
  205. reset_stepper_timeout();
  206. #define HAS_CURRENT_HOME(N) (defined(N##_CURRENT_HOME) && N##_CURRENT_HOME != N##_CURRENT)
  207. #if HAS_CURRENT_HOME(X) || HAS_CURRENT_HOME(X2) || HAS_CURRENT_HOME(Y) || HAS_CURRENT_HOME(Y2) || (ENABLED(DELTA) && HAS_CURRENT_HOME(Z)) || HAS_CURRENT_HOME(I) || HAS_CURRENT_HOME(J) || HAS_CURRENT_HOME(K) || HAS_CURRENT_HOME(U) || HAS_CURRENT_HOME(V) || HAS_CURRENT_HOME(W)
  208. #define HAS_HOMING_CURRENT 1
  209. #endif
  210. #if HAS_HOMING_CURRENT
  211. auto debug_current = [](FSTR_P const s, const int16_t a, const int16_t b) {
  212. DEBUG_ECHOF(s); DEBUG_ECHOLNPGM(" current: ", a, " -> ", b);
  213. };
  214. #if HAS_CURRENT_HOME(X)
  215. const int16_t tmc_save_current_X = stepperX.getMilliamps();
  216. stepperX.rms_current(X_CURRENT_HOME);
  217. if (DEBUGGING(LEVELING)) debug_current(F(STR_X), tmc_save_current_X, X_CURRENT_HOME);
  218. #endif
  219. #if HAS_CURRENT_HOME(X2)
  220. const int16_t tmc_save_current_X2 = stepperX2.getMilliamps();
  221. stepperX2.rms_current(X2_CURRENT_HOME);
  222. if (DEBUGGING(LEVELING)) debug_current(F(STR_X2), tmc_save_current_X2, X2_CURRENT_HOME);
  223. #endif
  224. #if HAS_CURRENT_HOME(Y)
  225. const int16_t tmc_save_current_Y = stepperY.getMilliamps();
  226. stepperY.rms_current(Y_CURRENT_HOME);
  227. if (DEBUGGING(LEVELING)) debug_current(F(STR_Y), tmc_save_current_Y, Y_CURRENT_HOME);
  228. #endif
  229. #if HAS_CURRENT_HOME(Y2)
  230. const int16_t tmc_save_current_Y2 = stepperY2.getMilliamps();
  231. stepperY2.rms_current(Y2_CURRENT_HOME);
  232. if (DEBUGGING(LEVELING)) debug_current(F(STR_Y2), tmc_save_current_Y2, Y2_CURRENT_HOME);
  233. #endif
  234. #if HAS_CURRENT_HOME(Z) && ENABLED(DELTA)
  235. const int16_t tmc_save_current_Z = stepperZ.getMilliamps();
  236. stepperZ.rms_current(Z_CURRENT_HOME);
  237. if (DEBUGGING(LEVELING)) debug_current(F(STR_Z), tmc_save_current_Z, Z_CURRENT_HOME);
  238. #endif
  239. #if HAS_CURRENT_HOME(I)
  240. const int16_t tmc_save_current_I = stepperI.getMilliamps();
  241. stepperI.rms_current(I_CURRENT_HOME);
  242. if (DEBUGGING(LEVELING)) debug_current(F(STR_I), tmc_save_current_I, I_CURRENT_HOME);
  243. #endif
  244. #if HAS_CURRENT_HOME(J)
  245. const int16_t tmc_save_current_J = stepperJ.getMilliamps();
  246. stepperJ.rms_current(J_CURRENT_HOME);
  247. if (DEBUGGING(LEVELING)) debug_current(F(STR_J), tmc_save_current_J, J_CURRENT_HOME);
  248. #endif
  249. #if HAS_CURRENT_HOME(K)
  250. const int16_t tmc_save_current_K = stepperK.getMilliamps();
  251. stepperK.rms_current(K_CURRENT_HOME);
  252. if (DEBUGGING(LEVELING)) debug_current(F(STR_K), tmc_save_current_K, K_CURRENT_HOME);
  253. #endif
  254. #if HAS_CURRENT_HOME(U)
  255. const int16_t tmc_save_current_U = stepperU.getMilliamps();
  256. stepperU.rms_current(U_CURRENT_HOME);
  257. if (DEBUGGING(LEVELING)) debug_current(F(STR_U), tmc_save_current_U, U_CURRENT_HOME);
  258. #endif
  259. #if HAS_CURRENT_HOME(V)
  260. const int16_t tmc_save_current_V = stepperV.getMilliamps();
  261. stepperV.rms_current(V_CURRENT_HOME);
  262. if (DEBUGGING(LEVELING)) debug_current(F(STR_V), tmc_save_current_V, V_CURRENT_HOME);
  263. #endif
  264. #if HAS_CURRENT_HOME(W)
  265. const int16_t tmc_save_current_W = stepperW.getMilliamps();
  266. stepperW.rms_current(W_CURRENT_HOME);
  267. if (DEBUGGING(LEVELING)) debug_current(F(STR_W), tmc_save_current_W, W_CURRENT_HOME);
  268. #endif
  269. #if SENSORLESS_STALLGUARD_DELAY
  270. safe_delay(SENSORLESS_STALLGUARD_DELAY); // Short delay needed to settle
  271. #endif
  272. #endif
  273. #if ENABLED(IMPROVE_HOMING_RELIABILITY)
  274. motion_state_t saved_motion_state = begin_slow_homing();
  275. #endif
  276. // Always home with tool 0 active
  277. #if HAS_MULTI_HOTEND
  278. #if DISABLED(DELTA) || ENABLED(DELTA_HOME_TO_SAFE_ZONE)
  279. const uint8_t old_tool_index = active_extruder;
  280. #endif
  281. // PARKING_EXTRUDER homing requires different handling of movement / solenoid activation, depending on the side of homing
  282. #if ENABLED(PARKING_EXTRUDER)
  283. const bool pe_final_change_must_unpark = parking_extruder_unpark_after_homing(old_tool_index, X_HOME_DIR + 1 == old_tool_index * 2);
  284. #endif
  285. tool_change(0, true);
  286. #endif
  287. TERN_(HAS_DUPLICATION_MODE, set_duplication_enabled(false));
  288. remember_feedrate_scaling_off();
  289. endstops.enable(true); // Enable endstops for next homing move
  290. #if ENABLED(DELTA)
  291. constexpr bool doZ = true; // for NANODLP_Z_SYNC if your DLP is on a DELTA
  292. home_delta();
  293. TERN_(IMPROVE_HOMING_RELIABILITY, end_slow_homing(saved_motion_state));
  294. #elif ENABLED(AXEL_TPARA)
  295. constexpr bool doZ = true; // for NANODLP_Z_SYNC if your DLP is on a TPARA
  296. home_TPARA();
  297. #else
  298. #define _UNSAFE(A) (homeZ && TERN0(Z_SAFE_HOMING, axes_should_home(_BV(A##_AXIS))))
  299. const bool homeZ = TERN0(HAS_Z_AXIS, parser.seen_test('Z')),
  300. NUM_AXIS_LIST( // Other axes should be homed before Z safe-homing
  301. needX = _UNSAFE(X), needY = _UNSAFE(Y), needZ = false, // UNUSED
  302. needI = _UNSAFE(I), needJ = _UNSAFE(J), needK = _UNSAFE(K),
  303. needU = _UNSAFE(U), needV = _UNSAFE(V), needW = _UNSAFE(W)
  304. ),
  305. NUM_AXIS_LIST( // Home each axis if needed or flagged
  306. homeX = needX || parser.seen_test('X'),
  307. homeY = needY || parser.seen_test('Y'),
  308. homeZZ = homeZ,
  309. homeI = needI || parser.seen_test(AXIS4_NAME), homeJ = needJ || parser.seen_test(AXIS5_NAME),
  310. homeK = needK || parser.seen_test(AXIS6_NAME), homeU = needU || parser.seen_test(AXIS7_NAME),
  311. homeV = needV || parser.seen_test(AXIS8_NAME), homeW = needW || parser.seen_test(AXIS9_NAME)
  312. ),
  313. home_all = NUM_AXIS_GANG( // Home-all if all or none are flagged
  314. homeX == homeX, && homeY == homeX, && homeZ == homeX,
  315. && homeI == homeX, && homeJ == homeX, && homeK == homeX,
  316. && homeU == homeX, && homeV == homeX, && homeW == homeX
  317. ),
  318. NUM_AXIS_LIST(
  319. doX = home_all || homeX, doY = home_all || homeY, doZ = home_all || homeZ,
  320. doI = home_all || homeI, doJ = home_all || homeJ, doK = home_all || homeK,
  321. doU = home_all || homeU, doV = home_all || homeV, doW = home_all || homeW
  322. );
  323. #if HAS_Z_AXIS
  324. UNUSED(needZ); UNUSED(homeZZ);
  325. #else
  326. constexpr bool doZ = false;
  327. #endif
  328. TERN_(HOME_Z_FIRST, if (doZ) homeaxis(Z_AXIS));
  329. const bool seenR = parser.seenval('R');
  330. const float z_homing_height = seenR ? parser.value_linear_units() : Z_HOMING_HEIGHT;
  331. if (z_homing_height && (seenR || NUM_AXIS_GANG(doX, || doY, || TERN0(Z_SAFE_HOMING, doZ), || doI, || doJ, || doK, || doU, || doV, || doW))) {
  332. // Raise Z before homing any other axes and z is not already high enough (never lower z)
  333. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Raise Z (before homing) by ", z_homing_height);
  334. do_z_clearance(z_homing_height);
  335. TERN_(BLTOUCH, bltouch.init());
  336. }
  337. // Diagonal move first if both are homing
  338. TERN_(QUICK_HOME, if (doX && doY) quick_home_xy());
  339. // Home Y (before X)
  340. if (ENABLED(HOME_Y_BEFORE_X) && (doY || TERN0(CODEPENDENT_XY_HOMING, doX)))
  341. homeaxis(Y_AXIS);
  342. // Home X
  343. if (doX || (doY && ENABLED(CODEPENDENT_XY_HOMING) && DISABLED(HOME_Y_BEFORE_X))) {
  344. #if ENABLED(DUAL_X_CARRIAGE)
  345. // Always home the 2nd (right) extruder first
  346. active_extruder = 1;
  347. homeaxis(X_AXIS);
  348. // Remember this extruder's position for later tool change
  349. inactive_extruder_x = current_position.x;
  350. // Home the 1st (left) extruder
  351. active_extruder = 0;
  352. homeaxis(X_AXIS);
  353. // Consider the active extruder to be in its "parked" position
  354. idex_set_parked();
  355. #else
  356. homeaxis(X_AXIS);
  357. #endif
  358. }
  359. #if BOTH(FOAMCUTTER_XYUV, HAS_I_AXIS)
  360. // Home I (after X)
  361. if (doI) homeaxis(I_AXIS);
  362. #endif
  363. // Home Y (after X)
  364. if (DISABLED(HOME_Y_BEFORE_X) && doY)
  365. homeaxis(Y_AXIS);
  366. #if BOTH(FOAMCUTTER_XYUV, HAS_J_AXIS)
  367. // Home J (after Y)
  368. if (doJ) homeaxis(J_AXIS);
  369. #endif
  370. TERN_(IMPROVE_HOMING_RELIABILITY, end_slow_homing(saved_motion_state));
  371. #if ENABLED(FOAMCUTTER_XYUV)
  372. // skip homing of unused Z axis for foamcutters
  373. if (doZ) set_axis_is_at_home(Z_AXIS);
  374. #else
  375. // Home Z last if homing towards the bed
  376. #if HAS_Z_AXIS && DISABLED(HOME_Z_FIRST)
  377. if (doZ) {
  378. #if EITHER(Z_MULTI_ENDSTOPS, Z_STEPPER_AUTO_ALIGN)
  379. stepper.set_all_z_lock(false);
  380. stepper.set_separate_multi_axis(false);
  381. #endif
  382. #if ENABLED(Z_SAFE_HOMING)
  383. if (TERN1(POWER_LOSS_RECOVERY, !parser.seen_test('H'))) home_z_safely(); else homeaxis(Z_AXIS);
  384. #else
  385. homeaxis(Z_AXIS);
  386. #endif
  387. probe.move_z_after_homing();
  388. }
  389. #endif
  390. SECONDARY_AXIS_CODE(
  391. if (doI) homeaxis(I_AXIS),
  392. if (doJ) homeaxis(J_AXIS),
  393. if (doK) homeaxis(K_AXIS),
  394. if (doU) homeaxis(U_AXIS),
  395. if (doV) homeaxis(V_AXIS),
  396. if (doW) homeaxis(W_AXIS)
  397. );
  398. #endif
  399. sync_plan_position();
  400. #endif
  401. /**
  402. * Preserve DXC mode across a G28 for IDEX printers in DXC_DUPLICATION_MODE.
  403. * This is important because it lets a user use the LCD Panel to set an IDEX Duplication mode, and
  404. * then print a standard GCode file that contains a single print that does a G28 and has no other
  405. * IDEX specific commands in it.
  406. */
  407. #if ENABLED(DUAL_X_CARRIAGE)
  408. if (idex_is_duplicating()) {
  409. TERN_(IMPROVE_HOMING_RELIABILITY, saved_motion_state = begin_slow_homing());
  410. // Always home the 2nd (right) extruder first
  411. active_extruder = 1;
  412. homeaxis(X_AXIS);
  413. // Remember this extruder's position for later tool change
  414. inactive_extruder_x = current_position.x;
  415. // Home the 1st (left) extruder
  416. active_extruder = 0;
  417. homeaxis(X_AXIS);
  418. // Consider the active extruder to be parked
  419. idex_set_parked();
  420. dual_x_carriage_mode = IDEX_saved_mode;
  421. set_duplication_enabled(IDEX_saved_duplication_state);
  422. TERN_(IMPROVE_HOMING_RELIABILITY, end_slow_homing(saved_motion_state));
  423. }
  424. #endif // DUAL_X_CARRIAGE
  425. endstops.not_homing();
  426. // Clear endstop state for polled stallGuard endstops
  427. TERN_(SPI_ENDSTOPS, endstops.clear_endstop_state());
  428. // Move to a height where we can use the full xy-area
  429. TERN_(DELTA_HOME_TO_SAFE_ZONE, do_blocking_move_to_z(delta_clip_start_height));
  430. TERN_(CAN_SET_LEVELING_AFTER_G28, if (leveling_restore_state) set_bed_leveling_enabled());
  431. restore_feedrate_and_scaling();
  432. // Restore the active tool after homing
  433. #if HAS_MULTI_HOTEND && (DISABLED(DELTA) || ENABLED(DELTA_HOME_TO_SAFE_ZONE))
  434. tool_change(old_tool_index, TERN(PARKING_EXTRUDER, !pe_final_change_must_unpark, DISABLED(DUAL_X_CARRIAGE))); // Do move if one of these
  435. #endif
  436. #if HAS_HOMING_CURRENT
  437. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Restore driver current...");
  438. #if HAS_CURRENT_HOME(X)
  439. stepperX.rms_current(tmc_save_current_X);
  440. #endif
  441. #if HAS_CURRENT_HOME(X2)
  442. stepperX2.rms_current(tmc_save_current_X2);
  443. #endif
  444. #if HAS_CURRENT_HOME(Y)
  445. stepperY.rms_current(tmc_save_current_Y);
  446. #endif
  447. #if HAS_CURRENT_HOME(Y2)
  448. stepperY2.rms_current(tmc_save_current_Y2);
  449. #endif
  450. #if HAS_CURRENT_HOME(Z) && ENABLED(DELTA)
  451. stepperZ.rms_current(tmc_save_current_Z);
  452. #endif
  453. #if HAS_CURRENT_HOME(I)
  454. stepperI.rms_current(tmc_save_current_I);
  455. #endif
  456. #if HAS_CURRENT_HOME(J)
  457. stepperJ.rms_current(tmc_save_current_J);
  458. #endif
  459. #if HAS_CURRENT_HOME(K)
  460. stepperK.rms_current(tmc_save_current_K);
  461. #endif
  462. #if HAS_CURRENT_HOME(U)
  463. stepperU.rms_current(tmc_save_current_U);
  464. #endif
  465. #if HAS_CURRENT_HOME(V)
  466. stepperV.rms_current(tmc_save_current_V);
  467. #endif
  468. #if HAS_CURRENT_HOME(W)
  469. stepperW.rms_current(tmc_save_current_W);
  470. #endif
  471. #if SENSORLESS_STALLGUARD_DELAY
  472. safe_delay(SENSORLESS_STALLGUARD_DELAY); // Short delay needed to settle
  473. #endif
  474. #endif // HAS_HOMING_CURRENT
  475. ui.refresh();
  476. TERN_(HAS_DWIN_E3V2_BASIC, DWIN_HomingDone());
  477. TERN_(EXTENSIBLE_UI, ExtUI::onHomingDone());
  478. report_current_position();
  479. if (ENABLED(NANODLP_Z_SYNC) && (doZ || ENABLED(NANODLP_ALL_AXIS)))
  480. SERIAL_ECHOLNPGM(STR_Z_MOVE_COMP);
  481. TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(old_grblstate));
  482. }