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

tool_change.cpp 22KB

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