From f7d23705eacbcbfb0aa578d28aab63465b7159f0 Mon Sep 17 00:00:00 2001 From: HanifKoh <76276251+HanifKoh@users.noreply.github.com> Date: Tue, 27 Oct 2026 12:22:50 +0800 Subject: [PATCH] Name the Tool When a Temperature Tower Steps the Nozzle Temperature (#16898) The temperature tower re-targets the hotend at every layer with a bare M104. Every other temperature command on a multi-tool printer names its tool, and the firmware applies a tool-less M104 to whichever tool it considers active, so a tower assigned to any tool but the first heated the wrong nozzle. Pass the tool printing the tower, as the first-layer M109 right before it already does. --- src/libslic3r/GCode.cpp | 7 ++-- tests/fff_print/test_gcode.cpp | 66 ++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 3c63b6b440..7a51938e56 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -6751,6 +6751,9 @@ LayerResult GCode::process_layer( break; } case CalibMode::Calib_Temp_Tower: { + // Name the tool printing the tower: on a multi-tool printer a bare M104 goes to + // whichever tool the firmware considers active. + const int tool = m_writer.filament() ? static_cast(m_writer.filament()->id()) : -1; // ORCA-Belt: the sectioned variant prints each temperature as its // own object in native belt orientation, with the temperature // encoded in the object name ("temp_230") — step per object @@ -6759,9 +6762,9 @@ LayerResult GCode::process_layer( if (m_config.belt_printer.value && sscanf(layer.object()->model_object()->name.c_str(), "temp_%d", §ioned_temp) == 1 && sectioned_temp > 0) { - gcode += writer().set_temperature(static_cast(sectioned_temp)); + gcode += writer().set_temperature(static_cast(sectioned_temp), false, tool); } else { - gcode += writer().set_temperature(this->interpolate_value_across_layers(static_cast(print.calib_params().start), static_cast(print.calib_params().end), 5.0f)); + gcode += writer().set_temperature(this->interpolate_value_across_layers(static_cast(print.calib_params().start), static_cast(print.calib_params().end), 5.0f), false, tool); } break; } diff --git a/tests/fff_print/test_gcode.cpp b/tests/fff_print/test_gcode.cpp index 668a01c44a..5d1d0b07de 100644 --- a/tests/fff_print/test_gcode.cpp +++ b/tests/fff_print/test_gcode.cpp @@ -6,6 +6,7 @@ #include #include "libslic3r/BoundingBox.hpp" #include "libslic3r/Config.hpp" +#include "libslic3r/calib.hpp" #include "libslic3r/GCodeReader.hpp" #include "libslic3r/Model.hpp" #include "libslic3r/ModelArrange.hpp" @@ -25,6 +26,8 @@ #include #include #include +#include +#include #include #include #include @@ -460,3 +463,66 @@ TEST_CASE("An exported G-code's settings load back as the settings it was sliced CHECK_THAT(matrix[1] * multiplier[0], Catch::Matchers::WithinAbs(140., 1e-6)); CHECK(bundle.project_config.option>("prime_volume_mode")->value == PrimeVolumeMode::pvmFast); } + +// A temperature tower re-targets the hotend at every layer. On a multi-tool printer that +// command has to name the tool printing the tower: a bare M104 goes to whichever tool the +// firmware considers active, which the first-layer M109 right before it already addresses by +// tool index. A single-tool printer keeps the bare form. +TEST_CASE("The temperature tower steps the temperature of the tool printing it", "[GCode][Calib]") +{ + const bool multi_tool = GENERATE(false, true); + DYNAMIC_SECTION((multi_tool ? "two direct drive tools, the tower on the second one (filament 2 -> T1)" : "one tool")) { + DynamicPrintConfig config = multi_tool ? + Test::multifilament_config(2, { + {"nozzle_diameter", "0.4,0.4"}, + {"printer_extruder_id", "1,2"}, + {"printer_extruder_variant", "Direct Drive Standard,Direct Drive Standard"}, + {"extruder_printable_height", "0,0"}, + {"filament_self_index", "1,2"}, + {"single_extruder_multi_material", 0}, + {"enable_prime_tower", 0}, + {"nozzle_temperature_initial_layer", "230,230"}, + {"nozzle_temperature", "230,230"}, + }) : + DynamicPrintConfig::full_print_config(); + config.set_deserialize_strict({ + {"skirt_loops", 0}, + {"brim_type", "no_brim"}, + // Without the end G-code's heater-off M104 S0, every temperature command after the + // first layer change is the tower's. + {"machine_end_gcode", ""}, + }); + if (multi_tool) + Test::size_flush_to_nozzles(config); + + const std::vector> overrides{{{"extruder", multi_tool ? 2 : 1}}}; + Print print; + Model model; + // A 20 mm cube at the default 0.2 mm layer height is 100 layers, more than ten per band. + Test::init_print({Test::cube(20)}, print, model, config, &overrides); + Calib_Params params; + params.mode = CalibMode::Calib_Temp_Tower; + params.start = 230; + params.end = 190; + params.step = 5; + print.set_calib_params(params); + const std::string gcode = Test::gcode(print); + + const size_t layers_begin = gcode.find(";LAYER_CHANGE"); + REQUIRE(layers_begin != std::string::npos); + const std::regex temperature_command(R"(^M10[49] S(\d+)(?: T(\d+))?)"); + std::set temperatures; + std::set tools; + std::istringstream stream(gcode.substr(layers_begin)); + for (std::string line; std::getline(stream, line);) { + std::smatch m; + if (!std::regex_search(line, m, temperature_command)) + continue; + temperatures.insert(std::stoi(m[1])); + tools.insert(m[2].matched ? m[2].str() : "none"); + } + // Every 5 degree band from the start to the end temperature, and nothing else. + CHECK(temperatures == std::set{190, 195, 200, 205, 210, 215, 220, 225, 230}); + CHECK(tools == std::set{multi_tool ? "1" : "none"}); + } +}