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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 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 "tool_change.h"
  23. #include "motion.h"
  24. #include "planner.h"
  25. #include "stepper.h"
  26. #include "../Marlin.h"
  27. #include "../inc/MarlinConfig.h"
  28. #if ENABLED(PARKING_EXTRUDER) && PARKING_EXTRUDER_SOLENOIDS_DELAY > 0
  29. #include "../gcode/gcode.h" // for dwell()
  30. #endif
  31. #if ENABLED(EXT_SOLENOID) && !ENABLED(PARKING_EXTRUDER)
  32. #include "../feature/solenoid.h"
  33. #endif
  34. #if ENABLED(SWITCHING_EXTRUDER)
  35. #if EXTRUDERS > 3
  36. #define REQ_ANGLES 4
  37. #define _SERVO_NR (e < 2 ? SWITCHING_EXTRUDER_SERVO_NR : SWITCHING_EXTRUDER_E23_SERVO_NR)
  38. #else
  39. #define REQ_ANGLES 2
  40. #define _SERVO_NR SWITCHING_EXTRUDER_SERVO_NR
  41. #endif
  42. void move_extruder_servo(const uint8_t e) {
  43. constexpr int16_t angles[] = SWITCHING_EXTRUDER_SERVO_ANGLES;
  44. static_assert(COUNT(angles) == REQ_ANGLES, "SWITCHING_EXTRUDER_SERVO_ANGLES needs " STRINGIFY(REQ_ANGLES) " angles.");
  45. stepper.synchronize();
  46. #if EXTRUDERS & 1
  47. if (e < EXTRUDERS - 1)
  48. #endif
  49. {
  50. MOVE_SERVO(_SERVO_NR, angles[e]);
  51. safe_delay(500);
  52. }
  53. }
  54. #endif // SWITCHING_EXTRUDER
  55. #if ENABLED(SWITCHING_NOZZLE)
  56. void move_nozzle_servo(const uint8_t e) {
  57. const int16_t angles[2] = SWITCHING_NOZZLE_SERVO_ANGLES;
  58. stepper.synchronize();
  59. MOVE_SERVO(SWITCHING_NOZZLE_SERVO_NR, angles[e]);
  60. safe_delay(500);
  61. }
  62. #endif // SWITCHING_NOZZLE
  63. #if ENABLED(PARKING_EXTRUDER)
  64. void pe_set_magnet(const uint8_t extruder_num, const uint8_t state) {
  65. switch (extruder_num) {
  66. case 1: OUT_WRITE(SOL1_PIN, state); break;
  67. default: OUT_WRITE(SOL0_PIN, state); break;
  68. }
  69. #if PARKING_EXTRUDER_SOLENOIDS_DELAY > 0
  70. gcode.dwell(PARKING_EXTRUDER_SOLENOIDS_DELAY);
  71. #endif
  72. }
  73. #endif // PARKING_EXTRUDER
  74. #if HAS_FANMUX
  75. void fanmux_switch(const uint8_t e) {
  76. WRITE(FANMUX0_PIN, TEST(e, 0) ? HIGH : LOW);
  77. #if PIN_EXISTS(FANMUX1)
  78. WRITE(FANMUX1_PIN, TEST(e, 1) ? HIGH : LOW);
  79. #if PIN_EXISTS(FANMUX2)
  80. WRITE(FANMUX2, TEST(e, 2) ? HIGH : LOW);
  81. #endif
  82. #endif
  83. }
  84. FORCE_INLINE void fanmux_init(void){
  85. SET_OUTPUT(FANMUX0_PIN);
  86. #if PIN_EXISTS(FANMUX1)
  87. SET_OUTPUT(FANMUX1_PIN);
  88. #if PIN_EXISTS(FANMUX2)
  89. SET_OUTPUT(FANMUX2_PIN);
  90. #endif
  91. #endif
  92. fanmux_switch(0);
  93. }
  94. #endif // HAS_FANMUX
  95. inline void invalid_extruder_error(const uint8_t e) {
  96. SERIAL_ECHO_START();
  97. SERIAL_CHAR('T');
  98. SERIAL_ECHO_F(e, DEC);
  99. SERIAL_CHAR(' ');
  100. SERIAL_ECHOLN(MSG_INVALID_EXTRUDER);
  101. }
  102. /**
  103. * Perform a tool-change, which may result in moving the
  104. * previous tool out of the way and the new tool into place.
  105. */
  106. void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool no_move/*=false*/) {
  107. #if ENABLED(MIXING_EXTRUDER) && MIXING_VIRTUAL_TOOLS > 1
  108. if (tmp_extruder >= MIXING_VIRTUAL_TOOLS)
  109. return invalid_extruder_error(tmp_extruder);
  110. // T0-Tnnn: Switch virtual tool by changing the mix
  111. for (uint8_t j = 0; j < MIXING_STEPPERS; j++)
  112. mixing_factor[j] = mixing_virtual_tool_mix[tmp_extruder][j];
  113. #else // !MIXING_EXTRUDER || MIXING_VIRTUAL_TOOLS <= 1
  114. if (tmp_extruder >= EXTRUDERS)
  115. return invalid_extruder_error(tmp_extruder);
  116. #if HOTENDS > 1
  117. const float old_feedrate_mm_s = fr_mm_s > 0.0 ? fr_mm_s : feedrate_mm_s;
  118. feedrate_mm_s = fr_mm_s > 0.0 ? fr_mm_s : XY_PROBE_FEEDRATE_MM_S;
  119. if (tmp_extruder != active_extruder) {
  120. if (!no_move && axis_unhomed_error()) {
  121. no_move = true;
  122. #if ENABLED(DEBUG_LEVELING_FEATURE)
  123. if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("No move on toolchange");
  124. #endif
  125. }
  126. // Save current position to destination, for use later
  127. set_destination_to_current();
  128. #if ENABLED(DUAL_X_CARRIAGE)
  129. #if ENABLED(DEBUG_LEVELING_FEATURE)
  130. if (DEBUGGING(LEVELING)) {
  131. SERIAL_ECHOPGM("Dual X Carriage Mode ");
  132. switch (dual_x_carriage_mode) {
  133. case DXC_FULL_CONTROL_MODE: SERIAL_ECHOLNPGM("DXC_FULL_CONTROL_MODE"); break;
  134. case DXC_AUTO_PARK_MODE: SERIAL_ECHOLNPGM("DXC_AUTO_PARK_MODE"); break;
  135. case DXC_DUPLICATION_MODE: SERIAL_ECHOLNPGM("DXC_DUPLICATION_MODE"); break;
  136. }
  137. }
  138. #endif
  139. const float xhome = x_home_pos(active_extruder);
  140. if (dual_x_carriage_mode == DXC_AUTO_PARK_MODE
  141. && IsRunning()
  142. && (delayed_move_time || current_position[X_AXIS] != xhome)
  143. ) {
  144. float raised_z = current_position[Z_AXIS] + TOOLCHANGE_PARK_ZLIFT;
  145. #if ENABLED(MAX_SOFTWARE_ENDSTOPS)
  146. NOMORE(raised_z, soft_endstop_max[Z_AXIS]);
  147. #endif
  148. #if ENABLED(DEBUG_LEVELING_FEATURE)
  149. if (DEBUGGING(LEVELING)) {
  150. SERIAL_ECHOLNPAIR("Raise to ", raised_z);
  151. SERIAL_ECHOLNPAIR("MoveX to ", xhome);
  152. SERIAL_ECHOLNPAIR("Lower to ", current_position[Z_AXIS]);
  153. }
  154. #endif
  155. // Park old head: 1) raise 2) move to park position 3) lower
  156. for (uint8_t i = 0; i < 3; i++)
  157. planner.buffer_line(
  158. i == 0 ? current_position[X_AXIS] : xhome,
  159. current_position[Y_AXIS],
  160. i == 2 ? current_position[Z_AXIS] : raised_z,
  161. current_position[E_AXIS],
  162. planner.max_feedrate_mm_s[i == 1 ? X_AXIS : Z_AXIS],
  163. active_extruder
  164. );
  165. stepper.synchronize();
  166. }
  167. // Apply Y & Z extruder offset (X offset is used as home pos with Dual X)
  168. current_position[Y_AXIS] -= hotend_offset[Y_AXIS][active_extruder] - hotend_offset[Y_AXIS][tmp_extruder];
  169. current_position[Z_AXIS] -= hotend_offset[Z_AXIS][active_extruder] - hotend_offset[Z_AXIS][tmp_extruder];
  170. // Activate the new extruder ahead of calling set_axis_is_at_home!
  171. active_extruder = tmp_extruder;
  172. // This function resets the max/min values - the current position may be overwritten below.
  173. set_axis_is_at_home(X_AXIS);
  174. #if ENABLED(DEBUG_LEVELING_FEATURE)
  175. if (DEBUGGING(LEVELING)) DEBUG_POS("New Extruder", current_position);
  176. #endif
  177. // Only when auto-parking are carriages safe to move
  178. if (dual_x_carriage_mode != DXC_AUTO_PARK_MODE) no_move = true;
  179. switch (dual_x_carriage_mode) {
  180. case DXC_FULL_CONTROL_MODE:
  181. // New current position is the position of the activated extruder
  182. current_position[X_AXIS] = LOGICAL_X_POSITION(inactive_extruder_x_pos);
  183. // Save the inactive extruder's position (from the old current_position)
  184. inactive_extruder_x_pos = RAW_X_POSITION(destination[X_AXIS]);
  185. break;
  186. case DXC_AUTO_PARK_MODE:
  187. // record raised toolhead position for use by unpark
  188. COPY(raised_parked_position, current_position);
  189. raised_parked_position[Z_AXIS] += TOOLCHANGE_UNPARK_ZLIFT;
  190. #if ENABLED(MAX_SOFTWARE_ENDSTOPS)
  191. NOMORE(raised_parked_position[Z_AXIS], soft_endstop_max[Z_AXIS]);
  192. #endif
  193. active_extruder_parked = true;
  194. delayed_move_time = 0;
  195. break;
  196. case DXC_DUPLICATION_MODE:
  197. // If the new extruder is the left one, set it "parked"
  198. // This triggers the second extruder to move into the duplication position
  199. active_extruder_parked = (active_extruder == 0);
  200. if (active_extruder_parked)
  201. current_position[X_AXIS] = LOGICAL_X_POSITION(inactive_extruder_x_pos);
  202. else
  203. current_position[X_AXIS] = destination[X_AXIS] + duplicate_extruder_x_offset;
  204. inactive_extruder_x_pos = RAW_X_POSITION(destination[X_AXIS]);
  205. extruder_duplication_enabled = false;
  206. #if ENABLED(DEBUG_LEVELING_FEATURE)
  207. if (DEBUGGING(LEVELING)) {
  208. SERIAL_ECHOLNPAIR("Set inactive_extruder_x_pos=", inactive_extruder_x_pos);
  209. SERIAL_ECHOLNPGM("Clear extruder_duplication_enabled");
  210. }
  211. #endif
  212. break;
  213. }
  214. #if ENABLED(DEBUG_LEVELING_FEATURE)
  215. if (DEBUGGING(LEVELING)) {
  216. SERIAL_ECHOLNPAIR("Active extruder parked: ", active_extruder_parked ? "yes" : "no");
  217. DEBUG_POS("New extruder (parked)", current_position);
  218. }
  219. #endif
  220. // No extra case for HAS_ABL in DUAL_X_CARRIAGE. Does that mean they don't work together?
  221. #else // !DUAL_X_CARRIAGE
  222. #if ENABLED(PARKING_EXTRUDER) // Dual Parking extruder
  223. const float z_diff = hotend_offset[Z_AXIS][active_extruder] - hotend_offset[Z_AXIS][tmp_extruder];
  224. float z_raise = 0;
  225. if (!no_move) {
  226. const float parkingposx[] = PARKING_EXTRUDER_PARKING_X,
  227. midpos = ((parkingposx[1] - parkingposx[0])/2) + parkingposx[0] + hotend_offset[X_AXIS][active_extruder],
  228. grabpos = parkingposx[tmp_extruder] + hotend_offset[X_AXIS][active_extruder]
  229. + (tmp_extruder == 0 ? -(PARKING_EXTRUDER_GRAB_DISTANCE) : PARKING_EXTRUDER_GRAB_DISTANCE);
  230. /**
  231. * Steps:
  232. * 1. raise Z-Axis to have enough clearance
  233. * 2. move to park poition of old extruder
  234. * 3. disengage magnetc field, wait for delay
  235. * 4. move near new extruder
  236. * 5. engage magnetic field for new extruder
  237. * 6. move to parking incl. offset of new extruder
  238. * 7. lower Z-Axis
  239. */
  240. // STEP 1
  241. #if ENABLED(DEBUG_LEVELING_FEATURE)
  242. SERIAL_ECHOLNPGM("Starting Autopark");
  243. if (DEBUGGING(LEVELING)) DEBUG_POS("current position:", current_position);
  244. #endif
  245. z_raise = PARKING_EXTRUDER_SECURITY_RAISE;
  246. current_position[Z_AXIS] += z_raise;
  247. #if ENABLED(DEBUG_LEVELING_FEATURE)
  248. SERIAL_ECHOLNPGM("(1) Raise Z-Axis ");
  249. if (DEBUGGING(LEVELING)) DEBUG_POS("Moving to Raised Z-Position", current_position);
  250. #endif
  251. planner.buffer_line_kinematic(current_position, planner.max_feedrate_mm_s[Z_AXIS], active_extruder);
  252. stepper.synchronize();
  253. // STEP 2
  254. current_position[X_AXIS] = parkingposx[active_extruder] + hotend_offset[X_AXIS][active_extruder];
  255. #if ENABLED(DEBUG_LEVELING_FEATURE)
  256. SERIAL_ECHOLNPAIR("(2) Park extruder ", active_extruder);
  257. if (DEBUGGING(LEVELING)) DEBUG_POS("Moving ParkPos", current_position);
  258. #endif
  259. planner.buffer_line_kinematic(current_position, planner.max_feedrate_mm_s[X_AXIS], active_extruder);
  260. stepper.synchronize();
  261. // STEP 3
  262. #if ENABLED(DEBUG_LEVELING_FEATURE)
  263. SERIAL_ECHOLNPGM("(3) Disengage magnet ");
  264. #endif
  265. pe_deactivate_magnet(active_extruder);
  266. // STEP 4
  267. #if ENABLED(DEBUG_LEVELING_FEATURE)
  268. SERIAL_ECHOLNPGM("(4) Move to position near new extruder");
  269. #endif
  270. current_position[X_AXIS] += (active_extruder == 0 ? 10 : -10); // move 10mm away from parked extruder
  271. #if ENABLED(DEBUG_LEVELING_FEATURE)
  272. if (DEBUGGING(LEVELING)) DEBUG_POS("Moving away from parked extruder", current_position);
  273. #endif
  274. planner.buffer_line_kinematic(current_position, planner.max_feedrate_mm_s[X_AXIS], active_extruder);
  275. stepper.synchronize();
  276. // STEP 5
  277. #if ENABLED(DEBUG_LEVELING_FEATURE)
  278. SERIAL_ECHOLNPGM("(5) Engage magnetic field");
  279. #endif
  280. #if ENABLED(PARKING_EXTRUDER_SOLENOIDS_INVERT)
  281. pe_activate_magnet(active_extruder); //just save power for inverted magnets
  282. #endif
  283. pe_activate_magnet(tmp_extruder);
  284. // STEP 6
  285. current_position[X_AXIS] = grabpos + (tmp_extruder == 0 ? (+10) : (-10));
  286. planner.buffer_line_kinematic(current_position, planner.max_feedrate_mm_s[X_AXIS], active_extruder);
  287. current_position[X_AXIS] = grabpos;
  288. #if ENABLED(DEBUG_LEVELING_FEATURE)
  289. SERIAL_ECHOLNPAIR("(6) Unpark extruder ", tmp_extruder);
  290. if (DEBUGGING(LEVELING)) DEBUG_POS("Move UnparkPos", current_position);
  291. #endif
  292. planner.buffer_line_kinematic(current_position, planner.max_feedrate_mm_s[X_AXIS]/2, active_extruder);
  293. stepper.synchronize();
  294. // Step 7
  295. current_position[X_AXIS] = midpos - hotend_offset[X_AXIS][tmp_extruder];
  296. #if ENABLED(DEBUG_LEVELING_FEATURE)
  297. SERIAL_ECHOLNPGM("(7) Move midway between hotends");
  298. if (DEBUGGING(LEVELING)) DEBUG_POS("Move midway to new extruder", current_position);
  299. #endif
  300. planner.buffer_line_kinematic(current_position, planner.max_feedrate_mm_s[X_AXIS], active_extruder);
  301. stepper.synchronize();
  302. #if ENABLED(DEBUG_LEVELING_FEATURE)
  303. SERIAL_ECHOLNPGM("Autopark done.");
  304. #endif
  305. }
  306. else { // nomove == true
  307. // Only engage magnetic field for new extruder
  308. pe_activate_magnet(tmp_extruder);
  309. #if ENABLED(PARKING_EXTRUDER_SOLENOIDS_INVERT)
  310. pe_activate_magnet(active_extruder); // Just save power for inverted magnets
  311. #endif
  312. }
  313. current_position[Z_AXIS] -= hotend_offset[Z_AXIS][tmp_extruder] - hotend_offset[Z_AXIS][active_extruder]; // Apply Zoffset
  314. #if ENABLED(DEBUG_LEVELING_FEATURE)
  315. if (DEBUGGING(LEVELING)) DEBUG_POS("Applying Z-offset", current_position);
  316. #endif
  317. #endif // dualParking extruder
  318. #if ENABLED(SWITCHING_NOZZLE)
  319. #define DONT_SWITCH (SWITCHING_EXTRUDER_SERVO_NR == SWITCHING_NOZZLE_SERVO_NR)
  320. // <0 if the new nozzle is higher, >0 if lower. A bigger raise when lower.
  321. const float z_diff = hotend_offset[Z_AXIS][active_extruder] - hotend_offset[Z_AXIS][tmp_extruder],
  322. z_raise = 0.3 + (z_diff > 0.0 ? z_diff : 0.0);
  323. // Always raise by some amount (destination copied from current_position earlier)
  324. current_position[Z_AXIS] += z_raise;
  325. planner.buffer_line_kinematic(current_position, planner.max_feedrate_mm_s[Z_AXIS], active_extruder);
  326. move_nozzle_servo(tmp_extruder);
  327. #endif
  328. /**
  329. * Set current_position to the position of the new nozzle.
  330. * Offsets are based on linear distance, so we need to get
  331. * the resulting position in coordinate space.
  332. *
  333. * - With grid or 3-point leveling, offset XYZ by a tilted vector
  334. * - With mesh leveling, update Z for the new position
  335. * - Otherwise, just use the raw linear distance
  336. *
  337. * Software endstops are altered here too. Consider a case where:
  338. * E0 at X=0 ... E1 at X=10
  339. * When we switch to E1 now X=10, but E1 can't move left.
  340. * To express this we apply the change in XY to the software endstops.
  341. * E1 can move farther right than E0, so the right limit is extended.
  342. *
  343. * Note that we don't adjust the Z software endstops. Why not?
  344. * Consider a case where Z=0 (here) and switching to E1 makes Z=1
  345. * because the bed is 1mm lower at the new position. As long as
  346. * the first nozzle is out of the way, the carriage should be
  347. * allowed to move 1mm lower. This technically "breaks" the
  348. * Z software endstop. But this is technically correct (and
  349. * there is no viable alternative).
  350. */
  351. #if ABL_PLANAR
  352. // Offset extruder, make sure to apply the bed level rotation matrix
  353. vector_3 tmp_offset_vec = vector_3(hotend_offset[X_AXIS][tmp_extruder],
  354. hotend_offset[Y_AXIS][tmp_extruder],
  355. 0),
  356. act_offset_vec = vector_3(hotend_offset[X_AXIS][active_extruder],
  357. hotend_offset[Y_AXIS][active_extruder],
  358. 0),
  359. offset_vec = tmp_offset_vec - act_offset_vec;
  360. #if ENABLED(DEBUG_LEVELING_FEATURE)
  361. if (DEBUGGING(LEVELING)) {
  362. tmp_offset_vec.debug(PSTR("tmp_offset_vec"));
  363. act_offset_vec.debug(PSTR("act_offset_vec"));
  364. offset_vec.debug(PSTR("offset_vec (BEFORE)"));
  365. }
  366. #endif
  367. offset_vec.apply_rotation(planner.bed_level_matrix.transpose(planner.bed_level_matrix));
  368. #if ENABLED(DEBUG_LEVELING_FEATURE)
  369. if (DEBUGGING(LEVELING)) offset_vec.debug(PSTR("offset_vec (AFTER)"));
  370. #endif
  371. // Adjustments to the current position
  372. const float xydiff[2] = { offset_vec.x, offset_vec.y };
  373. current_position[Z_AXIS] += offset_vec.z;
  374. #else // !ABL_PLANAR
  375. const float xydiff[2] = {
  376. hotend_offset[X_AXIS][tmp_extruder] - hotend_offset[X_AXIS][active_extruder],
  377. hotend_offset[Y_AXIS][tmp_extruder] - hotend_offset[Y_AXIS][active_extruder]
  378. };
  379. #if ENABLED(MESH_BED_LEVELING)
  380. if (leveling_is_active()) {
  381. #if ENABLED(DEBUG_LEVELING_FEATURE)
  382. if (DEBUGGING(LEVELING)) SERIAL_ECHOPAIR("Z before MBL: ", current_position[Z_AXIS]);
  383. #endif
  384. float x2 = current_position[X_AXIS] + xydiff[X_AXIS],
  385. y2 = current_position[Y_AXIS] + xydiff[Y_AXIS],
  386. z1 = current_position[Z_AXIS], z2 = z1;
  387. planner.apply_leveling(current_position[X_AXIS], current_position[Y_AXIS], z1);
  388. planner.apply_leveling(x2, y2, z2);
  389. current_position[Z_AXIS] += z2 - z1;
  390. #if ENABLED(DEBUG_LEVELING_FEATURE)
  391. if (DEBUGGING(LEVELING))
  392. SERIAL_ECHOLNPAIR(" after: ", current_position[Z_AXIS]);
  393. #endif
  394. }
  395. #endif // MESH_BED_LEVELING
  396. #endif // !HAS_ABL
  397. #if ENABLED(DEBUG_LEVELING_FEATURE)
  398. if (DEBUGGING(LEVELING)) {
  399. SERIAL_ECHOPAIR("Offset Tool XY by { ", xydiff[X_AXIS]);
  400. SERIAL_ECHOPAIR(", ", xydiff[Y_AXIS]);
  401. SERIAL_ECHOLNPGM(" }");
  402. }
  403. #endif
  404. // The newly-selected extruder XY is actually at...
  405. current_position[X_AXIS] += xydiff[X_AXIS];
  406. current_position[Y_AXIS] += xydiff[Y_AXIS];
  407. #if HAS_WORKSPACE_OFFSET || ENABLED(DUAL_X_CARRIAGE) || ENABLED(PARKING_EXTRUDER)
  408. for (uint8_t i = X_AXIS; i <= Y_AXIS; i++) {
  409. #if HAS_POSITION_SHIFT
  410. position_shift[i] += xydiff[i];
  411. #endif
  412. update_software_endstops((AxisEnum)i);
  413. }
  414. #endif
  415. // Set the new active extruder
  416. active_extruder = tmp_extruder;
  417. #endif // !DUAL_X_CARRIAGE
  418. #if ENABLED(DEBUG_LEVELING_FEATURE)
  419. if (DEBUGGING(LEVELING)) DEBUG_POS("Sync After Toolchange", current_position);
  420. #endif
  421. // Tell the planner the new "current position"
  422. SYNC_PLAN_POSITION_KINEMATIC();
  423. // Move to the "old position" (move the extruder into place)
  424. if (!no_move && IsRunning()) {
  425. #if ENABLED(DEBUG_LEVELING_FEATURE)
  426. if (DEBUGGING(LEVELING)) DEBUG_POS("Move back", destination);
  427. #endif
  428. prepare_move_to_destination();
  429. }
  430. #if ENABLED(SWITCHING_NOZZLE)
  431. // Move back down, if needed. (Including when the new tool is higher.)
  432. if (z_raise != z_diff) {
  433. destination[Z_AXIS] += z_diff;
  434. feedrate_mm_s = planner.max_feedrate_mm_s[Z_AXIS];
  435. prepare_move_to_destination();
  436. }
  437. #endif
  438. } // (tmp_extruder != active_extruder)
  439. stepper.synchronize();
  440. #if ENABLED(EXT_SOLENOID) && !ENABLED(PARKING_EXTRUDER)
  441. disable_all_solenoids();
  442. enable_solenoid_on_active_extruder();
  443. #endif // EXT_SOLENOID
  444. feedrate_mm_s = old_feedrate_mm_s;
  445. #else // HOTENDS <= 1
  446. UNUSED(fr_mm_s);
  447. UNUSED(no_move);
  448. #if ENABLED(MK2_MULTIPLEXER)
  449. if (tmp_extruder >= E_STEPPERS)
  450. return invalid_extruder_error(tmp_extruder);
  451. select_multiplexed_stepper(tmp_extruder);
  452. #endif
  453. // Set the new active extruder
  454. active_extruder = tmp_extruder;
  455. #endif // HOTENDS <= 1
  456. #if ENABLED(SWITCHING_EXTRUDER) && !DONT_SWITCH
  457. stepper.synchronize();
  458. move_extruder_servo(active_extruder);
  459. #endif
  460. #if HAS_FANMUX
  461. fanmux_switch(active_extruder);
  462. #endif
  463. SERIAL_ECHO_START();
  464. SERIAL_ECHOLNPAIR(MSG_ACTIVE_EXTRUDER, (int)active_extruder);
  465. #endif // !MIXING_EXTRUDER || MIXING_VIRTUAL_TOOLS <= 1
  466. }