dual_carriage: Allow dual carriage inactivation

Signed-off-by: Dmitry Butyugin <dmbutyugin@google.com>
This commit is contained in:
Dmitry Butyugin authored and KevinOConnor committed 2026-02-19 21:37:18 -05:00
1 parent 57c2e0c960
commit 187481e251
9 files changed
+140 -73

No files matched your search

+22
View File
@@ -157,6 +157,28 @@ gcode:
SET_DUAL_CARRIAGE CARRIAGE=carriage_v MODE=COPY
SYNC_EXTRUDER_MOTION EXTRUDER=extruder1 MOTION_QUEUE=extruder
[gcode_macro _DISABLE_AND_PARK_EXTRUDER]
gcode:
SAVE_GCODE_STATE NAME=disable_extruder
SAVE_DUAL_CARRIAGE_STATE NAME=disable_extruder
SET_HEATER_TEMPERATURE HEATER={params.EXTRUDER} TARGET=0
SYNC_EXTRUDER_MOTION EXTRUDER={params.EXTRUDER} MOTION_QUEUE=
PARK_{params.EXTRUDER}
RESTORE_DUAL_CARRIAGE_STATE NAME=disable_extruder MOVE=0
RESTORE_GCODE_STATE NAME=disable_extruder MOVE=0
[gcode_macro DISABLE_T0]
gcode:
SET_DUAL_CARRIAGE CARRIAGE=carriage_x MODE=INACTIVE
SET_DUAL_CARRIAGE CARRIAGE=carriage_y MODE=INACTIVE
_DISABLE_AND_PARK_EXTRUDER EXTRUDER=extruder
[gcode_macro DISABLE_T1]
gcode:
SET_DUAL_CARRIAGE CARRIAGE=carriage_u MODE=INACTIVE
SET_DUAL_CARRIAGE CARRIAGE=carriage_v MODE=INACTIVE
_DISABLE_AND_PARK_EXTRUDER EXTRUDER=extruder
[printer]
kinematics: generic_cartesian
max_velocity: 300
+26 -16
View File
@@ -343,19 +343,25 @@ The following command is available when the
enabled.
#### SET_DUAL_CARRIAGE
`SET_DUAL_CARRIAGE CARRIAGE=<carriage> [MODE=[PRIMARY|COPY|MIRROR]]`:
`SET_DUAL_CARRIAGE CARRIAGE=<carriage> [MODE=[PRIMARY|COPY|MIRROR|INACTIVE]]`:
This command will change the mode of the specified carriage.
If no `MODE` is provided it defaults to `PRIMARY`. `<carriage>` must
reference a defined primary or dual carriage for `generic_cartesian`
kinematics or be 0 (for primary carriage) or 1 (for dual carriage)
for all other kinematics supporting IDEX. Setting the mode to `PRIMARY`
deactivates the other carriage and makes the specified carriage execute
subsequent G-Code commands as-is. Before activating `COPY` or `MIRROR`
mode for a carriage, a different one must be activated as `PRIMARY` on
the same axis. When set to either of these two modes, the carriage
will then track the subsequent moves of its primary carriage and either
copy relative movements of it (in `COPY` mode) or execute them in the
opposite (mirror) direction (in `MIRROR` mode).
deactivates all other carriages on the same axis and makes the specified
carriage execute subsequent G-Code movement commands as-is. Before activating
`COPY` or `MIRROR` mode for a carriage, a different one must be activated as
`PRIMARY` on the same axis. When set to either of these two modes, the carriage
will track the subsequent G-Code moves and either copy relative movements
(in `COPY` mode) or execute them in the opposite (mirror) direction (in
`MIRROR` mode). Setting the mode to `INACTIVE` deactivates the carriage and
makes it ignore further G-Code moves. Note that deactivating the primary
carriage on the axis does not disable other carriages working in `COPY` or
`MIRROR` mode, which can be used to disable printing a failed part by any of
the tools and park that tool to prevent collisions with an unfinished part, see
this [sample configuration](../config/sample-corexyuv.cfg) for macros examples.
#### SAVE_DUAL_CARRIAGE_STATE
`SAVE_DUAL_CARRIAGE_STATE [NAME=<state_name>]`: Save the current positions
@@ -366,14 +372,18 @@ to the given string. If NAME is not provided it defaults to "default".
#### RESTORE_DUAL_CARRIAGE_STATE
`RESTORE_DUAL_CARRIAGE_STATE [NAME=<state_name>] [MOVE=[0|1] [MOVE_SPEED=<speed>]]`:
Restore the previously saved positions of the dual carriages and their modes,
unless "MOVE=0" is specified, in which case only the saved modes will be
restored, but not the positions of the carriages. If positions are being
restored and "MOVE_SPEED" is specified, then the toolhead moves will be
performed with the given speed (in mm/s); otherwise the toolhead move will
use the rail homing speed. Note that the carriages restore their positions
only over their own axis, which may be necessary to correctly restore COPY
and MIRROR mode of the dual carriage.
Restore the previously saved states of all dual and their primary carriages.
This command restores the modes of the carriages and moves them to their
previously saved positions, unless "MOVE=0" is specified. If positions are being
restored and "MOVE_SPEED" is specified, then the carriages will move with at
most the provided speed (in mm/s); otherwise the homing speeds of the
corresponding carriages will be used as a reference. Note that the carriages
restore their positions only over their own axes, which may be necessary to
correctly restore COPY and MIRROR mode of the dual carriage. In addition, this
command updates the Klipper toolhead position for each axis that has some dual
carriages: it is set to match the actual position of the activated primary
carriage of an axis or, if an axis does not have a saved primary carriage,
to the axis position when `SAVE_DUAL_CARRIAGE_STATE` command was called.
### [endstop_phase]
+5 -4
View File
@@ -48,10 +48,10 @@ class CartKinematics:
def calc_position(self, stepper_positions):
rails = self.rails
if self.dc_module:
primary_rail = self.dc_module.get_primary_rail(
self.dual_carriage_axis)
dc_rail = self.dc_module.get_primary_rail(self.dual_carriage_axis) \
or self.rails[self.dual_carriage_axis]
rails = (rails[:self.dual_carriage_axis] +
[primary_rail] + rails[self.dual_carriage_axis+1:])
[dc_rail] + rails[self.dual_carriage_axis+1:])
return [stepper_positions[rail.get_name()] for rail in rails]
def update_limits(self, i, range):
l, h = self.limits[i]
@@ -64,9 +64,10 @@ class CartKinematics:
rail.set_position(newpos)
for axis_name in homing_axes:
axis = "xyz".index(axis_name)
rail = None
if self.dc_module and axis == self.dual_carriage_axis:
rail = self.dc_module.get_primary_rail(self.dual_carriage_axis)
else:
if rail is None:
rail = self.rails[axis]
self.limits[axis] = rail.get_range()
def clear_homing_state(self, clear_axes):
+8 -18
View File
@@ -254,21 +254,6 @@ class GenericCartesianKinematics:
for c in config.get_prefix_sections('stepper ')]
def get_steppers(self):
return [s.get_stepper() for s in self.kin_steppers]
def get_primary_carriages(self):
carriages = []
for a in range(3):
c = None
if self.dc_module is not None and a in self.dc_module.get_axes():
primary_rail = self.dc_module.get_primary_rail(a)
for c in self.carriages.values():
if c.get_rail() == primary_rail:
break
else:
for c in self.primary_carriages:
if c.get_axis() == a:
break
carriages.append(c)
return carriages
def _get_kinematics_coeffs(self):
matr = {s.get_name() : list(s.get_kin_coeffs())
for s in self.kin_steppers}
@@ -340,7 +325,7 @@ class GenericCartesianKinematics:
homing_state.home_rails([rail], forcepos, homepos)
def home(self, homing_state):
self._check_kinematics(self.printer.command_error)
primary_carriages = self.get_primary_carriages()
primary_carriages = {c.get_axis(): c for c in self.primary_carriages}
# Each axis is homed independently and in order
for axis in homing_state.get_axes():
if self.dc_module is not None and axis in self.dc_module.get_axes():
@@ -373,8 +358,13 @@ class GenericCartesianKinematics:
self.max_z_velocity * z_ratio, self.max_z_accel * z_ratio)
def get_status(self, eventtime):
axes = [a for a, (l, h) in zip("xyz", self.limits) if l <= h]
ranges = [c.get_rail().get_range()
for c in self.get_primary_carriages()]
ranges = [(min(c.get_rail().get_range()[0]
for c in self.carriages.values()
if c.get_axis() == axis),
max(c.get_rail().get_range()[1]
for c in self.carriages.values()
if c.get_axis() == axis))
for axis in range(3)]
axes_min = gcode.Coord([r[0] for r in ranges])
axes_max = gcode.Coord([r[1] for r in ranges])
return {
+2 -1
View File
@@ -66,9 +66,10 @@ class HybridCoreXYKinematics:
rail.set_position(newpos)
for axis_name in homing_axes:
axis = "xyz".index(axis_name)
rail = None
if self.dc_module and axis == 0:
rail = self.dc_module.get_primary_rail(axis)
else:
if rail is None:
rail = self.rails[axis]
self.limits[axis] = rail.get_range()
def clear_homing_state(self, clear_axes):
+2 -1
View File
@@ -66,9 +66,10 @@ class HybridCoreXZKinematics:
rail.set_position(newpos)
for axis_name in homing_axes:
axis = "xyz".index(axis_name)
rail = None
if self.dc_module and axis == 0:
rail = self.dc_module.get_primary_rail(axis)
else:
if rail is None:
rail = self.rails[axis]
self.limits[axis] = rail.get_range()
def clear_homing_state(self, clear_axes):
+41 -33
View File
@@ -13,7 +13,7 @@ COPY = 'COPY'
MIRROR = 'MIRROR'
class DualCarriages:
VALID_MODES = [PRIMARY, COPY, MIRROR]
VALID_MODES = [INACTIVE, PRIMARY, COPY, MIRROR]
def __init__(self, printer, primary_rails, dual_rails, axes, safe_dist):
self.printer = printer
self._init_steppers(primary_rails + dual_rails)
@@ -24,15 +24,13 @@ class DualCarriages:
pc = primary_rails[i]
safe_dist[i] = min(abs(pc.position_min - dc.position_min),
abs(pc.position_max - dc.position_max))
self.primary_mode_dcs = [None] * 3
activated = [False] * 3
self.primary_rails = []
for i, c in enumerate(primary_rails):
activate = self.primary_mode_dcs[axes[i]] is None
activate, activated[axes[i]] = not activated[axes[i]], True
dc_rail = DualCarriagesRail(
printer, c, dual_rails[i], axes[i], safe_dist[i],
active=activate)
if activate:
self.primary_mode_dcs[axes[i]] = dc_rail
self.primary_rails.append(dc_rail)
self.dual_rails = [
DualCarriagesRail(printer, c, primary_rails[i],
@@ -83,9 +81,10 @@ class DualCarriages:
def get_axes(self):
return self.axes
def get_primary_rail(self, axis):
if self.primary_mode_dcs[axis] is None:
return None
return self.primary_mode_dcs[axis].rail
for dc_rail in self.dc_rails.values():
if dc_rail.mode == PRIMARY and dc_rail.axis == axis:
return dc_rail.rail
return None
def get_dc_rail_wrapper(self, rail):
for dc_rail in self.dc_rails.values():
if dc_rail.rail == rail:
@@ -111,7 +110,6 @@ class DualCarriages:
if target_dc.mode != PRIMARY:
newpos = pos[:axis] + [target_dc.get_axis_position(pos)] \
+ pos[axis+1:]
self.primary_mode_dcs[axis] = target_dc
target_dc.activate(PRIMARY, newpos, old_position=pos)
toolhead.set_position(newpos)
kin.update_limits(axis, target_dc.rail.get_range())
@@ -141,30 +139,29 @@ class DualCarriages:
return status
def get_kin_range(self, toolhead, axis):
pos = toolhead.get_position()
primary_carriage = self.primary_mode_dcs[axis]
if primary_carriage is None:
return (1.0, -1.0)
primary_pos = primary_carriage.get_axis_position(pos)
range_min = primary_carriage.rail.position_min
range_max = primary_carriage.rail.position_max
axis_pos = pos[axis]
range_min, range_max = -1e10, 1e10
for carriage in self.dc_rails.values():
if carriage.axis != axis:
continue
dcs = [carriage] + [dc for dc in self.dc_rails.values()
if carriage.rail is dc.dual_rail]
axes_pos = [dc.get_axis_position(pos) for dc in dcs]
# Check how dcs[0] affects the motion range of primary_carriage
# Check how dcs[0] affects the motion range
if not dcs[0].is_active():
continue
elif dcs[0].mode == PRIMARY:
range_min = max(range_min, dcs[0].rail.position_min)
range_max = min(range_max, dcs[0].rail.position_max)
elif dcs[0].mode == COPY:
range_min = max(range_min, primary_pos
range_min = max(range_min, axis_pos
+ dcs[0].rail.position_min - axes_pos[0])
range_max = min(range_max, primary_pos
range_max = min(range_max, axis_pos
+ dcs[0].rail.position_max - axes_pos[0])
elif dcs[0].mode == MIRROR:
range_min = max(range_min, primary_pos
range_min = max(range_min, axis_pos
+ axes_pos[0] - dcs[0].rail.position_max)
range_max = min(range_max, primary_pos
range_max = min(range_max, axis_pos
+ axes_pos[0] - dcs[0].rail.position_min)
safe_dist = dcs[0].safe_dist
if not safe_dist or len(dcs) == 1:
@@ -186,14 +183,14 @@ class DualCarriages:
if dcs[0].mode in (PRIMARY, COPY):
if self.get_dc_order(dcs[0], dcs[1]) > 0:
range_min = max(range_min, primary_pos + safe_move_dist)
range_min = max(range_min, axis_pos + safe_move_dist)
else:
range_max = min(range_max, primary_pos + safe_move_dist)
range_max = min(range_max, axis_pos + safe_move_dist)
else: # dcs[0].mode == MIRROR
if self.get_dc_order(dcs[0], dcs[1]) > 0:
range_max = min(range_max, primary_pos - safe_move_dist)
range_max = min(range_max, axis_pos - safe_move_dist)
else:
range_min = max(range_min, primary_pos - safe_move_dist)
range_min = max(range_min, axis_pos - safe_move_dist)
if range_min > range_max:
# During multi-MCU homing it is possible that the carriage
@@ -231,8 +228,6 @@ class DualCarriages:
axis = dc.axis
if mode == INACTIVE:
dc.inactivate(toolhead.get_position())
if self.primary_mode_dcs[axis] is dc:
self.primary_mode_dcs[axis] = None
elif mode == PRIMARY:
self.toggle_active_dc_rail(dc)
else:
@@ -265,7 +260,7 @@ class DualCarriages:
if mode not in self.VALID_MODES:
raise gcmd.error("Invalid mode=%s specified" % (mode,))
if mode in [COPY, MIRROR]:
if self.primary_mode_dcs[dc_rail.axis] in [None, dc_rail]:
if self.get_primary_rail(dc_rail.axis) in [None, dc_rail.rail]:
raise gcmd.error(
"Must activate another carriage as PRIMARY first")
curtime = self.printer.get_reactor().monotonic()
@@ -275,6 +270,13 @@ class DualCarriages:
raise gcmd.error(
"Axis %s must be homed prior to enabling mode=%s" %
(axis.upper(), mode))
if mode == INACTIVE:
active_dcs = [dc for dc in self.dc_rails.values()
if dc.is_active() and dc.axis == dc_rail.axis]
if active_dcs == [dc_rail]:
raise gcmd.error(
"Cannot deactivate the only active carriage for axis %s"
% 'XYZ'[dc_rail.axis])
self.activate_dc_mode(dc_rail, mode)
cmd_SAVE_DUAL_CARRIAGE_STATE_help = \
"Save dual carriages modes and positions"
@@ -286,7 +288,8 @@ class DualCarriages:
return {'carriage_modes': {dc.get_name() : dc.mode
for dc in self.dc_rails.values()},
'carriage_positions': {dc.get_name() : dc.get_axis_position(pos)
for dc in self.dc_rails.values()}}
for dc in self.dc_rails.values()},
'toolhead_position': tuple(pos)}
cmd_RESTORE_DUAL_CARRIAGE_STATE_help = \
"Restore dual carriages modes and positions"
def cmd_RESTORE_DUAL_CARRIAGE_STATE(self, gcmd):
@@ -300,12 +303,12 @@ class DualCarriages:
def restore_dual_carriage_state(self, saved_state, move, move_speed=0.):
toolhead = self.printer.lookup_object('toolhead')
toolhead.flush_step_generation()
move_pos = list(toolhead.get_position())
dcs = list(self.dc_rails.values())
if move:
homing_speed = 99999999.
move_pos = list(toolhead.get_position())
cur_pos = []
carriage_positions = saved_state['carriage_positions']
dcs = list(self.dc_rails.values())
for dc in dcs:
self.toggle_active_dc_rail(dc)
homing_speed = min(homing_speed, dc.rail.homing_speed)
@@ -335,9 +338,14 @@ class DualCarriages:
cur_pos[primary_ind])
toolhead.manual_move(move_pos, move_speed or homing_speed)
toolhead.flush_step_generation()
# Make sure the scaling coefficients are restored with the mode
for dc in dcs:
dc.inactivate(move_pos)
# Inactivate all carriages in order to restore scaling coefficients
# (if a move was requested) and correctly compute kinematics limits
for dc in dcs:
dc.inactivate(move_pos)
# Restore toolhead position in case some axes have no primary carriages
for axis in self.axes:
move_pos[axis] = saved_state['toolhead_position'][axis]
toolhead.set_position(move_pos)
saved_modes = saved_state['carriage_modes']
saved_primary_dcs = [dc for dc in self.dc_rails.values()
if saved_modes[dc.get_name()] == PRIMARY]
+27
View File
@@ -365,6 +365,33 @@ gcode:
SYNC_EXTRUDER_MOTION EXTRUDER=extruder2 MOTION_QUEUE=extruder
SYNC_EXTRUDER_MOTION EXTRUDER=extruder3 MOTION_QUEUE=extruder
[gcode_macro _DISABLE_TOOL]
gcode:
SAVE_GCODE_STATE
SET_DUAL_CARRIAGE CARRIAGE={params.CARRIAGE} MODE=INACTIVE
SAVE_DUAL_CARRIAGE_STATE
SET_DUAL_CARRIAGE CARRIAGE={params.CARRIAGE}
G1 X{params.PARKING_POSITION} F12000
SYNC_EXTRUDER_MOTION EXTRUDER={params.EXTRUDER} MOTION_QUEUE=
RESTORE_DUAL_CARRIAGE_STATE MOVE=0
RESTORE_GCODE_STATE MOVE=0
[gcode_macro DISABLE_T0]
gcode:
_DISABLE_TOOL CARRIAGE=carriage_t0 EXTRUDER=extruder PARKING_POSITION={printer.configfile.settings["carriage carriage_t0"].position_min}
[gcode_macro DISABLE_T1]
gcode:
_DISABLE_TOOL CARRIAGE=carriage_t1 EXTRUDER=extruder1 PARKING_POSITION={printer.configfile.settings["dual_carriage carriage_t1"].position_max}
[gcode_macro DISABLE_T2]
gcode:
_DISABLE_TOOL CARRIAGE=carriage_t2 EXTRUDER=extruder2 PARKING_POSITION={printer.configfile.settings["dual_carriage carriage_t2"].position_min}
[gcode_macro DISABLE_T3]
gcode:
_DISABLE_TOOL CARRIAGE=carriage_t3 EXTRUDER=extruder3 PARKING_POSITION={printer.configfile.settings["dual_carriage carriage_t3"].position_max}
[heater_bed]
heater_pin: PA1
sensor_pin: PF3 # TB
+7
View File
@@ -69,3 +69,10 @@ G1 X11 E0.1 F3000
SET_MIRROR_MODE2
G1 X10 Y10 F6000
G1 X11 E0.1 F3000
DISABLE_T0
G1 X12 E0.1
DISABLE_T2
G1 X13 E0.1
DISABLE_T3
G1 X14 E0.1