Apply some tool-change cleanup

This commit is contained in:
Scott Lahteine 2018-11-06 18:03:10 -06:00
parent 34ea458667
commit 5a470d4a49

View File

@ -129,10 +129,17 @@
inline void parking_extruder_tool_change(const uint8_t tmp_extruder, bool no_move) { inline void parking_extruder_tool_change(const uint8_t tmp_extruder, bool no_move) {
if (!no_move) { if (!no_move) {
const float parkingposx[] = PARKING_EXTRUDER_PARKING_X, constexpr float parkingposx[] = PARKING_EXTRUDER_PARKING_X;
midpos = (parkingposx[0] + parkingposx[1]) * 0.5 + hotend_offset[X_AXIS][active_extruder],
grabpos = parkingposx[tmp_extruder] + hotend_offset[X_AXIS][active_extruder] #if HAS_HOTEND_OFFSET
+ (tmp_extruder == 0 ? -(PARKING_EXTRUDER_GRAB_DISTANCE) : PARKING_EXTRUDER_GRAB_DISTANCE); const float x_offset = hotend_offset[X_AXIS][active_extruder];
#else
constexpr float x_offset = 0;
#endif
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;
/** /**
* 1. Raise Z-Axis to give enough clearance * 1. Raise Z-Axis to give enough clearance
* 2. Move to park position of old extruder * 2. Move to park position of old extruder
@ -144,42 +151,54 @@
*/ */
// STEP 1 // STEP 1
#if ENABLED(DEBUG_LEVELING_FEATURE) #if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("Start Autopark", current_position); if (DEBUGGING(LEVELING)) DEBUG_POS("Start Autopark", current_position);
#endif #endif
current_position[Z_AXIS] += toolchange_settings.z_raise; current_position[Z_AXIS] += toolchange_settings.z_raise;
#if ENABLED(DEBUG_LEVELING_FEATURE) #if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("(1) Raise Z-Axis", current_position); if (DEBUGGING(LEVELING)) DEBUG_POS("(1) Raise Z-Axis", current_position);
#endif #endif
planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Z_AXIS], active_extruder); planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Z_AXIS], active_extruder);
planner.synchronize(); planner.synchronize();
// STEP 2 // STEP 2
current_position[X_AXIS] = parkingposx[active_extruder] + hotend_offset[X_AXIS][active_extruder];
current_position[X_AXIS] = parkingposx[active_extruder] + x_offset;
#if ENABLED(DEBUG_LEVELING_FEATURE) #if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) { if (DEBUGGING(LEVELING)) {
SERIAL_ECHOLNPAIR("(2) Park extruder ", int(active_extruder)); SERIAL_ECHOLNPAIR("(2) Park extruder ", int(active_extruder));
DEBUG_POS("Moving ParkPos", current_position); DEBUG_POS("Moving ParkPos", current_position);
} }
#endif #endif
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], active_extruder);
planner.synchronize(); planner.synchronize();
// STEP 3 // STEP 3
#if ENABLED(DEBUG_LEVELING_FEATURE) #if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("(3) Disengage magnet "); if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("(3) Disengage magnet ");
#endif #endif
pe_deactivate_magnet(active_extruder); pe_deactivate_magnet(active_extruder);
// STEP 4 // STEP 4
#if ENABLED(DEBUG_LEVELING_FEATURE) #if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("(4) Move to position near new extruder"); if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("(4) Move to position near new extruder");
#endif #endif
current_position[X_AXIS] += active_extruder ? -10 : 10; // move 10mm away from parked extruder current_position[X_AXIS] += active_extruder ? -10 : 10; // move 10mm away from parked extruder
#if ENABLED(DEBUG_LEVELING_FEATURE) #if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("Move away from parked extruder", current_position); if (DEBUGGING(LEVELING)) DEBUG_POS("Move away from parked extruder", current_position);
#endif #endif
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], active_extruder);
planner.synchronize(); planner.synchronize();
@ -191,9 +210,11 @@
#if ENABLED(PARKING_EXTRUDER_SOLENOIDS_INVERT) #if ENABLED(PARKING_EXTRUDER_SOLENOIDS_INVERT)
pe_activate_magnet(active_extruder); //just save power for inverted magnets pe_activate_magnet(active_extruder); //just save power for inverted magnets
#endif #endif
pe_activate_magnet(tmp_extruder); pe_activate_magnet(tmp_extruder);
// STEP 6 // STEP 6
current_position[X_AXIS] = grabpos + (tmp_extruder ? -10 : 10); current_position[X_AXIS] = grabpos + (tmp_extruder ? -10 : 10);
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], active_extruder);
current_position[X_AXIS] = grabpos; current_position[X_AXIS] = grabpos;
@ -203,13 +224,21 @@
planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[X_AXIS]/2, active_extruder); planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[X_AXIS]/2, active_extruder);
planner.synchronize(); planner.synchronize();
// Step 7 // STEP 7
current_position[X_AXIS] = midpos - hotend_offset[X_AXIS][tmp_extruder];
current_position[X_AXIS] = midpos
#if HAS_HOTEND_OFFSET
- hotend_offset[X_AXIS][tmp_extruder]
#endif
;
#if ENABLED(DEBUG_LEVELING_FEATURE) #if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("(7) Move midway between hotends", current_position); if (DEBUGGING(LEVELING)) DEBUG_POS("(7) Move midway between hotends", current_position);
#endif #endif
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], active_extruder);
planner.synchronize(); planner.synchronize();
#if ENABLED(DEBUG_LEVELING_FEATURE) #if ENABLED(DEBUG_LEVELING_FEATURE)
SERIAL_ECHOLNPGM("Autopark done."); SERIAL_ECHOLNPGM("Autopark done.");
#endif #endif
@ -221,7 +250,10 @@
pe_activate_magnet(active_extruder); // Just save power for inverted magnets pe_activate_magnet(active_extruder); // Just save power for inverted magnets
#endif #endif
} }
current_position[Z_AXIS] += hotend_offset[Z_AXIS][active_extruder] - hotend_offset[Z_AXIS][tmp_extruder];
#if HAS_HOTEND_OFFSET
current_position[Z_AXIS] += hotend_offset[Z_AXIS][active_extruder] - hotend_offset[Z_AXIS][tmp_extruder];
#endif
#if ENABLED(DEBUG_LEVELING_FEATURE) #if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("Applying Z-offset", current_position); if (DEBUGGING(LEVELING)) DEBUG_POS("Applying Z-offset", current_position);
@ -251,80 +283,105 @@
*/ */
// STEP 1 // STEP 1
#if ENABLED(DEBUG_LEVELING_FEATURE) #if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("Starting Toolhead change", current_position); if (DEBUGGING(LEVELING)) DEBUG_POS("Starting Toolhead change", current_position);
#endif #endif
current_position[Z_AXIS] += toolchange_settings.z_raise; current_position[Z_AXIS] += toolchange_settings.z_raise;
#if ENABLED(DEBUG_LEVELING_FEATURE) #if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("(1) Raise Z-Axis", current_position); if (DEBUGGING(LEVELING)) DEBUG_POS("(1) Raise Z-Axis", current_position);
#endif #endif
planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Z_AXIS], active_extruder); planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Z_AXIS], active_extruder);
planner.synchronize(); planner.synchronize();
// STEP 2 // STEP 2
current_position[X_AXIS] = placexpos; current_position[X_AXIS] = placexpos;
#if ENABLED(DEBUG_LEVELING_FEATURE) #if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) { if (DEBUGGING(LEVELING)) {
SERIAL_ECHOLNPAIR("(2) Place old tool ", int(active_extruder)); SERIAL_ECHOLNPAIR("(2) Place old tool ", int(active_extruder));
DEBUG_POS("Move X SwitchPos", current_position); DEBUG_POS("Move X SwitchPos", current_position);
} }
#endif #endif
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], active_extruder);
planner.synchronize(); planner.synchronize();
current_position[Y_AXIS] = SWITCHING_TOOLHEAD_Y_POS - SWITCHING_TOOLHEAD_Y_SECURITY; current_position[Y_AXIS] = SWITCHING_TOOLHEAD_Y_POS - SWITCHING_TOOLHEAD_Y_SECURITY;
#if ENABLED(DEBUG_LEVELING_FEATURE) #if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("Move Y SwitchPos + Security", current_position); if (DEBUGGING(LEVELING)) DEBUG_POS("Move Y SwitchPos + Security", current_position);
#endif #endif
planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Y_AXIS], active_extruder); planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Y_AXIS], active_extruder);
planner.synchronize(); planner.synchronize();
// STEP 3 // STEP 3
#if ENABLED(DEBUG_LEVELING_FEATURE) #if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("(3) Unlock and Place Toolhead"); if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("(3) Unlock and Place Toolhead");
#endif #endif
MOVE_SERVO(SWITCHING_TOOLHEAD_SERVO_NR, angles[1]); MOVE_SERVO(SWITCHING_TOOLHEAD_SERVO_NR, angles[1]);
safe_delay(500); safe_delay(500);
current_position[Y_AXIS] = SWITCHING_TOOLHEAD_Y_POS; current_position[Y_AXIS] = SWITCHING_TOOLHEAD_Y_POS;
#if ENABLED(DEBUG_LEVELING_FEATURE) #if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("Move Y SwitchPos", current_position); if (DEBUGGING(LEVELING)) DEBUG_POS("Move Y SwitchPos", current_position);
#endif #endif
planner.buffer_line(current_position,(planner.settings.max_feedrate_mm_s[Y_AXIS] * 0.5), active_extruder); planner.buffer_line(current_position,(planner.settings.max_feedrate_mm_s[Y_AXIS] * 0.5), active_extruder);
planner.synchronize(); planner.synchronize();
safe_delay(200); safe_delay(200);
current_position[Y_AXIS] -= SWITCHING_TOOLHEAD_Y_CLEAR; current_position[Y_AXIS] -= SWITCHING_TOOLHEAD_Y_CLEAR;
#if ENABLED(DEBUG_LEVELING_FEATURE) #if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("Move back Y clear", current_position); if (DEBUGGING(LEVELING)) DEBUG_POS("Move back Y clear", current_position);
#endif #endif
planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Y_AXIS], active_extruder); // move away from docked toolhead planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Y_AXIS], active_extruder); // move away from docked toolhead
planner.synchronize(); planner.synchronize();
// STEP 4 // STEP 4
#if ENABLED(DEBUG_LEVELING_FEATURE) #if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("(4) Move to new toolhead position"); if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("(4) Move to new toolhead position");
#endif #endif
current_position[X_AXIS] = grabxpos; current_position[X_AXIS] = grabxpos;
#if ENABLED(DEBUG_LEVELING_FEATURE) #if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("Move to new toolhead X", current_position); if (DEBUGGING(LEVELING)) DEBUG_POS("Move to new toolhead X", current_position);
#endif #endif
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], active_extruder);
planner.synchronize(); planner.synchronize();
current_position[Y_AXIS] = SWITCHING_TOOLHEAD_Y_POS - SWITCHING_TOOLHEAD_Y_SECURITY; current_position[Y_AXIS] = SWITCHING_TOOLHEAD_Y_POS - SWITCHING_TOOLHEAD_Y_SECURITY;
#if ENABLED(DEBUG_LEVELING_FEATURE) #if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("Move Y SwitchPos + Security", current_position); if (DEBUGGING(LEVELING)) DEBUG_POS("Move Y SwitchPos + Security", current_position);
#endif #endif
planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Y_AXIS], active_extruder); planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Y_AXIS], active_extruder);
planner.synchronize(); planner.synchronize();
// STEP 5 // STEP 5
#if ENABLED(DEBUG_LEVELING_FEATURE) #if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("(5) Grab and lock new toolhead "); if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("(5) Grab and lock new toolhead ");
#endif #endif
current_position[Y_AXIS] = SWITCHING_TOOLHEAD_Y_POS; current_position[Y_AXIS] = SWITCHING_TOOLHEAD_Y_POS;
#if ENABLED(DEBUG_LEVELING_FEATURE) #if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("Move Y SwitchPos", current_position); if (DEBUGGING(LEVELING)) DEBUG_POS("Move Y SwitchPos", current_position);
#endif #endif
planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Y_AXIS] * 0.5, active_extruder); planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Y_AXIS] * 0.5, active_extruder);
planner.synchronize(); planner.synchronize();
@ -333,14 +390,19 @@
safe_delay(500); safe_delay(500);
current_position[Y_AXIS] -= SWITCHING_TOOLHEAD_Y_CLEAR; current_position[Y_AXIS] -= SWITCHING_TOOLHEAD_Y_CLEAR;
#if ENABLED(DEBUG_LEVELING_FEATURE) #if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("Move back Y clear", current_position); if (DEBUGGING(LEVELING)) DEBUG_POS("Move back Y clear", current_position);
#endif #endif
planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Y_AXIS], active_extruder); // move away from docked toolhead planner.buffer_line(current_position, planner.settings.max_feedrate_mm_s[Y_AXIS], active_extruder); // move away from docked toolhead
planner.synchronize(); planner.synchronize();
// STEP 6 // STEP 6
current_position[Z_AXIS] += hotend_offset[Z_AXIS][active_extruder] - hotend_offset[Z_AXIS][tmp_extruder];
#if HAS_HOTEND_OFFSET
current_position[Z_AXIS] += hotend_offset[Z_AXIS][active_extruder] - hotend_offset[Z_AXIS][tmp_extruder];
#endif
#if ENABLED(DEBUG_LEVELING_FEATURE) #if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("(6) Apply Z offset", current_position); if (DEBUGGING(LEVELING)) DEBUG_POS("(6) Apply Z offset", current_position);