Join Precise-Z Sliver Layers to the Prime Tower Layer Below (#17204)

* Join Precise-Z Sliver Layers to the Prime Tower Layer Below

Precise Z height ends each object at its exact top, so another object's
layers can print a few microns above these. Each sliver became its own
wipe tower layer, and a tool change on it was sized for that height: a
0.0009 mm layer asked for a 230 mm ramming band, which grew the tower
past the bed ("Prime tower is partially outside the printable area").
Once sized correctly, G-code export lost step with the tower and threw
"append_tcr was asked to do a toolchange it didn't expect".

A tower layer thinner than half the printer's minimum layer height now
joins the tower layer below: ToolOrdering records the tower layer each
layer prints on and whether it finishes it, the tower plans the joined
tool changes on that layer's z and height, and the G-code neither
advances the tower on a joined layer nor finishes the layer before it.

* Finish a Joined Prime Tower Layer on Its Last Tool Change

The joined layer always finished the tower layer, so a joined layer that
changed no tools asked for a result after the layer below had taken them
all and threw "Wipe tower generation failed". The layer that finishes is
now the last of the group that changes tools, or the last one when none
does, matching how a single layer merges its finish into a tool change.

A joined layer also reset the Type 1 tower's first print, so smooth
timelapse replayed the tower layer's wall and threw the same error.

Layers are now joined below the printer's minimum layer height instead of
half of it: precise Z height can move a layer off by up to a layer height,
and the 0.04-0.08 mm layers left on their own still grew the tower off the
bed.

* Print Joined Prime Tower Purges at the Tower Layer's Z

A joined layer printed its purges at its own nozzle height, up to just
under the minimum layer height above the tower layer, so the beads were
not pressed onto it. The emitter now descends to the tower layer's z for
a joined layer, travelling over the tower first and climbing back after,
the way it already does for a tower compacted below the objects.

Layers sliced at exactly the minimum layer height sum to gaps a hair
under it and were joined to the layer below; an EPSILON margin keeps
them apart.

* Travel Over the Prime Tower Before a Joined Layer Descends

With no change_filament_gcode and no nozzle change, the Type 1 emitter
descended to the joined tower layer's z while the head was still over the
part, then travelled to the tower at that z. It now travels over the tower
first. The tests check that every descent below the object layer happens
over the tower.
This commit is contained in:
HanifKoh authored and GitHub committed 2026-11-04 13:14:01 +08:00
1 parent 5191a5efeb
commit 1c9f6f9318
7 files changed
+290 -24

No files matched your search

+48 -5
View File
@@ -192,6 +192,14 @@ static double calc_max_layer_height(const PrintConfig &config, double max_object
return std::max(max_layer_height, max_object_layer_height);
}
static double calc_min_layer_height(const PrintConfig &config)
{
double min_layer_height = std::numeric_limits<double>::max();
for (size_t i = 0; i < config.nozzle_diameter.values.size(); ++ i)
min_layer_height = std::min(min_layer_height, config.min_layer_height.get_at(i));
return config.nozzle_diameter.values.empty() ? 0. : min_layer_height;
}
//calculate the flush weight (first value) and filament change count(second value)
// Nozzle-aware flush-stat calculator. Resolves each
// filament in the print sequence to its physical nozzle via the grouping result and tracks a
@@ -1233,13 +1241,48 @@ void ToolOrdering::fill_wipe_tower_partitions(const PrintConfig &config, coordf_
}
}
// Calculate the wipe_tower_layer_height values.
coordf_t wipe_tower_print_z_last = 0.;
for (LayerTools &lt : m_layer_tools)
if (lt.has_wipe_tower) {
// Calculate the wipe_tower_layer_height values. Precise Z height ends each object at its exact
// top, so another object's layers can sit above these by less than the printer's minimum layer
// height. A tower layer that thin cannot be printed, and a purge sized for it runs up to hundreds
// of mm long, so it joins the tower layer below. The floor matches the towers' own WT_EPSILON
// merge, which would otherwise size the joined tool changes with the sliver's height. The EPSILON
// margin keeps layers sliced at exactly the minimum height, whose sums round below it, apart.
const double min_tower_layer_height = std::max(calc_min_layer_height(config), 1e-3);
coordf_t wipe_tower_print_z_last = 0.;
// The layer that finishes the current tower layer, and whether any layer of it changes tools.
LayerTools *tower_layer_end = nullptr;
bool tower_layer_changes = false;
unsigned int current_extruder = (unsigned int) -1;
for (LayerTools &lt : m_layer_tools) {
lt.wipe_tower_layer_ends = true;
// The G-code takes one tower result per tool change, so a layer that changes tools always
// takes one; a layer that does not takes one only when it finishes the tower layer.
const bool changes = ! lt.extruders.empty() &&
(current_extruder == (unsigned int) -1 || lt.extruders.size() > 1 || lt.extruders.front() != current_extruder);
if (! lt.extruders.empty())
current_extruder = lt.extruders.back();
if (! lt.has_wipe_tower)
continue;
// Only a layer that prints joins, so the tower layer is always finished by a printing layer.
if (tower_layer_end != nullptr && ! lt.extruders.empty() && lt.print_z - wipe_tower_print_z_last + EPSILON < min_tower_layer_height) {
lt.wipe_tower_print_z = tower_layer_end->wipe_tower_print_z;
lt.wipe_tower_layer_height = tower_layer_end->wipe_tower_layer_height;
// The finish rides on the last tool change of the joined layers, as it does on its own
// layer: one that takes over after the last result is gone has nothing left to print.
if (changes || ! tower_layer_changes) {
tower_layer_end->wipe_tower_layer_ends = false;
tower_layer_end = &lt;
} else
lt.wipe_tower_layer_ends = false;
tower_layer_changes |= changes;
} else {
lt.wipe_tower_print_z = lt.print_z;
lt.wipe_tower_layer_height = lt.print_z - wipe_tower_print_z_last;
wipe_tower_print_z_last = lt.print_z;
wipe_tower_print_z_last = lt.print_z;
tower_layer_end = &lt;
tower_layer_changes = changes;
}
}
}
void ToolOrdering::collect_extruder_statistics(bool prime_multi_material)