Fix single nozzle temp change, do slower extra prime (#14696)

This commit is contained in:
InsanityAutomation 2019-07-21 20:33:37 -04:00 committed by Scott Lahteine
parent e5aa453293
commit dc6fa04f68
2 changed files with 96 additions and 92 deletions

View file

@ -44,10 +44,10 @@
void GcodeSuite::M900() { void GcodeSuite::M900() {
#if EXTRUDERS < 2 #if EXTRUDERS < 2
constexpr uint8_t tmp_extruder = 0; constexpr uint8_t tool_index = 0;
#else #else
const uint8_t tmp_extruder = parser.intval('T', active_extruder); const uint8_t tool_index = parser.intval('T', active_extruder);
if (tmp_extruder >= EXTRUDERS) { if (tool_index >= EXTRUDERS) {
SERIAL_ECHOLNPGM("?T value out of range."); SERIAL_ECHOLNPGM("?T value out of range.");
return; return;
} }
@ -55,17 +55,17 @@ void GcodeSuite::M900() {
#if ENABLED(EXTRA_LIN_ADVANCE_K) #if ENABLED(EXTRA_LIN_ADVANCE_K)
bool ext_slot = TEST(lin_adv_slot, tmp_extruder); bool ext_slot = TEST(lin_adv_slot, tool_index);
if (parser.seenval('S')) { if (parser.seenval('S')) {
const bool slot = parser.value_bool(); const bool slot = parser.value_bool();
if (ext_slot != slot) { if (ext_slot != slot) {
ext_slot = slot; ext_slot = slot;
SET_BIT_TO(lin_adv_slot, tmp_extruder, slot); SET_BIT_TO(lin_adv_slot, tool_index, slot);
planner.synchronize(); planner.synchronize();
const float temp = planner.extruder_advance_K[tmp_extruder]; const float temp = planner.extruder_advance_K[tool_index];
planner.extruder_advance_K[tmp_extruder] = saved_extruder_advance_K[tmp_extruder]; planner.extruder_advance_K[tool_index] = saved_extruder_advance_K[tool_index];
saved_extruder_advance_K[tmp_extruder] = temp; saved_extruder_advance_K[tool_index] = temp;
} }
} }
@ -73,10 +73,10 @@ void GcodeSuite::M900() {
const float newK = parser.value_float(); const float newK = parser.value_float();
if (WITHIN(newK, 0, 10)) { if (WITHIN(newK, 0, 10)) {
if (ext_slot) if (ext_slot)
saved_extruder_advance_K[tmp_extruder] = newK; saved_extruder_advance_K[tool_index] = newK;
else { else {
planner.synchronize(); planner.synchronize();
planner.extruder_advance_K[tmp_extruder] = newK; planner.extruder_advance_K[tool_index] = newK;
} }
} }
else else
@ -87,10 +87,10 @@ void GcodeSuite::M900() {
const float newL = parser.value_float(); const float newL = parser.value_float();
if (WITHIN(newL, 0, 10)) { if (WITHIN(newL, 0, 10)) {
if (!ext_slot) if (!ext_slot)
saved_extruder_advance_K[tmp_extruder] = newL; saved_extruder_advance_K[tool_index] = newL;
else { else {
planner.synchronize(); planner.synchronize();
planner.extruder_advance_K[tmp_extruder] = newL; planner.extruder_advance_K[tool_index] = newL;
} }
} }
else else
@ -117,7 +117,7 @@ void GcodeSuite::M900() {
const float newK = parser.value_float(); const float newK = parser.value_float();
if (WITHIN(newK, 0, 10)) { if (WITHIN(newK, 0, 10)) {
planner.synchronize(); planner.synchronize();
planner.extruder_advance_K[tmp_extruder] = newK; planner.extruder_advance_K[tool_index] = newK;
} }
else else
SERIAL_ECHOLNPGM("?K value out of range (0-10)."); SERIAL_ECHOLNPGM("?K value out of range (0-10).");

View file

@ -146,10 +146,10 @@ inline void fast_line_to_current(const AxisEnum fr_axis) {
parkingtraveldistance, // M951 D parkingtraveldistance, // M951 D
compensationmultiplier; compensationmultiplier;
inline void magnetic_parking_extruder_tool_change(const uint8_t tmp_extruder) { inline void magnetic_parking_extruder_tool_change(const uint8_t new_tool) {
const float oldx = current_position[X_AXIS], const float oldx = current_position[X_AXIS],
grabpos = mpe_settings.parking_xpos[tmp_extruder] + (tmp_extruder ? mpe_settings.grab_distance : -mpe_settings.grab_distance), grabpos = mpe_settings.parking_xpos[new_tool] + (new_tool ? mpe_settings.grab_distance : -mpe_settings.grab_distance),
offsetcompensation = offsetcompensation =
#if HAS_HOTEND_OFFSET #if HAS_HOTEND_OFFSET
hotend_offset[X_AXIS][active_extruder] * mpe_settings.compensation_factor hotend_offset[X_AXIS][active_extruder] * mpe_settings.compensation_factor
@ -174,14 +174,14 @@ inline void fast_line_to_current(const AxisEnum fr_axis) {
// STEP 1 // STEP 1
current_position[X_AXIS] = mpe_settings.parking_xpos[tmp_extruder] + offsetcompensation; current_position[X_AXIS] = mpe_settings.parking_xpos[new_tool] + offsetcompensation;
if (DEBUGGING(LEVELING)) { if (DEBUGGING(LEVELING)) {
DEBUG_ECHOPAIR("(1) Move extruder ", int(tmp_extruder)); DEBUG_ECHOPAIR("(1) Move extruder ", int(new_tool));
DEBUG_POS(" to new extruder ParkPos", current_position); DEBUG_POS(" to new extruder ParkPos", current_position);
} }
planner.buffer_line(current_position, mpe_settings.fast_feedrate, tmp_extruder); planner.buffer_line(current_position, mpe_settings.fast_feedrate, new_tool);
planner.synchronize(); planner.synchronize();
// STEP 2 // STEP 2
@ -189,11 +189,11 @@ inline void fast_line_to_current(const AxisEnum fr_axis) {
current_position[X_AXIS] = grabpos + offsetcompensation; current_position[X_AXIS] = grabpos + offsetcompensation;
if (DEBUGGING(LEVELING)) { if (DEBUGGING(LEVELING)) {
DEBUG_ECHOPAIR("(2) Couple extruder ", int(tmp_extruder)); DEBUG_ECHOPAIR("(2) Couple extruder ", int(new_tool));
DEBUG_POS(" to new extruder GrabPos", current_position); DEBUG_POS(" to new extruder GrabPos", current_position);
} }
planner.buffer_line(current_position, mpe_settings.slow_feedrate, tmp_extruder); planner.buffer_line(current_position, mpe_settings.slow_feedrate, new_tool);
planner.synchronize(); planner.synchronize();
// Delay before moving tool, to allow magnetic coupling // Delay before moving tool, to allow magnetic coupling
@ -201,24 +201,24 @@ inline void fast_line_to_current(const AxisEnum fr_axis) {
// STEP 3 // STEP 3
current_position[X_AXIS] = mpe_settings.parking_xpos[tmp_extruder] + offsetcompensation; current_position[X_AXIS] = mpe_settings.parking_xpos[new_tool] + offsetcompensation;
if (DEBUGGING(LEVELING)) { if (DEBUGGING(LEVELING)) {
DEBUG_ECHOPAIR("(3) Move extruder ", int(tmp_extruder)); DEBUG_ECHOPAIR("(3) Move extruder ", int(new_tool));
DEBUG_POS(" back to new extruder ParkPos", current_position); DEBUG_POS(" back to new extruder ParkPos", current_position);
} }
planner.buffer_line(current_position, mpe_settings.slow_feedrate, tmp_extruder); planner.buffer_line(current_position, mpe_settings.slow_feedrate, new_tool);
planner.synchronize(); planner.synchronize();
// STEP 4 // STEP 4
current_position[X_AXIS] = mpe_settings.parking_xpos[active_extruder] + (active_extruder == 0 ? MPE_TRAVEL_DISTANCE : -MPE_TRAVEL_DISTANCE) + offsetcompensation; current_position[X_AXIS] = mpe_settings.parking_xpos[active_extruder] + (active_extruder == 0 ? MPE_TRAVEL_DISTANCE : -MPE_TRAVEL_DISTANCE) + offsetcompensation;
if (DEBUGGING(LEVELING)) { if (DEBUGGING(LEVELING)) {
DEBUG_ECHOPAIR("(4) Move extruder ", int(tmp_extruder)); DEBUG_ECHOPAIR("(4) Move extruder ", int(new_tool));
DEBUG_POS(" close to old extruder ParkPos", current_position); DEBUG_POS(" close to old extruder ParkPos", current_position);
} }
planner.buffer_line(current_position, mpe_settings.fast_feedrate, tmp_extruder); planner.buffer_line(current_position, mpe_settings.fast_feedrate, new_tool);
planner.synchronize(); planner.synchronize();
// STEP 5 // STEP 5
@ -226,11 +226,11 @@ inline void fast_line_to_current(const AxisEnum fr_axis) {
current_position[X_AXIS] = mpe_settings.parking_xpos[active_extruder] + offsetcompensation; current_position[X_AXIS] = mpe_settings.parking_xpos[active_extruder] + offsetcompensation;
if (DEBUGGING(LEVELING)) { if (DEBUGGING(LEVELING)) {
DEBUG_ECHOPAIR("(5) Park extruder ", int(tmp_extruder)); DEBUG_ECHOPAIR("(5) Park extruder ", int(new_tool));
DEBUG_POS(" at old extruder ParkPos", current_position); DEBUG_POS(" at old extruder ParkPos", current_position);
} }
planner.buffer_line(current_position, mpe_settings.slow_feedrate, tmp_extruder); planner.buffer_line(current_position, mpe_settings.slow_feedrate, new_tool);
planner.synchronize(); planner.synchronize();
// STEP 6 // STEP 6
@ -238,11 +238,11 @@ inline void fast_line_to_current(const AxisEnum fr_axis) {
current_position[X_AXIS] = oldx; current_position[X_AXIS] = oldx;
if (DEBUGGING(LEVELING)) { if (DEBUGGING(LEVELING)) {
DEBUG_ECHOPAIR("(6) Move extruder ", int(tmp_extruder)); DEBUG_ECHOPAIR("(6) Move extruder ", int(new_tool));
DEBUG_POS(" to starting position", current_position); DEBUG_POS(" to starting position", current_position);
} }
planner.buffer_line(current_position, mpe_settings.fast_feedrate, tmp_extruder); planner.buffer_line(current_position, mpe_settings.fast_feedrate, new_tool);
planner.synchronize(); planner.synchronize();
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Autopark done."); if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Autopark done.");
@ -269,7 +269,7 @@ inline void fast_line_to_current(const AxisEnum fr_axis) {
#endif #endif
} }
inline void parking_extruder_tool_change(const uint8_t tmp_extruder, bool no_move) { inline void parking_extruder_tool_change(const uint8_t new_tool, bool no_move) {
if (!no_move) { if (!no_move) {
constexpr float parkingposx[] = PARKING_EXTRUDER_PARKING_X; constexpr float parkingposx[] = PARKING_EXTRUDER_PARKING_X;
@ -281,7 +281,7 @@ inline void fast_line_to_current(const AxisEnum fr_axis) {
#endif #endif
const float midpos = (parkingposx[0] + parkingposx[1]) * 0.5 + x_offset, const float midpos = (parkingposx[0] + parkingposx[1]) * 0.5 + x_offset,
grabpos = parkingposx[tmp_extruder] + (tmp_extruder ? PARKING_EXTRUDER_GRAB_DISTANCE : -(PARKING_EXTRUDER_GRAB_DISTANCE)) + x_offset; grabpos = parkingposx[new_tool] + (new_tool ? PARKING_EXTRUDER_GRAB_DISTANCE : -(PARKING_EXTRUDER_GRAB_DISTANCE)) + x_offset;
/** /**
* 1. Move to park position of old extruder * 1. Move to park position of old extruder
@ -325,11 +325,11 @@ inline void fast_line_to_current(const AxisEnum fr_axis) {
#if ENABLED(PARKING_EXTRUDER_SOLENOIDS_INVERT) #if ENABLED(PARKING_EXTRUDER_SOLENOIDS_INVERT)
pe_activate_solenoid(active_extruder); // Just save power for inverted magnets pe_activate_solenoid(active_extruder); // Just save power for inverted magnets
#endif #endif
pe_activate_solenoid(tmp_extruder); pe_activate_solenoid(new_tool);
// STEP 5 // STEP 5
current_position[X_AXIS] = grabpos + (tmp_extruder ? -10 : 10); current_position[X_AXIS] = grabpos + (new_tool ? -10 : 10);
fast_line_to_current(X_AXIS); fast_line_to_current(X_AXIS);
current_position[X_AXIS] = grabpos; current_position[X_AXIS] = grabpos;
@ -343,7 +343,7 @@ inline void fast_line_to_current(const AxisEnum fr_axis) {
current_position[X_AXIS] = midpos current_position[X_AXIS] = midpos
#if HAS_HOTEND_OFFSET #if HAS_HOTEND_OFFSET
- hotend_offset[X_AXIS][tmp_extruder] - hotend_offset[X_AXIS][new_tool]
#endif #endif
; ;
if (DEBUGGING(LEVELING)) { if (DEBUGGING(LEVELING)) {
@ -357,7 +357,7 @@ inline void fast_line_to_current(const AxisEnum fr_axis) {
} }
else { // nomove == true else { // nomove == true
// Only engage magnetic field for new extruder // Only engage magnetic field for new extruder
pe_activate_solenoid(tmp_extruder); pe_activate_solenoid(new_tool);
#if ENABLED(PARKING_EXTRUDER_SOLENOIDS_INVERT) #if ENABLED(PARKING_EXTRUDER_SOLENOIDS_INVERT)
pe_activate_solenoid(active_extruder); // Just save power for inverted magnets pe_activate_solenoid(active_extruder); // Just save power for inverted magnets
#endif #endif
@ -368,14 +368,14 @@ inline void fast_line_to_current(const AxisEnum fr_axis) {
#if ENABLED(SWITCHING_TOOLHEAD) #if ENABLED(SWITCHING_TOOLHEAD)
inline void switching_toolhead_tool_change(const uint8_t tmp_extruder, bool no_move/*=false*/) { inline void switching_toolhead_tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
if (no_move) return; if (no_move) return;
constexpr uint16_t angles[2] = SWITCHING_TOOLHEAD_SERVO_ANGLES; constexpr uint16_t angles[2] = SWITCHING_TOOLHEAD_SERVO_ANGLES;
constexpr float toolheadposx[] = SWITCHING_TOOLHEAD_X_POS; constexpr float toolheadposx[] = SWITCHING_TOOLHEAD_X_POS;
const float placexpos = toolheadposx[active_extruder], const float placexpos = toolheadposx[active_extruder],
grabxpos = toolheadposx[tmp_extruder]; grabxpos = toolheadposx[new_tool];
/** /**
* 1. Move to switch position of current toolhead * 1. Move to switch position of current toolhead
@ -464,7 +464,7 @@ inline void fast_line_to_current(const AxisEnum fr_axis) {
#elif ENABLED(MAGNETIC_SWITCHING_TOOLHEAD) #elif ENABLED(MAGNETIC_SWITCHING_TOOLHEAD)
inline void magnetic_switching_toolhead_tool_change(const uint8_t tmp_extruder, bool no_move/*=false*/) { inline void magnetic_switching_toolhead_tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
if (no_move) return; if (no_move) return;
constexpr float toolheadposx[] = SWITCHING_TOOLHEAD_X_POS, constexpr float toolheadposx[] = SWITCHING_TOOLHEAD_X_POS,
@ -472,8 +472,8 @@ inline void fast_line_to_current(const AxisEnum fr_axis) {
const float placexpos = toolheadposx[active_extruder], const float placexpos = toolheadposx[active_extruder],
placexclear = toolheadclearx[active_extruder], placexclear = toolheadclearx[active_extruder],
grabxpos = toolheadposx[tmp_extruder], grabxpos = toolheadposx[new_tool],
grabxclear = toolheadclearx[tmp_extruder]; grabxclear = toolheadclearx[new_tool];
/** /**
* 1. Move to switch position of current toolhead * 1. Move to switch position of current toolhead
@ -564,11 +564,11 @@ inline void fast_line_to_current(const AxisEnum fr_axis) {
#if ENABLED(PRIME_BEFORE_REMOVE) && (SWITCHING_TOOLHEAD_PRIME_MM || SWITCHING_TOOLHEAD_RETRACT_MM) #if ENABLED(PRIME_BEFORE_REMOVE) && (SWITCHING_TOOLHEAD_PRIME_MM || SWITCHING_TOOLHEAD_RETRACT_MM)
#if SWITCHING_TOOLHEAD_PRIME_MM #if SWITCHING_TOOLHEAD_PRIME_MM
current_position[E_AXIS] += SWITCHING_TOOLHEAD_PRIME_MM; current_position[E_AXIS] += SWITCHING_TOOLHEAD_PRIME_MM;
planner.buffer_line(current_position, MMM_TO_MMS(SWITCHING_TOOLHEAD_PRIME_FEEDRATE), tmp_extruder); planner.buffer_line(current_position, MMM_TO_MMS(SWITCHING_TOOLHEAD_PRIME_FEEDRATE), new_tool);
#endif #endif
#if SWITCHING_TOOLHEAD_RETRACT_MM #if SWITCHING_TOOLHEAD_RETRACT_MM
current_position[E_AXIS] -= SWITCHING_TOOLHEAD_RETRACT_MM; current_position[E_AXIS] -= SWITCHING_TOOLHEAD_RETRACT_MM;
planner.buffer_line(current_position, MMM_TO_MMS(SWITCHING_TOOLHEAD_RETRACT_FEEDRATE), tmp_extruder); planner.buffer_line(current_position, MMM_TO_MMS(SWITCHING_TOOLHEAD_RETRACT_FEEDRATE), new_tool);
#endif #endif
#else #else
planner.synchronize(); planner.synchronize();
@ -595,12 +595,12 @@ inline void fast_line_to_current(const AxisEnum fr_axis) {
inline void est_deactivate_solenoid() { OUT_WRITE(SOL0_PIN, LOW); } inline void est_deactivate_solenoid() { OUT_WRITE(SOL0_PIN, LOW); }
void est_init() { est_activate_solenoid(); } void est_init() { est_activate_solenoid(); }
inline void em_switching_toolhead_tool_change(const uint8_t tmp_extruder, bool no_move) { inline void em_switching_toolhead_tool_change(const uint8_t new_tool, bool no_move) {
if (no_move) return; if (no_move) return;
constexpr float toolheadposx[] = SWITCHING_TOOLHEAD_X_POS; constexpr float toolheadposx[] = SWITCHING_TOOLHEAD_X_POS;
const float placexpos = toolheadposx[active_extruder], const float placexpos = toolheadposx[active_extruder],
grabxpos = toolheadposx[tmp_extruder]; grabxpos = toolheadposx[new_tool];
/** /**
* 1. Raise Z-Axis to give enough clearance * 1. Raise Z-Axis to give enough clearance
@ -688,7 +688,7 @@ inline void fast_line_to_current(const AxisEnum fr_axis) {
// 9. Apply Z hotend offset to current position // 9. Apply Z hotend offset to current position
if (DEBUGGING(LEVELING)) DEBUG_POS("(9) Applying Z-offset", current_position); if (DEBUGGING(LEVELING)) DEBUG_POS("(9) Applying Z-offset", current_position);
current_position[Z_AXIS] += hotend_offset[Z_AXIS][active_extruder] - hotend_offset[Z_AXIS][tmp_extruder]; current_position[Z_AXIS] += hotend_offset[Z_AXIS][active_extruder] - hotend_offset[Z_AXIS][new_tool];
if (DEBUGGING(LEVELING)) DEBUG_POS("EMST Tool-Change done.", current_position); if (DEBUGGING(LEVELING)) DEBUG_POS("EMST Tool-Change done.", current_position);
} }
@ -703,7 +703,7 @@ inline void invalid_extruder_error(const uint8_t e) {
#if ENABLED(DUAL_X_CARRIAGE) #if ENABLED(DUAL_X_CARRIAGE)
inline void dualx_tool_change(const uint8_t tmp_extruder, bool &no_move) { inline void dualx_tool_change(const uint8_t new_tool, bool &no_move) {
if (DEBUGGING(LEVELING)) { if (DEBUGGING(LEVELING)) {
DEBUG_ECHOPGM("Dual X Carriage Mode "); DEBUG_ECHOPGM("Dual X Carriage Mode ");
switch (dual_x_carriage_mode) { switch (dual_x_carriage_mode) {
@ -728,7 +728,7 @@ inline void invalid_extruder_error(const uint8_t e) {
} }
// Activate the new extruder ahead of calling set_axis_is_at_home! // Activate the new extruder ahead of calling set_axis_is_at_home!
active_extruder = tmp_extruder; active_extruder = new_tool;
// This function resets the max/min values - the current position may be overwritten below. // This function resets the max/min values - the current position may be overwritten below.
set_axis_is_at_home(X_AXIS); set_axis_is_at_home(X_AXIS);
@ -764,35 +764,37 @@ inline void invalid_extruder_error(const uint8_t e) {
* Perform a tool-change, which may result in moving the * Perform a tool-change, which may result in moving the
* previous tool out of the way and the new tool into place. * previous tool out of the way and the new tool into place.
*/ */
void tool_change(const uint8_t tmp_extruder, bool no_move/*=false*/) { void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
#if ENABLED(MAGNETIC_SWITCHING_TOOLHEAD) #if ENABLED(MAGNETIC_SWITCHING_TOOLHEAD)
if (tmp_extruder == active_extruder) return; if (new_tool == active_extruder) return;
#endif #endif
const uint8_t old_tool = active_extruder;
#if ENABLED(MIXING_EXTRUDER) #if ENABLED(MIXING_EXTRUDER)
UNUSED(no_move); UNUSED(no_move);
if (tmp_extruder >= MIXING_VIRTUAL_TOOLS) if (new_tool >= MIXING_VIRTUAL_TOOLS)
return invalid_extruder_error(tmp_extruder); return invalid_extruder_error(new_tool);
#if MIXING_VIRTUAL_TOOLS > 1 #if MIXING_VIRTUAL_TOOLS > 1
// T0-Tnnn: Switch virtual tool by changing the index to the mix // T0-Tnnn: Switch virtual tool by changing the index to the mix
mixer.T(tmp_extruder); mixer.T(new_tool);
#endif #endif
#elif ENABLED(PRUSA_MMU2) #elif ENABLED(PRUSA_MMU2)
UNUSED(no_move); UNUSED(no_move);
mmu2.tool_change(tmp_extruder); mmu2.tool_change(new_tool);
#elif EXTRUDERS < 2 #elif EXTRUDERS < 2
UNUSED(no_move); UNUSED(no_move);
if (tmp_extruder) invalid_extruder_error(tmp_extruder); if (new_tool) invalid_extruder_error(new_tool);
return; return;
#else // EXTRUDERS > 1 #else // EXTRUDERS > 1
@ -800,12 +802,12 @@ void tool_change(const uint8_t tmp_extruder, bool no_move/*=false*/) {
planner.synchronize(); planner.synchronize();
#if ENABLED(DUAL_X_CARRIAGE) // Only T0 allowed if the Printer is in DXC_DUPLICATION_MODE or DXC_MIRRORED_MODE #if ENABLED(DUAL_X_CARRIAGE) // Only T0 allowed if the Printer is in DXC_DUPLICATION_MODE or DXC_MIRRORED_MODE
if (tmp_extruder != 0 && dxc_is_duplicating()) if (new_tool != 0 && dxc_is_duplicating())
return invalid_extruder_error(tmp_extruder); return invalid_extruder_error(new_tool);
#endif #endif
if (tmp_extruder >= EXTRUDERS) if (new_tool >= EXTRUDERS)
return invalid_extruder_error(tmp_extruder); return invalid_extruder_error(new_tool);
if (!no_move && !all_axes_homed()) { if (!no_move && !all_axes_homed()) {
no_move = true; no_move = true;
@ -827,7 +829,7 @@ void tool_change(const uint8_t tmp_extruder, bool no_move/*=false*/) {
#if ENABLED(TOOLCHANGE_FILAMENT_SWAP) #if ENABLED(TOOLCHANGE_FILAMENT_SWAP)
const bool should_swap = can_move_away && toolchange_settings.swap_length; const bool should_swap = can_move_away && toolchange_settings.swap_length;
#if ENABLED(PREVENT_COLD_EXTRUSION) #if ENABLED(PREVENT_COLD_EXTRUSION)
const bool too_cold = !DEBUGGING(DRYRUN) && (thermalManager.targetTooColdToExtrude(active_extruder) || thermalManager.targetTooColdToExtrude(tmp_extruder)); const bool too_cold = !DEBUGGING(DRYRUN) && (thermalManager.targetTooColdToExtrude(old_tool) || thermalManager.targetTooColdToExtrude(new_tool));
#else #else
constexpr bool too_cold = false; constexpr bool too_cold = false;
#endif #endif
@ -835,7 +837,7 @@ void tool_change(const uint8_t tmp_extruder, bool no_move/*=false*/) {
if (too_cold) { if (too_cold) {
SERIAL_ECHO_MSG(MSG_ERR_HOTEND_TOO_COLD); SERIAL_ECHO_MSG(MSG_ERR_HOTEND_TOO_COLD);
#if ENABLED(SINGLENOZZLE) #if ENABLED(SINGLENOZZLE)
active_extruder = tmp_extruder; active_extruder = new_tool;
return; return;
#endif #endif
} }
@ -843,8 +845,8 @@ void tool_change(const uint8_t tmp_extruder, bool no_move/*=false*/) {
#if ENABLED(ADVANCED_PAUSE_FEATURE) #if ENABLED(ADVANCED_PAUSE_FEATURE)
do_pause_e_move(-toolchange_settings.swap_length, MMM_TO_MMS(toolchange_settings.retract_speed)); do_pause_e_move(-toolchange_settings.swap_length, MMM_TO_MMS(toolchange_settings.retract_speed));
#else #else
current_position[E_AXIS] -= toolchange_settings.swap_length / planner.e_factor[active_extruder]; current_position[E_AXIS] -= toolchange_settings.swap_length / planner.e_factor[old_tool];
planner.buffer_line(current_position, MMM_TO_MMS(toolchange_settings.retract_speed), active_extruder); planner.buffer_line(current_position, MMM_TO_MMS(toolchange_settings.retract_speed), old_tool);
planner.synchronize(); planner.synchronize();
#endif #endif
} }
@ -856,17 +858,17 @@ void tool_change(const uint8_t tmp_extruder, bool no_move/*=false*/) {
TEMPORARY_BED_LEVELING_STATE(false); TEMPORARY_BED_LEVELING_STATE(false);
#endif #endif
if (tmp_extruder != active_extruder) { if (new_tool != old_tool) {
#if SWITCHING_NOZZLE_TWO_SERVOS #if SWITCHING_NOZZLE_TWO_SERVOS
raise_nozzle(active_extruder); raise_nozzle(old_tool);
#endif #endif
REMEMBER(fr, feedrate_mm_s, XY_PROBE_FEEDRATE_MM_S); REMEMBER(fr, feedrate_mm_s, XY_PROBE_FEEDRATE_MM_S);
#if HAS_SOFTWARE_ENDSTOPS #if HAS_SOFTWARE_ENDSTOPS
#if HAS_HOTEND_OFFSET #if HAS_HOTEND_OFFSET
#define _EXT_ARGS , active_extruder, tmp_extruder #define _EXT_ARGS , old_tool, new_tool
#else #else
#define _EXT_ARGS #define _EXT_ARGS
#endif #endif
@ -891,7 +893,7 @@ void tool_change(const uint8_t tmp_extruder, bool no_move/*=false*/) {
current_position[X_AXIS] = toolchange_settings.change_point.x; current_position[X_AXIS] = toolchange_settings.change_point.x;
current_position[Y_AXIS] = toolchange_settings.change_point.y; current_position[Y_AXIS] = toolchange_settings.change_point.y;
#endif #endif
planner.buffer_line(current_position, feedrate_mm_s, active_extruder); planner.buffer_line(current_position, feedrate_mm_s, old_tool);
planner.synchronize(); planner.synchronize();
} }
#endif #endif
@ -900,26 +902,26 @@ void tool_change(const uint8_t tmp_extruder, bool no_move/*=false*/) {
#if ENABLED(DUAL_X_CARRIAGE) #if ENABLED(DUAL_X_CARRIAGE)
constexpr float xdiff = 0; constexpr float xdiff = 0;
#else #else
const float xdiff = hotend_offset[X_AXIS][tmp_extruder] - hotend_offset[X_AXIS][active_extruder]; const float xdiff = hotend_offset[X_AXIS][new_tool] - hotend_offset[X_AXIS][old_tool];
#endif #endif
const float ydiff = hotend_offset[Y_AXIS][tmp_extruder] - hotend_offset[Y_AXIS][active_extruder], const float ydiff = hotend_offset[Y_AXIS][new_tool] - hotend_offset[Y_AXIS][old_tool],
zdiff = hotend_offset[Z_AXIS][tmp_extruder] - hotend_offset[Z_AXIS][active_extruder]; zdiff = hotend_offset[Z_AXIS][new_tool] - hotend_offset[Z_AXIS][old_tool];
#else #else
constexpr float xdiff = 0, ydiff = 0, zdiff = 0; constexpr float xdiff = 0, ydiff = 0, zdiff = 0;
#endif #endif
#if ENABLED(DUAL_X_CARRIAGE) #if ENABLED(DUAL_X_CARRIAGE)
dualx_tool_change(tmp_extruder, no_move); dualx_tool_change(new_tool, no_move);
#elif ENABLED(PARKING_EXTRUDER) // Dual Parking extruder #elif ENABLED(PARKING_EXTRUDER) // Dual Parking extruder
parking_extruder_tool_change(tmp_extruder, no_move); parking_extruder_tool_change(new_tool, no_move);
#elif ENABLED(MAGNETIC_PARKING_EXTRUDER) // Magnetic Parking extruder #elif ENABLED(MAGNETIC_PARKING_EXTRUDER) // Magnetic Parking extruder
magnetic_parking_extruder_tool_change(tmp_extruder); magnetic_parking_extruder_tool_change(new_tool);
#elif ENABLED(SWITCHING_TOOLHEAD) // Switching Toolhead #elif ENABLED(SWITCHING_TOOLHEAD) // Switching Toolhead
switching_toolhead_tool_change(tmp_extruder, no_move); switching_toolhead_tool_change(new_tool, no_move);
#elif ENABLED(MAGNETIC_SWITCHING_TOOLHEAD) // Magnetic Switching Toolhead #elif ENABLED(MAGNETIC_SWITCHING_TOOLHEAD) // Magnetic Switching Toolhead
magnetic_switching_toolhead_tool_change(tmp_extruder, no_move); magnetic_switching_toolhead_tool_change(new_tool, no_move);
#elif ENABLED(ELECTROMAGNETIC_SWITCHING_TOOLHEAD) // Magnetic Switching ToolChanger #elif ENABLED(ELECTROMAGNETIC_SWITCHING_TOOLHEAD) // Magnetic Switching ToolChanger
em_switching_toolhead_tool_change(tmp_extruder, no_move); em_switching_toolhead_tool_change(new_tool, no_move);
#elif ENABLED(SWITCHING_NOZZLE) && !SWITCHING_NOZZLE_TWO_SERVOS // Switching Nozzle (single servo) #elif ENABLED(SWITCHING_NOZZLE) && !SWITCHING_NOZZLE_TWO_SERVOS // Switching Nozzle (single servo)
// Raise by a configured distance to avoid workpiece, except with // Raise by a configured distance to avoid workpiece, except with
// SWITCHING_NOZZLE_TWO_SERVOS, as both nozzles will lift instead. // SWITCHING_NOZZLE_TWO_SERVOS, as both nozzles will lift instead.
@ -928,7 +930,7 @@ void tool_change(const uint8_t tmp_extruder, bool no_move/*=false*/) {
NOMORE(current_position[Z_AXIS], soft_endstop[Z_AXIS].max); NOMORE(current_position[Z_AXIS], soft_endstop[Z_AXIS].max);
#endif #endif
if (!no_move) fast_line_to_current(Z_AXIS); if (!no_move) fast_line_to_current(Z_AXIS);
move_nozzle_servo(tmp_extruder); move_nozzle_servo(new_tool);
#endif #endif
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Offset Tool XY by { ", xdiff, ", ", ydiff, ", ", zdiff, " }"); if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Offset Tool XY by { ", xdiff, ", ", ydiff, ", ", zdiff, " }");
@ -939,7 +941,7 @@ void tool_change(const uint8_t tmp_extruder, bool no_move/*=false*/) {
current_position[Z_AXIS] += zdiff; current_position[Z_AXIS] += zdiff;
// Set the new active extruder if not already done in tool specific function above // Set the new active extruder if not already done in tool specific function above
active_extruder = tmp_extruder; active_extruder = new_tool;
// Tell the planner the new "current position" // Tell the planner the new "current position"
sync_plan_position(); sync_plan_position();
@ -956,28 +958,30 @@ void tool_change(const uint8_t tmp_extruder, bool no_move/*=false*/) {
#if ENABLED(SINGLENOZZLE) #if ENABLED(SINGLENOZZLE)
#if FAN_COUNT > 0 #if FAN_COUNT > 0
singlenozzle_fan_speed[active_extruder] = thermalManager.fan_speed[0]; singlenozzle_fan_speed[old_tool] = thermalManager.fan_speed[0];
thermalManager.fan_speed[0] = singlenozzle_fan_speed[tmp_extruder]; thermalManager.fan_speed[0] = singlenozzle_fan_speed[new_tool];
#endif #endif
singlenozzle_temp[active_extruder] = thermalManager.temp_hotend[0].target; singlenozzle_temp[old_tool] = thermalManager.temp_hotend[0].target;
if (singlenozzle_temp[tmp_extruder] && singlenozzle_temp[tmp_extruder] != singlenozzle_temp[active_extruder]) { if (singlenozzle_temp[new_tool] && singlenozzle_temp[new_tool] != singlenozzle_temp[old_tool]) {
thermalManager.setTargetHotend(singlenozzle_temp[tmp_extruder], 0); thermalManager.setTargetHotend(singlenozzle_temp[new_tool], 0);
#if HAS_DISPLAY #if HAS_DISPLAY
thermalManager.set_heating_message(0); thermalManager.set_heating_message(0);
#endif #endif
(void)thermalManager.wait_for_hotend(0, false); // Wait for heating or cooling (void)thermalManager.wait_for_hotend(0, false); // Wait for heating or cooling
} }
active_extruder = tmp_extruder;
#endif #endif
#if ENABLED(TOOLCHANGE_FILAMENT_SWAP) #if ENABLED(TOOLCHANGE_FILAMENT_SWAP)
if (should_swap && !too_cold) { if (should_swap && !too_cold) {
#if ENABLED(ADVANCED_PAUSE_FEATURE) #if ENABLED(ADVANCED_PAUSE_FEATURE)
do_pause_e_move(toolchange_settings.swap_length + toolchange_settings.extra_prime, MMM_TO_MMS(toolchange_settings.prime_speed)); do_pause_e_move(toolchange_settings.swap_length, MMM_TO_MMS(toolchange_settings.prime_speed));
do_pause_e_move(toolchange_settings.extra_prime, ADVANCED_PAUSE_PURGE_FEEDRATE);
#else #else
current_position[E_AXIS] += (toolchange_settings.swap_length + toolchange_settings.extra_prime) / planner.e_factor[tmp_extruder]; current_position[E_AXIS] += toolchange_settings.swap_length / planner.e_factor[new_tool];
planner.buffer_line(current_position, MMM_TO_MMS(toolchange_settings.prime_speed), tmp_extruder); planner.buffer_line(current_position, MMM_TO_MMS(toolchange_settings.prime_speed), new_tool);
current_position[E_AXIS] += toolchange_settings.extra_prime / planner.e_factor[new_tool];
planner.buffer_line(current_position, MMM_TO_MMS(toolchange_settings.prime_speed * 0.2f), new_tool);
#endif #endif
planner.synchronize(); planner.synchronize();
planner.set_e_position_mm((destination[E_AXIS] = current_position[E_AXIS] = current_position[E_AXIS] - (TOOLCHANGE_FIL_EXTRA_PRIME))); planner.set_e_position_mm((destination[E_AXIS] = current_position[E_AXIS] = current_position[E_AXIS] - (TOOLCHANGE_FIL_EXTRA_PRIME)));
@ -989,7 +993,7 @@ void tool_change(const uint8_t tmp_extruder, bool no_move/*=false*/) {
// If the original position is within tool store area, go to X origin at once // If the original position is within tool store area, go to X origin at once
if (destination[Y_AXIS] < SWITCHING_TOOLHEAD_Y_POS + SWITCHING_TOOLHEAD_Y_CLEAR) { if (destination[Y_AXIS] < SWITCHING_TOOLHEAD_Y_POS + SWITCHING_TOOLHEAD_Y_CLEAR) {
current_position[X_AXIS] = 0; current_position[X_AXIS] = 0;
planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[X_AXIS], active_extruder); planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[X_AXIS], new_tool);
planner.synchronize(); planner.synchronize();
} }
#else #else
@ -1022,14 +1026,14 @@ void tool_change(const uint8_t tmp_extruder, bool no_move/*=false*/) {
#endif #endif
#if ENABLED(PRUSA_MMU2) #if ENABLED(PRUSA_MMU2)
mmu2.tool_change(tmp_extruder); mmu2.tool_change(new_tool);
#endif #endif
#if SWITCHING_NOZZLE_TWO_SERVOS #if SWITCHING_NOZZLE_TWO_SERVOS
lower_nozzle(active_extruder); lower_nozzle(new_tool);
#endif #endif
} // (tmp_extruder != active_extruder) } // (new_tool != old_tool)
planner.synchronize(); planner.synchronize();
@ -1039,8 +1043,8 @@ void tool_change(const uint8_t tmp_extruder, bool no_move/*=false*/) {
#endif #endif
#if ENABLED(MK2_MULTIPLEXER) #if ENABLED(MK2_MULTIPLEXER)
if (tmp_extruder >= E_STEPPERS) return invalid_extruder_error(tmp_extruder); if (new_tool >= E_STEPPERS) return invalid_extruder_error(new_tool);
select_multiplexed_stepper(tmp_extruder); select_multiplexed_stepper(new_tool);
#endif #endif
#if DO_SWITCH_EXTRUDER #if DO_SWITCH_EXTRUDER