Skip to content

Commit

Permalink
overhaul
Browse files Browse the repository at this point in the history
  • Loading branch information
DerAndere1 committed Apr 20, 2024
1 parent 96cafb1 commit abcb22a
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 39 deletions.
7 changes: 4 additions & 3 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,13 @@
//#define SAFE_TOOLCHANGE_START_Z 200

#if ANY(SWITCHING_TOOLHEAD, MAGNETIC_SWITCHING_TOOLHEAD, ELECTROMAGNETIC_SWITCHING_TOOLHEAD)
//#define SWITCHING_TOOLHEAD_Z_POS 100 // (mm) Z position of the toolhead dock.
// Leave this option disabled if the bed can move in Z direction
//#define SWITCHING_TOOLHEAD_Z_CLEAR 60 // (mm) Minimum distance from dock along Z for unobstructed X axis if the tools are placed onto the dock in Z direction
#define SWITCHING_TOOLHEAD_Y_POS 235 // (mm) Y position of the toolhead dock
#define SWITCHING_TOOLHEAD_Y_SECURITY 10 // (mm) Security distance Y axis
#define SWITCHING_TOOLHEAD_Y_CLEAR 60 // (mm) Minimum distance from dock for unobstructed X axis
#define SWITCHING_TOOLHEAD_X_POS { 215, 0 } // (mm) X positions for parking the extruders
//#define SWITCHING_TOOLHEAD_Z_POS 100 // (mm) Z position of the toolhead dock.
// Leave disabled if dock is on the frame of a CORE_XY machine
#if ENABLED(SWITCHING_TOOLHEAD)
#define SWITCHING_TOOLHEAD_SERVO_NR 2 // Index of the servo connector
#define SWITCHING_TOOLHEAD_SERVO_ANGLES { 0, 180 } // (degrees) Angles for Lock, Unlock
Expand Down Expand Up @@ -367,7 +368,7 @@

// Offset of the extruders (uncomment if using more than one and relying on firmware to position when changing).
// The offset has to be X=0, Y=0 for the extruder 0 hotend (default extruder).
// For the other hotends it is their distance from the extruder 0 hotend.
// For the other hotends it is their distance from the extruder 0 hotend in negative axis direction.
//#define HOTEND_OFFSET_X { 0.0, 20.00 } // (mm) relative X-offset for each nozzle
//#define HOTEND_OFFSET_Y { 0.0, 5.00 } // (mm) relative Y-offset for each nozzle
//#define HOTEND_OFFSET_Z { 0.0, 0.00 } // (mm) relative Z-offset for each nozzle
Expand Down
149 changes: 113 additions & 36 deletions Marlin/src/module/tool_change.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,7 @@ void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_axis, 0.
(void)check_tool_sensor_stats(active_extruder, true);

