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

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