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.

tool_change.cpp 37KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2019 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 <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "../inc/MarlinConfigPre.h"
  23. #include "tool_change.h"
  24. #include "probe.h"
  25. #include "motion.h"
  26. #include "planner.h"
  27. #include "temperature.h"
  28. #include "../Marlin.h"
  29. #define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE)
  30. #include "../core/debug_out.h"
  31. #if EXTRUDERS > 1
  32. toolchange_settings_t toolchange_settings; // Initialized by settings.load()
  33. #endif
  34. #if ENABLED(SINGLENOZZLE)
  35. uint16_t singlenozzle_temp[EXTRUDERS];
  36. #if FAN_COUNT > 0
  37. uint8_t singlenozzle_fan_speed[EXTRUDERS];
  38. #endif
  39. #endif
  40. #if ENABLED(MAGNETIC_PARKING_EXTRUDER) || (ENABLED(PARKING_EXTRUDER) && PARKING_EXTRUDER_SOLENOIDS_DELAY > 0)
  41. #include "../gcode/gcode.h" // for dwell()
  42. #endif
  43. #if ANY(SWITCHING_EXTRUDER, SWITCHING_NOZZLE, SWITCHING_TOOLHEAD)
  44. #include "servo.h"
  45. #endif
  46. #if ENABLED(EXT_SOLENOID) && DISABLED(PARKING_EXTRUDER)
  47. #include "../feature/solenoid.h"
  48. #endif
  49. #if ENABLED(MK2_MULTIPLEXER)
  50. #include "../feature/snmm.h"
  51. #endif
  52. #if ENABLED(MIXING_EXTRUDER)
  53. #include "../feature/mixing.h"
  54. #endif
  55. #if HAS_LEVELING
  56. #include "../feature/bedlevel/bedlevel.h"
  57. #endif
  58. #if HAS_FANMUX
  59. #include "../feature/fanmux.h"
  60. #endif
  61. #if ENABLED(PRUSA_MMU2)
  62. #include "../feature/prusa_MMU2/mmu2.h"
  63. #endif
  64. #if HAS_LCD_MENU
  65. #include "../lcd/ultralcd.h"
  66. #endif
  67. #if DO_SWITCH_EXTRUDER
  68. #if EXTRUDERS > 3
  69. #define _SERVO_NR(E) ((E) < 2 ? SWITCHING_EXTRUDER_SERVO_NR : SWITCHING_EXTRUDER_E23_SERVO_NR)
  70. #else
  71. #define _SERVO_NR(E) SWITCHING_EXTRUDER_SERVO_NR
  72. #endif
  73. void move_extruder_servo(const uint8_t e) {
  74. planner.synchronize();
  75. #if EXTRUDERS & 1
  76. if (e < EXTRUDERS - 1)
  77. #endif
  78. {
  79. MOVE_SERVO(_SERVO_NR(e), servo_angles[_SERVO_NR(e)][e]);
  80. safe_delay(500);
  81. }
  82. }
  83. #endif // DO_SWITCH_EXTRUDER
  84. #if ENABLED(SWITCHING_NOZZLE)
  85. #if SWITCHING_NOZZLE_TWO_SERVOS
  86. inline void _move_nozzle_servo(const uint8_t e, const uint8_t angle_index) {
  87. constexpr int8_t sns_index[2] = { SWITCHING_NOZZLE_SERVO_NR, SWITCHING_NOZZLE_E1_SERVO_NR };
  88. constexpr int16_t sns_angles[2] = SWITCHING_NOZZLE_SERVO_ANGLES;
  89. planner.synchronize();
  90. MOVE_SERVO(sns_index[e], sns_angles[angle_index]);
  91. safe_delay(500);
  92. }
  93. void lower_nozzle(const uint8_t e) { _move_nozzle_servo(e, 0); }
  94. void raise_nozzle(const uint8_t e) { _move_nozzle_servo(e, 1); }
  95. #else
  96. void move_nozzle_servo(const uint8_t angle_index) {
  97. planner.synchronize();
  98. MOVE_SERVO(SWITCHING_NOZZLE_SERVO_NR, servo_angles[SWITCHING_NOZZLE_SERVO_NR][angle_index]);
  99. safe_delay(500);
  100. }
  101. #endif
  102. #endif // SWITCHING_NOZZLE
  103. inline void fast_line_to_current(const AxisEnum fr_axis) {
  104. planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[fr_axis], active_extruder);
  105. }
  106. #if ENABLED(MAGNETIC_PARKING_EXTRUDER)
  107. float parkingposx[2] , // M951 R L
  108. parkinggrabdistance , // M951 I
  109. parkingslowspeed, // M951 J
  110. parkinghighspeed , // M951 H
  111. parkingtraveldistance, // M951 D
  112. compensationmultiplier;
  113. inline void magnetic_parking_extruder_tool_change(const uint8_t tmp_extruder) {
  114. const float oldx = current_position[X_AXIS],
  115. grabpos = mpe_settings.parking_xpos[tmp_extruder] + (tmp_extruder ? mpe_settings.grab_distance : -mpe_settings.grab_distance),
  116. offsetcompensation =
  117. #if HAS_HOTEND_OFFSET
  118. hotend_offset[X_AXIS][active_extruder] * mpe_settings.compensation_factor
  119. #else
  120. 0
  121. #endif
  122. ;
  123. if (axis_unhomed_error(true, false, false)) return;
  124. /**
  125. * Z Lift and Nozzle Offset shift ar defined in caller method to work equal with any Multi Hotend realization
  126. *
  127. * Steps:
  128. * 1. Move high speed to park position of new extruder
  129. * 2. Move to couple position of new extruder (this also discouple the old extruder)
  130. * 3. Move to park position of new extruder
  131. * 4. Move high speed to approach park position of old extruder
  132. * 5. Move to park position of old extruder
  133. * 6. Move to starting position
  134. */
  135. // STEP 1
  136. current_position[X_AXIS] = mpe_settings.parking_xpos[tmp_extruder] + offsetcompensation;
  137. if (DEBUGGING(LEVELING)) {
  138. DEBUG_ECHOPAIR("(1) Move extruder ", int(tmp_extruder));
  139. DEBUG_POS(" to new extruder ParkPos", current_position);
  140. }
  141. planner.buffer_line(current_position, mpe_settings.fast_feedrate, tmp_extruder);
  142. planner.synchronize();
  143. // STEP 2
  144. current_position[X_AXIS] = grabpos + offsetcompensation;
  145. if (DEBUGGING(LEVELING)) {
  146. DEBUG_ECHOPAIR("(2) Couple extruder ", int(tmp_extruder));
  147. DEBUG_POS(" to new extruder GrabPos", current_position);
  148. }
  149. planner.buffer_line(current_position, mpe_settings.slow_feedrate, tmp_extruder);
  150. planner.synchronize();
  151. // Delay before moving tool, to allow magnetic coupling
  152. gcode.dwell(150);
  153. // STEP 3
  154. current_position[X_AXIS] = mpe_settings.parking_xpos[tmp_extruder] + offsetcompensation;
  155. if (DEBUGGING(LEVELING)) {
  156. DEBUG_ECHOPAIR("(3) Move extruder ", int(tmp_extruder));
  157. DEBUG_POS(" back to new extruder ParkPos", current_position);
  158. }
  159. planner.buffer_line(current_position, mpe_settings.slow_feedrate, tmp_extruder);
  160. planner.synchronize();
  161. // STEP 4
  162. current_position[X_AXIS] = mpe_settings.parking_xpos[active_extruder] + (active_extruder == 0 ? MPE_TRAVEL_DISTANCE : -MPE_TRAVEL_DISTANCE) + offsetcompensation;
  163. if (DEBUGGING(LEVELING)) {
  164. DEBUG_ECHOPAIR("(4) Move extruder ", int(tmp_extruder));
  165. DEBUG_POS(" close to old extruder ParkPos", current_position);
  166. }
  167. planner.buffer_line(current_position, mpe_settings.fast_feedrate, tmp_extruder);
  168. planner.synchronize();
  169. // STEP 5
  170. current_position[X_AXIS] = mpe_settings.parking_xpos[active_extruder] + offsetcompensation;
  171. if (DEBUGGING(LEVELING)) {
  172. DEBUG_ECHOPAIR("(5) Park extruder ", int(tmp_extruder));
  173. DEBUG_POS(" at old extruder ParkPos", current_position);
  174. }
  175. planner.buffer_line(current_position, mpe_settings.slow_feedrate, tmp_extruder);
  176. planner.synchronize();
  177. // STEP 6
  178. current_position[X_AXIS] = oldx;
  179. if (DEBUGGING(LEVELING)) {
  180. DEBUG_ECHOPAIR("(6) Move extruder ", int(tmp_extruder));
  181. DEBUG_POS(" to starting position", current_position);
  182. }
  183. planner.buffer_line(current_position, mpe_settings.fast_feedrate, tmp_extruder);
  184. planner.synchronize();
  185. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Autopark done.");
  186. }
  187. #elif ENABLED(PARKING_EXTRUDER)
  188. void pe_solenoid_init() {
  189. for (uint8_t n = 0; n <= 1; ++n)
  190. #if ENABLED(PARKING_EXTRUDER_SOLENOIDS_INVERT)
  191. pe_activate_solenoid(n);
  192. #else
  193. pe_deactivate_solenoid(n);
  194. #endif
  195. }
  196. void pe_set_solenoid(const uint8_t extruder_num, const uint8_t state) {
  197. switch (extruder_num) {
  198. case 1: OUT_WRITE(SOL1_PIN, state); break;
  199. default: OUT_WRITE(SOL0_PIN, state); break;
  200. }
  201. #if PARKING_EXTRUDER_SOLENOIDS_DELAY > 0
  202. gcode.dwell(PARKING_EXTRUDER_SOLENOIDS_DELAY);
  203. #endif
  204. }
  205. inline void parking_extruder_tool_change(const uint8_t tmp_extruder, bool no_move) {
  206. if (!no_move) {
  207. constexpr float parkingposx[] = PARKING_EXTRUDER_PARKING_X;
  208. #if HAS_HOTEND_OFFSET
  209. const float x_offset = hotend_offset[X_AXIS][active_extruder];
  210. #else
  211. constexpr float x_offset = 0;
  212. #endif
  213. const float midpos = (parkingposx[0] + parkingposx[1]) * 0.5 + x_offset,
  214. grabpos = parkingposx[tmp_extruder] + (tmp_extruder ? PARKING_EXTRUDER_GRAB_DISTANCE : -(PARKING_EXTRUDER_GRAB_DISTANCE)) + x_offset;
  215. /**
  216. * 1. Move to park position of old extruder
  217. * 2. Disengage magnetic field, wait for delay
  218. * 3. Move near new extruder
  219. * 4. Engage magnetic field for new extruder
  220. * 5. Move to parking incl. offset of new extruder
  221. * 6. Lower Z-Axis
  222. */
  223. // STEP 1
  224. if (DEBUGGING(LEVELING)) DEBUG_POS("Start Autopark", current_position);
  225. current_position[X_AXIS] = parkingposx[active_extruder] + x_offset;
  226. if (DEBUGGING(LEVELING)) {
  227. DEBUG_ECHOLNPAIR("(1) Park extruder ", int(active_extruder));
  228. DEBUG_POS("Moving ParkPos", current_position);
  229. }
  230. fast_line_to_current(X_AXIS);
  231. planner.synchronize();
  232. // STEP 2
  233. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("(2) Disengage magnet ");
  234. pe_deactivate_solenoid(active_extruder);
  235. // STEP 3
  236. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("(3) Move near new extruder");
  237. current_position[X_AXIS] += active_extruder ? -10 : 10; // move 10mm away from parked extruder
  238. if (DEBUGGING(LEVELING)) DEBUG_POS("Move away from parked extruder", current_position);
  239. fast_line_to_current(X_AXIS);
  240. planner.synchronize();
  241. // STEP 4
  242. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("(4) Engage magnetic field");
  243. #if ENABLED(PARKING_EXTRUDER_SOLENOIDS_INVERT)
  244. pe_activate_solenoid(active_extruder); //just save power for inverted magnets
  245. #endif
  246. pe_activate_solenoid(tmp_extruder);
  247. // STEP 5
  248. current_position[X_AXIS] = grabpos + (tmp_extruder ? -10 : 10);
  249. fast_line_to_current(X_AXIS);
  250. current_position[X_AXIS] = grabpos;
  251. if (DEBUGGING(LEVELING)) DEBUG_POS("(5) Unpark extruder", current_position);
  252. planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[X_AXIS] * 0.5, active_extruder);
  253. planner.synchronize();
  254. // STEP 6
  255. current_position[X_AXIS] = midpos
  256. #if HAS_HOTEND_OFFSET
  257. - hotend_offset[X_AXIS][tmp_extruder]
  258. #endif
  259. ;
  260. if (DEBUGGING(LEVELING)) DEBUG_POS("(6) Move midway between hotends", current_position);
  261. fast_line_to_current(X_AXIS);
  262. planner.synchronize();
  263. DEBUG_ECHOLNPGM("Autopark done.");
  264. }
  265. else { // nomove == true
  266. // Only engage magnetic field for new extruder
  267. pe_activate_solenoid(tmp_extruder);
  268. #if ENABLED(PARKING_EXTRUDER_SOLENOIDS_INVERT)
  269. pe_activate_solenoid(active_extruder); // Just save power for inverted magnets
  270. #endif
  271. }
  272. }
  273. #endif // PARKING_EXTRUDER
  274. #if ENABLED(SWITCHING_TOOLHEAD)
  275. inline void switching_toolhead_tool_change(const uint8_t tmp_extruder, bool no_move/*=false*/) {
  276. if (no_move) return;
  277. constexpr uint16_t angles[2] = SWITCHING_TOOLHEAD_SERVO_ANGLES;
  278. constexpr float toolheadposx[] = SWITCHING_TOOLHEAD_X_POS;
  279. const float placexpos = toolheadposx[active_extruder],
  280. grabxpos = toolheadposx[tmp_extruder];
  281. /**
  282. * 1. Move to switch position of current toolhead
  283. * 2. Unlock tool and drop it in the dock
  284. * 3. Move to the new toolhead
  285. * 4. Grab and lock the new toolhead
  286. */
  287. // 1. Move to switch position of current toolhead
  288. if (DEBUGGING(LEVELING)) DEBUG_POS("Starting Toolhead change", current_position);
  289. current_position[X_AXIS] = placexpos;
  290. if (DEBUGGING(LEVELING)) {
  291. DEBUG_ECHOLNPAIR("(1) Place old tool ", int(active_extruder));
  292. DEBUG_POS("Move X SwitchPos", current_position);
  293. }
  294. fast_line_to_current(X_AXIS);
  295. planner.synchronize();
  296. current_position[Y_AXIS] = SWITCHING_TOOLHEAD_Y_POS - SWITCHING_TOOLHEAD_Y_SECURITY;
  297. if (DEBUGGING(LEVELING)) DEBUG_POS("Move Y SwitchPos + Security", current_position);
  298. fast_line_to_current(Y_AXIS);
  299. planner.synchronize();
  300. // 2. Unlock tool and drop it in the dock
  301. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("(2) Unlock and Place Toolhead");
  302. MOVE_SERVO(SWITCHING_TOOLHEAD_SERVO_NR, angles[1]);
  303. safe_delay(500);
  304. current_position[Y_AXIS] = SWITCHING_TOOLHEAD_Y_POS;
  305. if (DEBUGGING(LEVELING)) DEBUG_POS("Move Y SwitchPos", current_position);
  306. planner.buffer_line(current_position,(planner.settings.max_feedrate_mm_s[Y_AXIS] * 0.5), active_extruder);
  307. planner.synchronize();
  308. safe_delay(200);
  309. current_position[Y_AXIS] -= SWITCHING_TOOLHEAD_Y_CLEAR;
  310. if (DEBUGGING(LEVELING)) DEBUG_POS("Move back Y clear", current_position);
  311. fast_line_to_current(Y_AXIS); // move away from docked toolhead
  312. planner.synchronize();
  313. // 3. Move to the new toolhead
  314. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("(3) Move to new toolhead position");
  315. current_position[X_AXIS] = grabxpos;
  316. if (DEBUGGING(LEVELING)) DEBUG_POS("Move to new toolhead X", current_position);
  317. fast_line_to_current(X_AXIS);
  318. planner.synchronize();
  319. current_position[Y_AXIS] = SWITCHING_TOOLHEAD_Y_POS - SWITCHING_TOOLHEAD_Y_SECURITY;
  320. if (DEBUGGING(LEVELING)) DEBUG_POS("Move Y SwitchPos + Security", current_position);
  321. fast_line_to_current(Y_AXIS);
  322. planner.synchronize();
  323. // 4. Grab and lock the new toolhead
  324. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("(4) Grab and lock new toolhead ");
  325. current_position[Y_AXIS] = SWITCHING_TOOLHEAD_Y_POS;
  326. if (DEBUGGING(LEVELING)) DEBUG_POS("Move Y SwitchPos", current_position);
  327. planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Y_AXIS] * 0.5, active_extruder);
  328. planner.synchronize();
  329. safe_delay(200);
  330. MOVE_SERVO(SWITCHING_TOOLHEAD_SERVO_NR, angles[0]);
  331. safe_delay(500);
  332. current_position[Y_AXIS] -= SWITCHING_TOOLHEAD_Y_CLEAR;
  333. if (DEBUGGING(LEVELING)) DEBUG_POS("Move back Y clear", current_position);
  334. fast_line_to_current(Y_AXIS); // move away from docked toolhead
  335. planner.synchronize();
  336. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Toolhead change done.");
  337. }
  338. #elif ENABLED(MAGNETIC_SWITCHING_TOOLHEAD)
  339. inline void magnetic_switching_toolhead_tool_change(const uint8_t tmp_extruder, bool no_move/*=false*/) {
  340. if (no_move) return;
  341. constexpr float toolheadposx[] = SWITCHING_TOOLHEAD_X_POS;
  342. const float placexpos = toolheadposx[active_extruder],
  343. grabxpos = toolheadposx[tmp_extruder];
  344. /**
  345. * 1. Move to switch position of current toolhead
  346. * 2. Release and place toolhead in the dock
  347. * 3. Move to the new toolhead
  348. * 4. Grab the new toolhead and move to security position
  349. */
  350. if (DEBUGGING(LEVELING)) DEBUG_POS("Starting Toolhead change", current_position);
  351. // 1. Move to switch position current toolhead
  352. current_position[Y_AXIS] = SWITCHING_TOOLHEAD_Y_POS + SWITCHING_TOOLHEAD_Y_CLEAR;
  353. if (DEBUGGING(LEVELING)) {
  354. SERIAL_ECHOLNPAIR("(1) Place old tool ", int(active_extruder));
  355. DEBUG_POS("Move Y SwitchPos + Security", current_position);
  356. }
  357. planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Y_AXIS], active_extruder);
  358. planner.synchronize();
  359. current_position[X_AXIS] = placexpos + SWITCHING_TOOLHEAD_X_SECURITY;
  360. if (DEBUGGING(LEVELING)) DEBUG_POS("Move X SwitchPos + Security", current_position);
  361. planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[X_AXIS], active_extruder);
  362. planner.synchronize();
  363. current_position[Y_AXIS] = SWITCHING_TOOLHEAD_Y_POS;
  364. if (DEBUGGING(LEVELING)) DEBUG_POS("Move Y SwitchPos", current_position);
  365. planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Y_AXIS], active_extruder);
  366. planner.synchronize();
  367. current_position[X_AXIS] = placexpos;
  368. if (DEBUGGING(LEVELING)) DEBUG_POS("Move X SwitchPos", current_position);
  369. planner.buffer_line(current_position, (planner.settings.max_feedrate_mm_s[X_AXIS] * 0.25), active_extruder);
  370. planner.synchronize();
  371. // 2. Release and place toolhead in the dock
  372. if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("(2) Release and Place Toolhead");
  373. current_position[Y_AXIS] = SWITCHING_TOOLHEAD_Y_POS + SWITCHING_TOOLHEAD_Y_RELEASE;
  374. if (DEBUGGING(LEVELING)) DEBUG_POS("Move Y SwitchPos + Release", current_position);
  375. planner.buffer_line(current_position, (planner.settings.max_feedrate_mm_s[Y_AXIS] * 0.1), active_extruder);
  376. planner.synchronize();
  377. current_position[Y_AXIS] = SWITCHING_TOOLHEAD_Y_POS + SWITCHING_TOOLHEAD_Y_SECURITY;
  378. if (DEBUGGING(LEVELING)) DEBUG_POS("Move Y SwitchPos + Security", current_position);
  379. planner.buffer_line(current_position, (planner.settings.max_feedrate_mm_s[Y_AXIS]), active_extruder);
  380. planner.synchronize();
  381. // 3. Move to new toolhead position
  382. if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("(3) Move to new toolhead position");
  383. current_position[X_AXIS] = grabxpos;
  384. if (DEBUGGING(LEVELING)) DEBUG_POS("Move to new toolhead X", current_position);
  385. planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[X_AXIS], active_extruder);
  386. planner.synchronize();
  387. // 4. Grab the new toolhead and move to security position
  388. if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("(4) Grab new toolhead and move to security position");
  389. current_position[Y_AXIS] = SWITCHING_TOOLHEAD_Y_POS + SWITCHING_TOOLHEAD_Y_RELEASE;
  390. if (DEBUGGING(LEVELING)) DEBUG_POS("Move Y SwitchPos + Release", current_position);
  391. planner.buffer_line(current_position, (planner.settings.max_feedrate_mm_s[Y_AXIS]), active_extruder);
  392. planner.synchronize();
  393. current_position[Y_AXIS] = SWITCHING_TOOLHEAD_Y_POS;
  394. if (DEBUGGING(LEVELING)) DEBUG_POS("Move Y SwitchPos", current_position);
  395. planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Y_AXIS] * 0.2, active_extruder);
  396. planner.synchronize();
  397. safe_delay(100);
  398. current_position[X_AXIS] = grabxpos + SWITCHING_TOOLHEAD_X_SECURITY;
  399. if (DEBUGGING(LEVELING)) DEBUG_POS("Move to new toolhead X + Security", current_position);
  400. planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[X_AXIS] * 0.1, active_extruder);
  401. planner.synchronize();
  402. safe_delay(100);
  403. current_position[Y_AXIS] += SWITCHING_TOOLHEAD_Y_CLEAR;
  404. if (DEBUGGING(LEVELING)) DEBUG_POS("Move back Y clear", current_position);
  405. planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Y_AXIS], active_extruder); // move away from docked toolhead
  406. planner.synchronize();
  407. }
  408. #elif ENABLED(ELECTROMAGNETIC_SWITCHING_TOOLHEAD)
  409. inline void est_activate_solenoid() { OUT_WRITE(SOL0_PIN, HIGH); }
  410. inline void est_deactivate_solenoid() { OUT_WRITE(SOL0_PIN, LOW); }
  411. void est_init() { est_activate_solenoid(); }
  412. inline void electromagnetic_switching_toolhead(const uint8_t tmp_extruder, bool no_move) {
  413. if (no_move) return;
  414. constexpr float toolheadposx[] = SWITCHING_TOOLHEAD_X_POS;
  415. const float placexpos = toolheadposx[active_extruder],
  416. grabxpos = toolheadposx[tmp_extruder];
  417. /**
  418. * 1. Raise Z-Axis to give enough clearance
  419. * 2. Move to position near active extruder parking
  420. * 3. Move gently to park position of active extruder
  421. * 4. Disengage magnetic field, wait for delay
  422. * 5. Leave extruder and move to position near new extruder parking
  423. * 6. Move gently to park position of new extruder
  424. * 7. Engage magnetic field for new extruder parking
  425. * 8. Unpark extruder
  426. * 9. Apply Z hotend offset to current position
  427. */
  428. #if ENABLED(DEBUG_LEVELING_FEATURE)
  429. if (DEBUGGING(LEVELING)) DEBUG_POS("Starting Autopark", current_position);
  430. #endif
  431. // 1. Raise Z-Axis to give enough clearance
  432. current_position[Z_AXIS] += SWITCHING_TOOLHEAD_Z_HOP;
  433. #if ENABLED(DEBUG_LEVELING_FEATURE)
  434. if (DEBUGGING(LEVELING)) DEBUG_POS("(1) Raise Z-Axis ", current_position);
  435. #endif
  436. planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Z_AXIS], active_extruder);
  437. // 2. Move to position near active extruder parking
  438. #if ENABLED(DEBUG_LEVELING_FEATURE)
  439. if (DEBUGGING(LEVELING)) {
  440. planner.synchronize();
  441. SERIAL_ECHOLNPAIR("(2) Move near active extruder parking", active_extruder);
  442. DEBUG_POS("Moving ParkPos", current_position);
  443. }
  444. #endif
  445. current_position[X_AXIS] = placexpos + hotend_offset[X_AXIS][active_extruder];
  446. current_position[Y_AXIS] = SWITCHING_TOOLHEAD_Y_POS + SWITCHING_TOOLHEAD_Y_CLEAR + hotend_offset[Y_AXIS][active_extruder];
  447. planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[X_AXIS], active_extruder);
  448. // 3. Move gently to park position of active extruder
  449. #if ENABLED(DEBUG_LEVELING_FEATURE)
  450. if (DEBUGGING(LEVELING)) {
  451. planner.synchronize();
  452. SERIAL_ECHOLNPAIR("(3) Move gently to park position of active extruder", active_extruder);
  453. DEBUG_POS("Moving ParkPos", current_position);
  454. }
  455. #endif
  456. current_position[Y_AXIS] -= SWITCHING_TOOLHEAD_Y_CLEAR;
  457. planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Y_AXIS] * 0.5, active_extruder);
  458. // 4. Disengage magnetic field, wait for delay
  459. #if ENABLED(DEBUG_LEVELING_FEATURE)
  460. if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("(4) Disengage magnet");
  461. #endif
  462. planner.synchronize();
  463. est_deactivate_solenoid();
  464. // 5. Leave extruder and move to position near new extruder parking
  465. #if ENABLED(DEBUG_LEVELING_FEATURE)
  466. if (DEBUGGING(LEVELING)) {
  467. SERIAL_ECHOLNPGM("(5) Move near new extruder parking");
  468. DEBUG_POS("Moving ParkPos", current_position);
  469. }
  470. #endif
  471. current_position[Y_AXIS] += SWITCHING_TOOLHEAD_Y_CLEAR;
  472. planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Y_AXIS] * 0.5f, active_extruder);
  473. current_position[X_AXIS] = grabxpos + hotend_offset[X_AXIS][active_extruder];
  474. current_position[Y_AXIS] = SWITCHING_TOOLHEAD_Y_POS + SWITCHING_TOOLHEAD_Y_CLEAR + hotend_offset[Y_AXIS][active_extruder];
  475. planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[X_AXIS], active_extruder);
  476. // 6. Move gently to park position of new extruder
  477. #if ENABLED(DEBUG_LEVELING_FEATURE)
  478. if (DEBUGGING(LEVELING)) {
  479. planner.synchronize();
  480. SERIAL_ECHOLNPGM("(6) Move near new extruder");
  481. }
  482. #endif
  483. current_position[Y_AXIS] -= SWITCHING_TOOLHEAD_Y_CLEAR;
  484. planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Y_AXIS] * 0.5f, active_extruder);
  485. // 7. Engage magnetic field for new extruder parking
  486. #if ENABLED(DEBUG_LEVELING_FEATURE)
  487. if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("(7) Engage magnetic field");
  488. #endif
  489. planner.synchronize();
  490. est_activate_solenoid();
  491. // 8. Unpark extruder
  492. #if ENABLED(DEBUG_LEVELING_FEATURE)
  493. if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("(8) Unpark extruder");
  494. #endif
  495. current_position[Y_AXIS] += SWITCHING_TOOLHEAD_Y_CLEAR;
  496. planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[X_AXIS] * 0.5f, active_extruder);
  497. // 9. Apply Z hotend offset to current position
  498. current_position[Z_AXIS] += hotend_offset[Z_AXIS][active_extruder] - hotend_offset[Z_AXIS][tmp_extruder];
  499. #if ENABLED(DEBUG_LEVELING_FEATURE)
  500. if (DEBUGGING(LEVELING)) {
  501. planner.synchronize();
  502. DEBUG_POS("(9) Applying Z-offset", current_position);
  503. }
  504. #endif
  505. }
  506. #endif // ELECTROMAGNETIC_SWITCHING_TOOLHEAD
  507. inline void invalid_extruder_error(const uint8_t e) {
  508. SERIAL_ECHO_START();
  509. SERIAL_CHAR('T'); SERIAL_ECHO(int(e));
  510. SERIAL_CHAR(' '); SERIAL_ECHOLNPGM(MSG_INVALID_EXTRUDER);
  511. }
  512. #if ENABLED(DUAL_X_CARRIAGE)
  513. inline void dualx_tool_change(const uint8_t tmp_extruder, bool &no_move) {
  514. if (DEBUGGING(LEVELING)) {
  515. DEBUG_ECHOPGM("Dual X Carriage Mode ");
  516. switch (dual_x_carriage_mode) {
  517. case DXC_FULL_CONTROL_MODE: DEBUG_ECHOLNPGM("FULL_CONTROL"); break;
  518. case DXC_AUTO_PARK_MODE: DEBUG_ECHOLNPGM("AUTO_PARK"); break;
  519. case DXC_DUPLICATION_MODE: DEBUG_ECHOLNPGM("DUPLICATION"); break;
  520. case DXC_MIRRORED_MODE: DEBUG_ECHOLNPGM("MIRRORED"); break;
  521. }
  522. }
  523. const float xhome = x_home_pos(active_extruder);
  524. if (dual_x_carriage_mode == DXC_AUTO_PARK_MODE
  525. && IsRunning()
  526. && (delayed_move_time || current_position[X_AXIS] != xhome) && ! no_move
  527. ) {
  528. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("MoveX to ", xhome);
  529. // Park old head
  530. planner.buffer_line(xhome, current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], planner.settings.max_feedrate_mm_s[X_AXIS], active_extruder);
  531. planner.synchronize();
  532. }
  533. // Activate the new extruder ahead of calling set_axis_is_at_home!
  534. active_extruder = tmp_extruder;
  535. // This function resets the max/min values - the current position may be overwritten below.
  536. set_axis_is_at_home(X_AXIS);
  537. if (DEBUGGING(LEVELING)) DEBUG_POS("New Extruder", current_position);
  538. switch (dual_x_carriage_mode) {
  539. case DXC_FULL_CONTROL_MODE:
  540. // New current position is the position of the activated extruder
  541. current_position[X_AXIS] = inactive_extruder_x_pos;
  542. // Save the inactive extruder's position (from the old current_position)
  543. inactive_extruder_x_pos = destination[X_AXIS];
  544. break;
  545. case DXC_AUTO_PARK_MODE:
  546. // record current raised toolhead position for use by unpark
  547. COPY(raised_parked_position, current_position);
  548. active_extruder_parked = true;
  549. delayed_move_time = 0;
  550. break;
  551. default:
  552. break;
  553. }
  554. if (DEBUGGING(LEVELING)) {
  555. DEBUG_ECHOLNPAIR("Active extruder parked: ", active_extruder_parked ? "yes" : "no");
  556. DEBUG_POS("New extruder (parked)", current_position);
  557. }
  558. }
  559. #endif // DUAL_X_CARRIAGE
  560. /**
  561. * Perform a tool-change, which may result in moving the
  562. * previous tool out of the way and the new tool into place.
  563. */
  564. void tool_change(const uint8_t tmp_extruder, bool no_move/*=false*/) {
  565. #if ENABLED(MAGNETIC_SWITCHING_TOOLHEAD)
  566. if (tmp_extruder == active_extruder) return;
  567. #endif
  568. #if ENABLED(MIXING_EXTRUDER)
  569. UNUSED(no_move);
  570. if (tmp_extruder >= MIXING_VIRTUAL_TOOLS)
  571. return invalid_extruder_error(tmp_extruder);
  572. #if MIXING_VIRTUAL_TOOLS > 1
  573. // T0-Tnnn: Switch virtual tool by changing the index to the mix
  574. mixer.T(tmp_extruder);
  575. #endif
  576. #elif ENABLED(PRUSA_MMU2)
  577. UNUSED(no_move);
  578. mmu2.tool_change(tmp_extruder);
  579. #elif EXTRUDERS < 2
  580. UNUSED(no_move);
  581. if (tmp_extruder) invalid_extruder_error(tmp_extruder);
  582. return;
  583. #else // EXTRUDERS > 1
  584. planner.synchronize();
  585. #if ENABLED(DUAL_X_CARRIAGE) // Only T0 allowed if the Printer is in DXC_DUPLICATION_MODE or DXC_MIRRORED_MODE
  586. if (tmp_extruder != 0 && dxc_is_duplicating())
  587. return invalid_extruder_error(tmp_extruder);
  588. #endif
  589. #if HAS_LEVELING
  590. // Set current position to the physical position
  591. const bool leveling_was_active = planner.leveling_active;
  592. set_bed_leveling_enabled(false);
  593. #endif
  594. if (tmp_extruder >= EXTRUDERS)
  595. return invalid_extruder_error(tmp_extruder);
  596. if (!no_move && !all_axes_homed()) {
  597. no_move = true;
  598. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("No move (not homed)");
  599. }
  600. #if HAS_LCD_MENU
  601. ui.return_to_status();
  602. #endif
  603. #if ENABLED(DUAL_X_CARRIAGE)
  604. const bool idex_full_control = dual_x_carriage_mode == DXC_FULL_CONTROL_MODE;
  605. #else
  606. constexpr bool idex_full_control = false;
  607. #endif
  608. const bool can_move_away = !no_move && !idex_full_control;
  609. #if ENABLED(TOOLCHANGE_FILAMENT_SWAP)
  610. const bool should_swap = can_move_away && toolchange_settings.swap_length;
  611. #if ENABLED(PREVENT_COLD_EXTRUSION)
  612. const bool too_cold = !DEBUGGING(DRYRUN) && (thermalManager.targetTooColdToExtrude(active_extruder) || thermalManager.targetTooColdToExtrude(tmp_extruder));
  613. #else
  614. constexpr bool too_cold = false;
  615. #endif
  616. if (should_swap) {
  617. if (too_cold) {
  618. SERIAL_ECHO_MSG(MSG_ERR_HOTEND_TOO_COLD);
  619. #if ENABLED(SINGLENOZZLE)
  620. active_extruder = tmp_extruder;
  621. return;
  622. #endif
  623. }
  624. else {
  625. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  626. do_pause_e_move(-toolchange_settings.swap_length, MMM_TO_MMS(toolchange_settings.retract_speed));
  627. #else
  628. current_position[E_AXIS] -= toolchange_settings.swap_length / planner.e_factor[active_extruder];
  629. planner.buffer_line(current_position, MMM_TO_MMS(toolchange_settings.retract_speed), active_extruder);
  630. planner.synchronize();
  631. #endif
  632. }
  633. }
  634. #endif // TOOLCHANGE_FILAMENT_SWAP
  635. if (tmp_extruder != active_extruder) {
  636. #if SWITCHING_NOZZLE_TWO_SERVOS
  637. raise_nozzle(active_extruder);
  638. #endif
  639. REMEMBER(fr, feedrate_mm_s, XY_PROBE_FEEDRATE_MM_S);
  640. #if HAS_SOFTWARE_ENDSTOPS
  641. #if HAS_HOTEND_OFFSET
  642. #define _EXT_ARGS , active_extruder, tmp_extruder
  643. #else
  644. #define _EXT_ARGS
  645. #endif
  646. update_software_endstops(X_AXIS _EXT_ARGS);
  647. #if DISABLED(DUAL_X_CARRIAGE)
  648. update_software_endstops(Y_AXIS _EXT_ARGS);
  649. update_software_endstops(Z_AXIS _EXT_ARGS);
  650. #endif
  651. #endif
  652. set_destination_from_current();
  653. #if DISABLED(SWITCHING_NOZZLE)
  654. if (can_move_away) {
  655. // Do a small lift to avoid the workpiece in the move back (below)
  656. current_position[Z_AXIS] += toolchange_settings.z_raise;
  657. #if HAS_SOFTWARE_ENDSTOPS
  658. NOMORE(current_position[Z_AXIS], soft_endstop[Z_AXIS].max);
  659. #endif
  660. fast_line_to_current(Z_AXIS);
  661. #if ENABLED(TOOLCHANGE_PARK)
  662. current_position[X_AXIS] = toolchange_settings.change_point.x;
  663. current_position[Y_AXIS] = toolchange_settings.change_point.y;
  664. #endif
  665. planner.buffer_line(current_position, feedrate_mm_s, active_extruder);
  666. planner.synchronize();
  667. }
  668. #endif
  669. #if HAS_HOTEND_OFFSET
  670. #if ENABLED(DUAL_X_CARRIAGE)
  671. constexpr float xdiff = 0;
  672. #else
  673. const float xdiff = hotend_offset[X_AXIS][tmp_extruder] - hotend_offset[X_AXIS][active_extruder];
  674. #endif
  675. const float ydiff = hotend_offset[Y_AXIS][tmp_extruder] - hotend_offset[Y_AXIS][active_extruder],
  676. zdiff = hotend_offset[Z_AXIS][tmp_extruder] - hotend_offset[Z_AXIS][active_extruder];
  677. #else
  678. constexpr float xdiff = 0, ydiff = 0, zdiff = 0;
  679. #endif
  680. #if ENABLED(DUAL_X_CARRIAGE)
  681. dualx_tool_change(tmp_extruder, no_move);
  682. #elif ENABLED(PARKING_EXTRUDER) // Dual Parking extruder
  683. parking_extruder_tool_change(tmp_extruder, no_move);
  684. #elif ENABLED(MAGNETIC_PARKING_EXTRUDER) // Magnetic Parking extruder
  685. magnetic_parking_extruder_tool_change(tmp_extruder);
  686. #elif ENABLED(SWITCHING_TOOLHEAD) // Switching Toolhead
  687. switching_toolhead_tool_change(tmp_extruder, no_move);
  688. #elif ENABLED(MAGNETIC_SWITCHING_TOOLHEAD) // Magnetic Switching Toolhead
  689. magnetic_switching_toolhead_tool_change(tmp_extruder, no_move);
  690. #elif ENABLED(ELECTROMAGNETIC_SWITCHING_TOOLHEAD) // Magnetic Switching ToolChanger
  691. electromagnetic_switching_toolhead(tmp_extruder, no_move);
  692. #elif ENABLED(SWITCHING_NOZZLE) && !SWITCHING_NOZZLE_TWO_SERVOS // Switching Nozzle (single servo)
  693. // Raise by a configured distance to avoid workpiece, except with
  694. // SWITCHING_NOZZLE_TWO_SERVOS, as both nozzles will lift instead.
  695. current_position[Z_AXIS] += MAX(-zdiff, 0.0) + toolchange_settings.z_raise;
  696. #if HAS_SOFTWARE_ENDSTOPS
  697. NOMORE(current_position[Z_AXIS], soft_endstop[Z_AXIS].max);
  698. #endif
  699. if (!no_move) fast_line_to_current(Z_AXIS);
  700. move_nozzle_servo(tmp_extruder);
  701. #endif
  702. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Offset Tool XY by { ", xdiff, ", ", ydiff, ", ", zdiff, " }");
  703. // The newly-selected extruder XY is actually at...
  704. current_position[X_AXIS] += xdiff;
  705. current_position[Y_AXIS] += ydiff;
  706. current_position[Z_AXIS] += zdiff;
  707. // Set the new active extruder if not already done in tool specific function above
  708. active_extruder = tmp_extruder;
  709. // Tell the planner the new "current position"
  710. sync_plan_position();
  711. #if ENABLED(DELTA)
  712. //LOOP_XYZ(i) update_software_endstops(i); // or modify the constrain function
  713. const bool safe_to_move = current_position[Z_AXIS] < delta_clip_start_height - 1;
  714. #else
  715. constexpr bool safe_to_move = true;
  716. #endif
  717. // Return to position and lower again
  718. if (safe_to_move && !no_move && IsRunning()) {
  719. #if ENABLED(SINGLENOZZLE)
  720. #if FAN_COUNT > 0
  721. singlenozzle_fan_speed[active_extruder] = thermalManager.fan_speed[0];
  722. thermalManager.fan_speed[0] = singlenozzle_fan_speed[tmp_extruder];
  723. #endif
  724. singlenozzle_temp[active_extruder] = thermalManager.temp_hotend[0].target;
  725. if (singlenozzle_temp[tmp_extruder] && singlenozzle_temp[tmp_extruder] != singlenozzle_temp[active_extruder]) {
  726. thermalManager.setTargetHotend(singlenozzle_temp[tmp_extruder], 0);
  727. #if EITHER(ULTRA_LCD, EXTENSIBLE_UI)
  728. thermalManager.set_heating_message(0);
  729. #endif
  730. (void)thermalManager.wait_for_hotend(0, false); // Wait for heating or cooling
  731. }
  732. active_extruder = tmp_extruder;
  733. #endif
  734. #if ENABLED(TOOLCHANGE_FILAMENT_SWAP)
  735. if (should_swap && !too_cold) {
  736. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  737. do_pause_e_move(toolchange_settings.swap_length + TOOLCHANGE_FIL_EXTRA_PRIME, MMM_TO_MMS(toolchange_settings.prime_speed));
  738. #else
  739. current_position[E_AXIS] += (toolchange_settings.swap_length + TOOLCHANGE_FIL_EXTRA_PRIME) / planner.e_factor[tmp_extruder];
  740. planner.buffer_line(current_position, MMM_TO_MMS(toolchange_settings.prime_speed), tmp_extruder);
  741. #endif
  742. planner.synchronize();
  743. #if TOOLCHANGE_FIL_EXTRA_PRIME
  744. planner.set_e_position_mm((destination[E_AXIS] = current_position[E_AXIS] = current_position[E_AXIS] - (TOOLCHANGE_FIL_EXTRA_PRIME)));
  745. #endif
  746. }
  747. #endif
  748. // Prevent a move outside physical bounds
  749. #if ENABLED(MAGNETIC_SWITCHING_TOOLHEAD)
  750. // If the original position is within tool store area, go to X origin at once
  751. if (destination[Y_AXIS] < SWITCHING_TOOLHEAD_Y_POS + SWITCHING_TOOLHEAD_Y_CLEAR) {
  752. current_position[X_AXIS] = 0;
  753. planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[X_AXIS], active_extruder);
  754. planner.synchronize();
  755. }
  756. #else
  757. apply_motion_limits(destination);
  758. #endif
  759. // Should the nozzle move back to the old position?
  760. if (can_move_away) {
  761. #if ENABLED(TOOLCHANGE_NO_RETURN)
  762. // Just move back down
  763. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Move back Z only");
  764. do_blocking_move_to_z(destination[Z_AXIS], planner.settings.max_feedrate_mm_s[Z_AXIS]);
  765. #else
  766. // Move back to the original (or adjusted) position
  767. if (DEBUGGING(LEVELING)) DEBUG_POS("Move back", destination);
  768. do_blocking_move_to(destination);
  769. #endif
  770. }
  771. else if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Move back skipped");
  772. #if ENABLED(DUAL_X_CARRIAGE)
  773. active_extruder_parked = false;
  774. #endif
  775. }
  776. #if ENABLED(SWITCHING_NOZZLE)
  777. else {
  778. // Move back down. (Including when the new tool is higher.)
  779. do_blocking_move_to_z(destination[Z_AXIS], planner.settings.max_feedrate_mm_s[Z_AXIS]);
  780. }
  781. #endif
  782. #if ENABLED(PRUSA_MMU2)
  783. mmu2.tool_change(tmp_extruder);
  784. #endif
  785. #if SWITCHING_NOZZLE_TWO_SERVOS
  786. lower_nozzle(active_extruder);
  787. #endif
  788. } // (tmp_extruder != active_extruder)
  789. planner.synchronize();
  790. #if ENABLED(EXT_SOLENOID) && DISABLED(PARKING_EXTRUDER)
  791. disable_all_solenoids();
  792. enable_solenoid_on_active_extruder();
  793. #endif
  794. #if ENABLED(MK2_MULTIPLEXER)
  795. if (tmp_extruder >= E_STEPPERS) return invalid_extruder_error(tmp_extruder);
  796. select_multiplexed_stepper(tmp_extruder);
  797. #endif
  798. #if DO_SWITCH_EXTRUDER
  799. planner.synchronize();
  800. move_extruder_servo(active_extruder);
  801. #endif
  802. #if HAS_FANMUX
  803. fanmux_switch(active_extruder);
  804. #endif
  805. #if HAS_LEVELING
  806. // Restore leveling to re-establish the logical position
  807. set_bed_leveling_enabled(leveling_was_active);
  808. #endif
  809. SERIAL_ECHO_START();
  810. SERIAL_ECHOLNPAIR(MSG_ACTIVE_EXTRUDER, int(active_extruder));
  811. #endif // EXTRUDERS > 1
  812. }