Split up tool_change, raise for non-delta too

This commit is contained in:
Scott Lahteine
2018-03-25 13:23:00 -04:00
parent 52750bf362
commit 712b213b40

View File

@@ -537,7 +537,7 @@ static millis_t stepper_inactive_time = (DEFAULT_STEPPER_DEACTIVE_TIME) * 1000UL
#endif
#if ENABLED(SWITCHING_NOZZLE)
#define DONT_SWITCH (SWITCHING_EXTRUDER_SERVO_NR == SWITCHING_NOZZLE_SERVO_NR)
#define DO_SWITCH_EXTRUDER (SWITCHING_EXTRUDER_SERVO_NR != SWITCHING_NOZZLE_SERVO_NR)
#endif
uint8_t target_extruder;
@@ -11278,52 +11278,25 @@ inline void invalid_extruder_error(const uint8_t e) {
#endif // HAS_FANMUX
/**
* Perform a tool-change, which may result in moving the
* previous tool out of the way and the new tool into place.
* Tool Change functions
*/
void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool no_move/*=false*/) {
#if ENABLED(MIXING_EXTRUDER) && MIXING_VIRTUAL_TOOLS > 1
#if ENABLED(MIXING_EXTRUDER) && MIXING_VIRTUAL_TOOLS > 1
inline void mixing_tool_change(const uint8_t tmp_extruder) {
if (tmp_extruder >= MIXING_VIRTUAL_TOOLS)
return invalid_extruder_error(tmp_extruder);
// T0-Tnnn: Switch virtual tool by changing the mix
for (uint8_t j = 0; j < MIXING_STEPPERS; j++)
mixing_factor[j] = mixing_virtual_tool_mix[tmp_extruder][j];
#else // !MIXING_EXTRUDER || MIXING_VIRTUAL_TOOLS <= 1
if (tmp_extruder >= EXTRUDERS)
return invalid_extruder_error(tmp_extruder);
#if HOTENDS > 1
const float old_feedrate_mm_s = fr_mm_s > 0.0 ? fr_mm_s : feedrate_mm_s;
feedrate_mm_s = fr_mm_s > 0.0 ? fr_mm_s : XY_PROBE_FEEDRATE_MM_S;
if (tmp_extruder != active_extruder) {
if (!no_move && axis_unhomed_error()) {
no_move = true;
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("No move on toolchange");
#endif
}
// Save current position to destination, for use later
set_destination_from_current();
#endif // MIXING_EXTRUDER && MIXING_VIRTUAL_TOOLS > 1
// Set current position to the physical position
const bool leveling_was_active = planner.leveling_active;
set_bed_leveling_enabled(false);
const float xydiff[2] = {
hotend_offset[X_AXIS][tmp_extruder] - hotend_offset[X_AXIS][active_extruder],
hotend_offset[Y_AXIS][tmp_extruder] - hotend_offset[Y_AXIS][active_extruder]
};
#if ENABLED(DUAL_X_CARRIAGE)
#if ENABLED(DUAL_X_CARRIAGE)
inline void dualx_tool_change(const uint8_t tmp_extruder, bool &no_move) {
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {
SERIAL_ECHOPGM("Dual X Carriage Mode ");
@@ -11402,11 +11375,7 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
// If the new extruder is the left one, set it "parked"
// This triggers the second extruder to move into the duplication position
active_extruder_parked = (active_extruder == 0);
if (active_extruder_parked)
current_position[X_AXIS] = inactive_extruder_x_pos;
else
current_position[X_AXIS] = destination[X_AXIS] + duplicate_extruder_x_offset;
current_position[X_AXIS] = active_extruder_parked ? inactive_extruder_x_pos : destination[X_AXIS] + duplicate_extruder_x_offset;
inactive_extruder_x_pos = destination[X_AXIS];
extruder_duplication_enabled = false;
#if ENABLED(DEBUG_LEVELING_FEATURE)
@@ -11426,15 +11395,15 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
#endif
// No extra case for HAS_ABL in DUAL_X_CARRIAGE. Does that mean they don't work together?
}
#else // !DUAL_X_CARRIAGE
#endif // DUAL_X_CARRIAGE
#if ENABLED(PARKING_EXTRUDER) || ENABLED(SWITCHING_NOZZLE)
const float z_diff = hotend_offset[Z_AXIS][active_extruder] - hotend_offset[Z_AXIS][tmp_extruder];
#endif
#if ENABLED(PARKING_EXTRUDER)
#if ENABLED(PARKING_EXTRUDER) // Dual Parking extruder
inline void parking_extruder_tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool no_move/*=false*/) {
constexpr float z_raise = PARKING_EXTRUDER_SECURITY_RAISE;
if (!no_move) {
const float parkingposx[] = PARKING_EXTRUDER_PARKING_X,
@@ -11532,56 +11501,101 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
pe_activate_magnet(active_extruder); // Just save power for inverted magnets
#endif
}
current_position[Z_AXIS] += z_diff; // Apply Zoffset
current_position[Z_AXIS] += hotend_offset[Z_AXIS][active_extruder] - hotend_offset[Z_AXIS][tmp_extruder];
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("Applying Z-offset", current_position);
#endif
}
#endif // dualParking extruder
#endif // PARKING_EXTRUDER
/**
* Perform a tool-change, which may result in moving the
* previous tool out of the way and the new tool into place.
*/
void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool no_move/*=false*/) {
#if ENABLED(MIXING_EXTRUDER) && MIXING_VIRTUAL_TOOLS > 1
mixing_tool_change(tmp_extruder);
#else // !MIXING_EXTRUDER || MIXING_VIRTUAL_TOOLS <= 1
if (tmp_extruder >= EXTRUDERS)
return invalid_extruder_error(tmp_extruder);
#if HOTENDS > 1
const float old_feedrate_mm_s = fr_mm_s > 0.0 ? fr_mm_s : feedrate_mm_s;
feedrate_mm_s = fr_mm_s > 0.0 ? fr_mm_s : XY_PROBE_FEEDRATE_MM_S;
if (tmp_extruder != active_extruder) {
if (!no_move && axis_unhomed_error()) {
no_move = true;
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("No move on toolchange");
#endif
}
// Save current position to destination, for use later
set_destination_from_current();
#if HAS_LEVELING
// Set current position to the physical position
const bool leveling_was_active = planner.leveling_active;
set_bed_leveling_enabled(false);
#endif
#if ENABLED(DUAL_X_CARRIAGE)
dualx_tool_change(tmp_extruder, no_move); // Can modify no_move
#else // !DUAL_X_CARRIAGE
#if ENABLED(PARKING_EXTRUDER) // Dual Parking extruder
parking_extruder_tool_change(tmp_extruder, no_move);
#endif
#if ENABLED(SWITCHING_NOZZLE)
// Always raise by at least 0.3
const float z_diff = hotend_offset[Z_AXIS][active_extruder] - hotend_offset[Z_AXIS][tmp_extruder];
current_position[Z_AXIS] += (z_diff > 0.0 ? z_diff : 0.0) + 0.3;
planner.buffer_line_kinematic(current_position, planner.max_feedrate_mm_s[Z_AXIS], active_extruder);
move_nozzle_servo(tmp_extruder);
#endif
const float xdiff = hotend_offset[X_AXIS][tmp_extruder] - hotend_offset[X_AXIS][active_extruder],
ydiff = hotend_offset[Y_AXIS][tmp_extruder] - hotend_offset[Y_AXIS][active_extruder];
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {
SERIAL_ECHOPAIR("Offset Tool XY by { ", xydiff[X_AXIS]);
SERIAL_ECHOPAIR(", ", xydiff[Y_AXIS]);
SERIAL_ECHOPAIR("Offset Tool XY by { ", xdiff);
SERIAL_ECHOPAIR(", ", ydiff);
SERIAL_ECHOLNPGM(" }");
}
#endif
// The newly-selected extruder XY is actually at...
current_position[X_AXIS] += xydiff[X_AXIS];
current_position[Y_AXIS] += xydiff[Y_AXIS];
current_position[X_AXIS] += xdiff;
current_position[Y_AXIS] += ydiff;
// Set the new active extruder
active_extruder = tmp_extruder;
#endif // !DUAL_X_CARRIAGE
#if HAS_LEVELING
// Restore leveling to re-establish the logical position
set_bed_leveling_enabled(leveling_was_active);
#endif
// Tell the planner the new "current position"
SYNC_PLAN_POSITION_KINEMATIC();
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("Sync After Toolchange", current_position);
#endif
#if ENABLED(DELTA)
//LOOP_XYZ(i) update_software_endstops(i); // or modify the constrain function
// Do a small lift to avoid the workpiece in the move back (below)
const bool safe_to_move = current_position[Z_AXIS] < delta_clip_start_height - 1;
if (!no_move && IsRunning() && safe_to_move) {
current_position[Z_AXIS] += 1.0;
planner.buffer_line_kinematic(current_position, planner.max_feedrate_mm_s[Z_AXIS], active_extruder);
}
#else
constexpr bool safe_to_move = true;
#endif
@@ -11590,8 +11604,11 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
destination[Z_AXIS] += z_diff; // Include the Z restore with the "move back"
#endif
// Move to the "old position" (move the extruder into place)
// Raise, move, and lower again
if (safe_to_move && !no_move && IsRunning()) {
// Do a small lift to avoid the workpiece in the move back (below)
current_position[Z_AXIS] += 1.0;
planner.buffer_line_kinematic(current_position, planner.max_feedrate_mm_s[Z_AXIS], active_extruder);
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("Move back", destination);
#endif
@@ -11632,7 +11649,7 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
#endif // HOTENDS <= 1
#if ENABLED(SWITCHING_EXTRUDER) && !DONT_SWITCH
#if DO_SWITCH_EXTRUDER
stepper.synchronize();
move_extruder_servo(active_extruder);
#endif
@@ -13975,7 +13992,7 @@ void setup() {
setup_endstop_interrupts();
#endif
#if ENABLED(SWITCHING_EXTRUDER) && !DONT_SWITCH
#if DO_SWITCH_EXTRUDER
move_extruder_servo(0); // Initialize extruder servo
#endif