/**
* 1. Move xy to switch position of current toolhead
* 2. Move z to switch position
* 1. Move to switch position of current toolhead
* 2. Unlock tool and drop it in the dock
* 3. Move to the new toolhead
* 4. Grab and lock the new toolhead
Expand All @@ -516,26 +515,57 @@ void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_axis, 0.

DEBUG_POS("Start ST Tool-Change", current_position);

current_position.x = placexpos;
current_position.x = SUM_TERN(HAS_HOTEND_OFFSET, placexpos, hotend_offset[active_extruder].x);

DEBUG_ECHOLNPGM("(1) Place old tool ", active_extruder);
DEBUG_POS("Move X SwitchPos", current_position);

fast_line_to_current(X_AXIS);

current_position.y = SWITCHING_TOOLHEAD_Y_POS - (SWITCHING_TOOLHEAD_Y_SECURITY);
current_position.y = SUM_TERN(HAS_HOTEND_OFFSET, SWITCHING_TOOLHEAD_Y_POS, hotend_offset[active_extruder].y) - (SWITCHING_TOOLHEAD_Y_CLEAR);

DEBUG_SYNCHRONIZE();
DEBUG_POS("Move Y SwitchPos + Security", current_position);
DEBUG_POS("Move Y SwitchPos - Y Clear", current_position);

slow_line_to_current(Y_AXIS);
#if ENABLED(SWITCHING_TOOLHEAD_Z_POS)
current_position.z = SWITCHING_TOOLHEAD_Z_POS;
fast_line_to_current(Y_AXIS); // move Y in front of the toolhead dock

#if defined(SWITCHING_TOOLHEAD_Z_CLEAR)
current_position.z = SWITCHING_TOOLHEAD_Z_POS + (SWITCHING_TOOLHEAD_Z_CLEAR);

DEBUG_SYNCHRONIZE();
DEBUG_POS("Move Z SwitchPos + Z Clear", current_position);

fast_line_to_current(Z_AXIS); // move Z on top of the toolhead dock

current_position.y = SUM_TERN(HAS_HOTEND_OFFSET, SWITCHING_TOOLHEAD_Y_POS, hotend_offset[active_extruder].y);

DEBUG_SYNCHRONIZE();
DEBUG_POS("Move Y SwitchPos", current_position);

fast_line_to_current(Y_AXIS); // move Y to the toolhead dock

current_position.z = SUM_TERN(HAS_HOTEND_OFFSET, SWITCHING_TOOLHEAD_Z_POS, hotend_offset[active_extruder].z);

DEBUG_SYNCHRONIZE();
DEBUG_POS("Move Z SwitchPos", current_position);

fast_line_to_current(Z_AXIS);
slow_line_to_current(Z_AXIS); // place tool in the toolhead dock

#else
#if defined(SWITCHING_TOOLHEAD_Z_POS)
current_position.z = SUM_TERN(HAS_HOTEND_OFFSET, SWITCHING_TOOLHEAD_Z_POS, hotend_offset[active_extruder].z);

DEBUG_SYNCHRONIZE();
DEBUG_POS("Move Z SwitchPos", current_position);

fast_line_to_current(Z_AXIS); // move Z to the toolhead dock
#endif
current_position.y = SUM_TERN(HAS_HOTEND_OFFSET, SWITCHING_TOOLHEAD_Y_POS, hotend_offset[active_extruder].y) - (SWITCHING_TOOLHEAD_Y_SECURITY);

DEBUG_SYNCHRONIZE();
DEBUG_POS("Move Y SwitchPos + Security", current_position);

slow_line_to_current(Y_AXIS);
#endif

// 2. Unlock tool and drop it in the dock
Expand All @@ -545,47 +575,68 @@ void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_axis, 0.
DEBUG_ECHOLNPGM("(2) Unlock and Place Toolhead");
switching_toolhead_lock(false);
safe_delay(500);

current_position.y = SWITCHING_TOOLHEAD_Y_POS;
DEBUG_POS("Move Y SwitchPos", current_position);
slow_line_to_current(Y_AXIS);
#if !defined(SWITCHING_TOOLHEAD_Z_CLEAR)
current_position.y += (SWITCHING_TOOLHEAD_Y_SECURITY);
DEBUG_POS("Move Y SwitchPos", current_position);
slow_line_to_current(Y_AXIS);
#endif

// Wait for move to complete, then another 0.2s
planner.synchronize();
safe_delay(200);

current_position.y -= SWITCHING_TOOLHEAD_Y_CLEAR;
DEBUG_POS("Move back Y clear", current_position);
slow_line_to_current(Y_AXIS); // move away from docked toolhead
#if defined(SWITCHING_TOOLHEAD_Z_CLEAR)
current_position.z += (SWITCHING_TOOLHEAD_Z_CLEAR);

DEBUG_SYNCHRONIZE();
DEBUG_POS("Move back Z Clear", current_position);

slow_line_to_current(Z_AXIS); // move away from docked toolhead
#else
current_position.y -= SWITCHING_TOOLHEAD_Y_CLEAR;

DEBUG_POS("Move back Y clear", current_position);
slow_line_to_current(Y_AXIS); // move away from docked toolhead
#endif

(void)check_tool_sensor_stats(active_extruder);

// 3. Move to the new toolhead

current_position.x = grabxpos;
current_position.x = SUM_TERN(HAS_HOTEND_OFFSET, grabxpos, hotend_offset[active_extruder].x);

DEBUG_SYNCHRONIZE();
DEBUG_ECHOLNPGM("(3) Move to new toolhead position");
DEBUG_POS("Move to new toolhead X", current_position);

fast_line_to_current(X_AXIS);

current_position.y = SWITCHING_TOOLHEAD_Y_POS - (SWITCHING_TOOLHEAD_Y_SECURITY);
// 4. Grab and lock the new toolhead

DEBUG_SYNCHRONIZE();
DEBUG_POS("Move Y SwitchPos + Security", current_position);
#if defined(SWITCHING_TOOLHEAD_Z_CLEAR)
current_position.z = SUM_TERN(HAS_HOTEND_OFFSET, SWITCHING_TOOLHEAD_Z_POS, hotend_offset[active_extruder].z);

slow_line_to_current(Y_AXIS);
DEBUG_SYNCHRONIZE();
DEBUG_ECHOLNPGM("(4) Grab and lock new toolhead");
DEBUG_POS("Move Z SwitchPos", current_position);

// 4. Grab and lock the new toolhead
slow_line_to_current(Z_AXIS);
#else
current_position.y = SUM_TERN(HAS_HOTEND_OFFSET, SWITCHING_TOOLHEAD_Y_POS, hotend_offset[active_extruder].y) - SWITCHING_TOOLHEAD_Y_SECURITY;

current_position.y = SWITCHING_TOOLHEAD_Y_POS;
DEBUG_SYNCHRONIZE();
DEBUG_POS("Move Y SwitchPos + Security", current_position);

DEBUG_SYNCHRONIZE();
DEBUG_ECHOLNPGM("(4) Grab and lock new toolhead");
DEBUG_POS("Move Y SwitchPos", current_position);
slow_line_to_current(Y_AXIS);

slow_line_to_current(Y_AXIS);
current_position.y = SUM_TERN(HAS_HOTEND_OFFSET, SWITCHING_TOOLHEAD_Y_POS, hotend_offset[active_extruder].y);

DEBUG_SYNCHRONIZE();
DEBUG_ECHOLNPGM("(4) Grab and lock new toolhead");
DEBUG_POS("Move Y SwitchPos", current_position);

slow_line_to_current(Y_AXIS);
#endif

// Wait for move to finish, pause 0.2s, move servo, pause 0.5s
planner.synchronize();
Expand All @@ -595,10 +646,24 @@ void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_axis, 0.

switching_toolhead_lock(true);
safe_delay(500);
#if defined(SWITCHING_TOOLHEAD_Z_CLEAR)
#if HAS_HOTEND_OFFSET
current_position.z = SWITCHING_TOOLHEAD_Z_POS + hotend_offset[active_extruder].z - hotend_offset[new_tool].z + (SWITCHING_TOOLHEAD_Z_CLEAR);
#else
current_position.z = SWITCHING_TOOLHEAD_Z_POS + (SWITCHING_TOOLHEAD_Z_CLEAR)
#endif
DEBUG_POS("Move back Z clear", current_position);
slow_line_to_current(Z_AXIS); // Move away from docked toolhead

current_position.y -= SWITCHING_TOOLHEAD_Y_CLEAR;
DEBUG_POS("Move back Y clear", current_position);
slow_line_to_current(Y_AXIS); // Move away from docked toolhead
current_position.y -= SWITCHING_TOOLHEAD_Y_CLEAR;
DEBUG_POS("Move back Y clear", current_position);
slow_line_to_current(Y_AXIS); // Move away from docked toolhead

#else
current_position.y -= SWITCHING_TOOLHEAD_Y_CLEAR;
DEBUG_POS("Move back Y clear", current_position);
slow_line_to_current(Y_AXIS); // Move away from docked toolhead
#endif
planner.synchronize(); // Always sync the final move

(void)check_tool_sensor_stats(new_tool, true, true);
Expand Down Expand Up @@ -1246,17 +1311,22 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
#if NONE(TOOLCHANGE_ZRAISE_BEFORE_RETRACT, HAS_SWITCHING_NOZZLE)
if (can_move_away && TERN1(TOOLCHANGE_PARK, toolchange_settings.enable_park)) {
// Do a small lift to avoid the workpiece in the move back (below)
// Or move to SAFE_TOOLCHANGE_START_Z, if enabled
#if ENABLED(SAFE_TOOLCHANGE_START_Z)
current_position.z = SAFE_TOOLCHANGE_START_Z;
#else
current_position.z += toolchange_settings.z_raise;
#endif
current_position.z += toolchange_settings.z_raise;
TERN_(HAS_SOFTWARE_ENDSTOPS, NOMORE(current_position.z, soft_endstop.max.z));
fast_line_to_current(Z_AXIS);
}
#endif

// Raise to safe Z
#if defined(SAFE_TOOLCHANGE_START_Z)
if (can_move_away && TERN1(TOOLCHANGE_PARK, toolchange_settings.enable_park)) {
current_position.z = SAFE_TOOLCHANGE_START_Z;
TERN_(HAS_SOFTWARE_ENDSTOPS, NOMORE(current_position.z, soft_endstop.max.z));
fast_line_to_current(Z_AXIS);
planner.synchronize();
}
#endif

// Toolchange park
#if ENABLED(TOOLCHANGE_PARK) && !HAS_SWITCHING_NOZZLE
if (can_move_away && toolchange_settings.enable_park) {
Expand Down Expand Up @@ -1375,6 +1445,13 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
// Move back to the original (or adjusted) position
DEBUG_POS("Move back", destination);

// Raise to safe Z
#if defined(SAFE_TOOLCHANGE_START_Z)
if (TERN1(TOOLCHANGE_PARK, toolchange_settings.enable_park)) {
do_blocking_move_to_z(SAFE_TOOLCHANGE_START_Z, planner.settings.max_feedrate_mm_s[Z_AXIS]);
}
#endif

#if ENABLED(TOOLCHANGE_PARK)
if (toolchange_settings.enable_park) do_blocking_move_to_xy_z(destination, destination.z, MMM_TO_MMS(TOOLCHANGE_PARK_XY_FEEDRATE));
#else
Expand Down

0 comments on commit abcb22a

Please sign in to comment.