My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

tool_change.cpp 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  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(SWITCHING_EXTRUDER) || ENABLED(SWITCHING_NOZZLE)
  32. #include "../module/servo.h"
  33. #endif
  34. #if ENABLED(EXT_SOLENOID) && !ENABLED(PARKING_EXTRUDER)
  35. #include "../feature/solenoid.h"
  36. #endif
  37. #if ENABLED(MK2_MULTIPLEXER)
  38. #include "../feature/snmm.h"
  39. #endif
  40. #if ENABLED(MIXING_EXTRUDER)
  41. #include "../feature/mixing.h"
  42. #endif
  43. #if HAS_LEVELING
  44. #include "../feature/bedlevel/bedlevel.h"
  45. #endif
  46. #if HAS_FANMUX
  47. #include "../feature/fanmux.h"
  48. #endif
  49. #if ENABLED(SWITCHING_EXTRUDER)
  50. #if EXTRUDERS > 3
  51. #define REQ_ANGLES 4
  52. #define _SERVO_NR (e < 2 ? SWITCHING_EXTRUDER_SERVO_NR : SWITCHING_EXTRUDER_E23_SERVO_NR)
  53. #else
  54. #define REQ_ANGLES 2
  55. #define _SERVO_NR SWITCHING_EXTRUDER_SERVO_NR
  56. #endif
  57. void move_extruder_servo(const uint8_t e) {
  58. constexpr int16_t angles[] = SWITCHING_EXTRUDER_SERVO_ANGLES;
  59. static_assert(COUNT(angles) == REQ_ANGLES, "SWITCHING_EXTRUDER_SERVO_ANGLES needs " STRINGIFY(REQ_ANGLES) " angles.");
  60. stepper.synchronize();
  61. #if EXTRUDERS & 1
  62. if (e < EXTRUDERS - 1)
  63. #endif
  64. {
  65. MOVE_SERVO(_SERVO_NR, angles[e]);
  66. safe_delay(500);
  67. }
  68. }
  69. #endif // SWITCHING_EXTRUDER
  70. #if ENABLED(SWITCHING_NOZZLE)
  71. void move_nozzle_servo(const uint8_t e) {
  72. const int16_t angles[2] = SWITCHING_NOZZLE_SERVO_ANGLES;
  73. stepper.synchronize();
  74. MOVE_SERVO(SWITCHING_NOZZLE_SERVO_NR, angles[e]);
  75. safe_delay(500);
  76. }
  77. #endif // SWITCHING_NOZZLE
  78. #if ENABLED(PARKING_EXTRUDER)
  79. void pe_magnet_init() {
  80. for (uint8_t n = 0; n <= 1; ++n)
  81. #if ENABLED(PARKING_EXTRUDER_SOLENOIDS_INVERT)
  82. pe_activate_magnet(n);
  83. #else
  84. pe_deactivate_magnet(n);
  85. #endif
  86. }
  87. void pe_set_magnet(const uint8_t extruder_num, const uint8_t state) {
  88. switch (extruder_num) {
  89. case 1: OUT_WRITE(SOL1_PIN, state); break;
  90. default: OUT_WRITE(SOL0_PIN, state); break;
  91. }
  92. #if PARKING_EXTRUDER_SOLENOIDS_DELAY > 0
  93. gcode.dwell(PARKING_EXTRUDER_SOLENOIDS_DELAY);
  94. #endif
  95. }
  96. #endif // PARKING_EXTRUDER
  97. inline void invalid_extruder_error(const uint8_t e) {
  98. SERIAL_ECHO_START();
  99. SERIAL_CHAR('T');
  100. SERIAL_ECHO_F(e, DEC);
  101. SERIAL_CHAR(' ');
  102. SERIAL_ECHOLN(MSG_INVALID_EXTRUDER);
  103. }
  104. /**
  105. * Perform a tool-change, which may result in moving the
  106. * previous tool out of the way and the new tool into place.
  107. */
  108. void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool no_move/*=false*/) {
  109. #if ENABLED(MIXING_EXTRUDER) && MIXING_VIRTUAL_TOOLS > 1
  110. if (tmp_extruder >= MIXING_VIRTUAL_TOOLS)
  111. return invalid_extruder_error(tmp_extruder);
  112. // T0-Tnnn: Switch virtual tool by changing the mix
  113. for (uint8_t j = 0; j < MIXING_STEPPERS; j++)
  114. mixing_factor[j] = mixing_virtual_tool_mix[tmp_extruder][j];
  115. #else // !MIXING_EXTRUDER || MIXING_VIRTUAL_TOOLS <= 1
  116. if (tmp_extruder >= EXTRUDERS)
  117. return invalid_extruder_error(tmp_extruder);
  118. #if HOTENDS > 1
  119. const float old_feedrate_mm_s = fr_mm_s > 0.0 ? fr_mm_s : feedrate_mm_s;
  120. feedrate_mm_s = fr_mm_s > 0.0 ? fr_mm_s : XY_PROBE_FEEDRATE_MM_S;
  121. if (tmp_extruder != active_extruder) {
  122. if (!no_move && axis_unhomed_error()) {
  123. no_move = true;
  124. #if ENABLED(DEBUG_LEVELING_FEATURE)
  125. if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("No move on toolchange");
  126. #endif
  127. }
  128. // Save current position to destination, for use later
  129. set_destination_from_current();
  130. #if ENABLED(DUAL_X_CARRIAGE)
  131. #if ENABLED(DEBUG_LEVELING_FEATURE)
  132. if (DEBUGGING(LEVELING)) {
  133. SERIAL_ECHOPGM("Dual X Carriage Mode ");
  134. switch (dual_x_carriage_mode) {
  135. case DXC_FULL_CONTROL_MODE: SERIAL_ECHOLNPGM("DXC_FULL_CONTROL_MODE"); break;
  136. case DXC_AUTO_PARK_MODE: SERIAL_ECHOLNPGM("DXC_AUTO_PARK_MODE"); break;
  137. case DXC_DUPLICATION_MODE: SERIAL_ECHOLNPGM("DXC_DUPLICATION_MODE"); break;
  138. }
  139. }
  140. #endif
  141. const float xhome = x_home_pos(active_extruder);
  142. if (dual_x_carriage_mode == DXC_AUTO_PARK_MODE
  143. && IsRunning()
  144. && (delayed_move_time || current_position[X_AXIS] != xhome)
  145. ) {
  146. float raised_z = current_position[Z_AXIS] + TOOLCHANGE_PARK_ZLIFT;
  147. #if ENABLED(MAX_SOFTWARE_ENDSTOPS)
  148. NOMORE(raised_z, soft_endstop_max[Z_AXIS]);
  149. #endif
  150. #if ENABLED(DEBUG_LEVELING_FEATURE)
  151. if (DEBUGGING(LEVELING)) {
  152. SERIAL_ECHOLNPAIR("Raise to ", raised_z);
  153. SERIAL_ECHOLNPAIR("MoveX to ", xhome);
  154. SERIAL_ECHOLNPAIR("Lower to ", current_position[Z_AXIS]);
  155. }
  156. #endif
  157. // Park old head: 1) raise 2) move to park position 3) lower
  158. for (uint8_t i = 0; i < 3; i++)
  159. planner.buffer_line(
  160. i == 0 ? current_position[X_AXIS] : xhome,
  161. current_position[Y_AXIS],
  162. i == 2 ? current_position[Z_AXIS] : raised_z,
  163. current_position[E_AXIS],
  164. planner.max_feedrate_mm_s[i == 1 ? X_AXIS : Z_AXIS],
  165. active_extruder
  166. );
  167. stepper.synchronize();
  168. }
  169. // Apply Y & Z extruder offset (X offset is used as home pos with Dual X)
  170. current_position[Y_AXIS] -= hotend_offset[Y_AXIS][active_extruder] - hotend_offset[Y_AXIS][tmp_extruder];
  171. current_position[Z_AXIS] -= hotend_offset[Z_AXIS][active_extruder] - hotend_offset[Z_AXIS][tmp_extruder];
  172. // Activate the new extruder ahead of calling set_axis_is_at_home!
  173. active_extruder = tmp_extruder;
  174. // This function resets the max/min values - the current position may be overwritten below.
  175. set_axis_is_at_home(X_AXIS);
  176. #if ENABLED(DEBUG_LEVELING_FEATURE)
  177. if (DEBUGGING(LEVELING)) DEBUG_POS("New Extruder", current_position);
  178. #endif
  179. // Only when auto-parking are carriages safe to move
  180. if (dual_x_carriage_mode != DXC_AUTO_PARK_MODE) no_move = true;
  181. switch (dual_x_carriage_mode) {
  182. case DXC_FULL_CONTROL_MODE:
  183. // New current position is the position of the activated extruder
  184. current_position[X_AXIS] = inactive_extruder_x_pos;
  185. // Save the inactive extruder's position (from the old current_position)
  186. inactive_extruder_x_pos = destination[X_AXIS];
  187. break;
  188. case DXC_AUTO_PARK_MODE:
  189. // record raised toolhead position for use by unpark
  190. COPY(raised_parked_position, current_position);
  191. raised_parked_position[Z_AXIS] += TOOLCHANGE_UNPARK_ZLIFT;
  192. #if ENABLED(MAX_SOFTWARE_ENDSTOPS)
  193. NOMORE(raised_parked_position[Z_AXIS], soft_endstop_max[Z_AXIS]);
  194. #endif
  195. active_extruder_parked = true;
  196. delayed_move_time = 0;
  197. break;
  198. case DXC_DUPLICATION_MODE:
  199. // If the new extruder is the left one, set it "parked"
  200. // This triggers the second extruder to move into the duplication position
  201. active_extruder_parked = (active_extruder == 0);
  202. if (active_extruder_parked)
  203. current_position[X_AXIS] = inactive_extruder_x_pos;
  204. else
  205. current_position[X_AXIS] = destination[X_AXIS] + duplicate_extruder_x_offset;
  206. inactive_extruder_x_pos = destination[X_AXIS];
  207. extruder_duplication_enabled = false;
  208. #if ENABLED(DEBUG_LEVELING_FEATURE)
  209. if (DEBUGGING(LEVELING)) {
  210. SERIAL_ECHOLNPAIR("Set inactive_extruder_x_pos=", inactive_extruder_x_pos);
  211. SERIAL_ECHOLNPGM("Clear extruder_duplication_enabled");
  212. }
  213. #endif
  214. break;
  215. }
  216. #if ENABLED(DEBUG_LEVELING_FEATURE)
  217. if (DEBUGGING(LEVELING)) {
  218. SERIAL_ECHOLNPAIR("Active extruder parked: ", active_extruder_parked ? "yes" : "no");
  219. DEBUG_POS("New extruder (parked)", current_position);
  220. }
  221. #endif
  222. // No extra case for HAS_ABL in DUAL_X_CARRIAGE. Does that mean they don't work together?
  223. #else // !DUAL_X_CARRIAGE
  224. #if ENABLED(PARKING_EXTRUDER) // Dual Parking extruder
  225. float z_raise = PARKING_EXTRUDER_SECURITY_RAISE;
  226. if (!no_move) {
  227. const float parkingposx[] = PARKING_EXTRUDER_PARKING_X,
  228. midpos = ((parkingposx[1] - parkingposx[0])/2) + parkingposx[0] + hotend_offset[X_AXIS][active_extruder],
  229. grabpos = parkingposx[tmp_extruder] + hotend_offset[X_AXIS][active_extruder]
  230. + (tmp_extruder == 0 ? -(PARKING_EXTRUDER_GRAB_DISTANCE) : PARKING_EXTRUDER_GRAB_DISTANCE);
  231. /**
  232. * Steps:
  233. * 1. Raise Z-Axis to give enough clearance
  234. * 2. Move to park position of old extruder
  235. * 3. Disengage magnetic field, wait for delay
  236. * 4. Move near new extruder
  237. * 5. Engage magnetic field for new extruder
  238. * 6. Move to parking incl. offset of new extruder
  239. * 7. Lower Z-Axis
  240. */
  241. // STEP 1
  242. #if ENABLED(DEBUG_LEVELING_FEATURE)
  243. SERIAL_ECHOLNPGM("Starting Autopark");
  244. if (DEBUGGING(LEVELING)) DEBUG_POS("current position:", current_position);
  245. #endif
  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 (planner.leveling_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. // Set the new active extruder
  408. active_extruder = tmp_extruder;
  409. #endif // !DUAL_X_CARRIAGE
  410. #if ENABLED(DEBUG_LEVELING_FEATURE)
  411. if (DEBUGGING(LEVELING)) DEBUG_POS("Sync After Toolchange", current_position);
  412. #endif
  413. // Tell the planner the new "current position"
  414. SYNC_PLAN_POSITION_KINEMATIC();
  415. // Move to the "old position" (move the extruder into place)
  416. #if ENABLED(SWITCHING_NOZZLE)
  417. destination[Z_AXIS] += z_diff; // Include the Z restore with the "move back"
  418. #endif
  419. if (!no_move && IsRunning()) {
  420. #if ENABLED(DEBUG_LEVELING_FEATURE)
  421. if (DEBUGGING(LEVELING)) DEBUG_POS("Move back", destination);
  422. #endif
  423. // Move back to the original (or tweaked) position
  424. do_blocking_move_to(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS]);
  425. }
  426. #if ENABLED(SWITCHING_NOZZLE)
  427. else {
  428. // Move back down. (Including when the new tool is higher.)
  429. do_blocking_move_to_z(destination[Z_AXIS], planner.max_feedrate_mm_s[Z_AXIS]);
  430. }
  431. #endif
  432. } // (tmp_extruder != active_extruder)
  433. stepper.synchronize();
  434. #if ENABLED(EXT_SOLENOID) && !ENABLED(PARKING_EXTRUDER)
  435. disable_all_solenoids();
  436. enable_solenoid_on_active_extruder();
  437. #endif // EXT_SOLENOID
  438. feedrate_mm_s = old_feedrate_mm_s;
  439. #else // HOTENDS <= 1
  440. UNUSED(fr_mm_s);
  441. UNUSED(no_move);
  442. #if ENABLED(MK2_MULTIPLEXER)
  443. if (tmp_extruder >= E_STEPPERS)
  444. return invalid_extruder_error(tmp_extruder);
  445. select_multiplexed_stepper(tmp_extruder);
  446. #endif
  447. // Set the new active extruder
  448. active_extruder = tmp_extruder;
  449. #endif // HOTENDS <= 1
  450. #if ENABLED(SWITCHING_EXTRUDER) && !DONT_SWITCH
  451. stepper.synchronize();
  452. move_extruder_servo(active_extruder);
  453. #endif
  454. #if HAS_FANMUX
  455. fanmux_switch(active_extruder);
  456. #endif
  457. SERIAL_ECHO_START();
  458. SERIAL_ECHOLNPAIR(MSG_ACTIVE_EXTRUDER, (int)active_extruder);
  459. #endif // !MIXING_EXTRUDER || MIXING_VIRTUAL_TOOLS <= 1
  460. }