From d9c27f3dee94e637cfafb83da1b1f9f48f4e46a0 Mon Sep 17 00:00:00 2001 From: HaythamB <49787517+HaythamB@users.noreply.github.com> Date: Sun, 20 Apr 2025 08:24:49 +0300 Subject: [PATCH] =?UTF-8?q?Fix=20#6839=20with=20final=20tool=20preheating?= =?UTF-8?q?=20on=20multitool=20machines=20causing=20in=E2=80=A6=20(#7405)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix #6839 with final tool preheating on multitool machines causing in appropriate temp settings Seems like Orca is trying to preheat the next tool in a multitool print, and ends up calling a heater off command in the last 30 seconds of any print. This happens because there's no handling to check if the next active tool is an actual valid tool index, or its a T-1 command to end the print since we're using the last tool. Simply moved the preheat commands into the conditional IF that automatically fixes this issue since the tool index is now properly evaluated. Co-authored-by: SoftFever --- src/libslic3r/GCode/GCodeProcessor.cpp | 95 +++++++++++++------------- 1 file changed, 48 insertions(+), 47 deletions(-) diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index d93f609e11..7b22a50eb5 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -4602,55 +4602,56 @@ void GCodeProcessor::run_post_process() if (m_print != nullptr) m_print->active_step_add_warning(PrintStateBase::WarningLevel::CRITICAL, warning); } - } - export_lines.insert_lines( - backtrace, cmd, - // line inserter - [tool_number, this](unsigned int id, const std::vector& time_diffs) { - const int temperature = int(m_layer_id != 1 ? m_extruder_temps_config[tool_number] : - m_extruder_temps_first_layer_config[tool_number]); - // Orca: M104.1 for XL printers, I can't find the documentation for this so I copied the C++ comments from - // Prusa-Firmware-Buddy here - /** - * M104.1: Early Set Hotend Temperature (preheat, and with stealth mode support) - * - * This GCode is used to tell the XL printer the time estimate when a tool will be used next, - * so that the printer can start preheating the tool in advance. - * - * ## Parameters - * - `P` - - time in seconds till the temperature S is required (in standard mode) - * - `Q` - - time in seconds till the temperature S is required (in stealth mode) - * The rest is same as M104 - */ - if (this->m_is_XL_printer) { - std::string out = "M104.1 T" + std::to_string(tool_number); - if (time_diffs.size() > 0) - out += " P" + std::to_string(int(std::round(time_diffs[0]))); - if (time_diffs.size() > 1) - out += " Q" + std::to_string(int(std::round(time_diffs[1]))); - out += " S" + std::to_string(temperature) + "\n"; - return out; - } else { - std::string comment = "preheat T" + std::to_string(tool_number) + - " time: " + std::to_string((int) std::round(time_diffs[0])) + "s"; - return GCodeWriter::set_temperature(temperature, this->m_flavor, false, tool_number, comment); - } - }, - // line replacer - [this, tool_number](const std::string& line) { - if (GCodeReader::GCodeLine::cmd_is(line, "M104")) { - GCodeReader::GCodeLine gline; - GCodeReader reader; - reader.parse_line(line, [&gline](GCodeReader& reader, const GCodeReader::GCodeLine& l) { gline = l; }); - - float val; - if (gline.has_value('T', val) && gline.raw().find("cooldown") != std::string::npos) { - if (static_cast(val) == tool_number) - return std::string("; removed M104\n"); + export_lines.insert_lines( + backtrace, cmd, + // line inserter + [tool_number, this](unsigned int id, const std::vector& time_diffs) { + const int temperature = int(m_layer_id != 1 ? m_extruder_temps_config[tool_number] : + m_extruder_temps_first_layer_config[tool_number]); + // Orca: M104.1 for XL printers, I can't find the documentation for this so I copied the C++ comments from + // Prusa-Firmware-Buddy here + /** + * M104.1: Early Set Hotend Temperature (preheat, and with stealth mode support) + * + * This GCode is used to tell the XL printer the time estimate when a tool will be used next, + * so that the printer can start preheating the tool in advance. + * + * ## Parameters + * - `P` - - time in seconds till the temperature S is required (in standard mode) + * - `Q` - - time in seconds till the temperature S is required (in stealth mode) + * The rest is same as M104 + */ + if (this->m_is_XL_printer) { + std::string out = "M104.1 T" + std::to_string(tool_number); + if (time_diffs.size() > 0) + out += " P" + std::to_string(int(std::round(time_diffs[0]))); + if (time_diffs.size() > 1) + out += " Q" + std::to_string(int(std::round(time_diffs[1]))); + out += " S" + std::to_string(temperature) + "\n"; + return out; + } else { + std::string comment = "preheat T" + std::to_string(tool_number) + + " time: " + std::to_string((int) std::round(time_diffs[0])) + "s"; + return GCodeWriter::set_temperature(temperature, this->m_flavor, false, tool_number, comment); } + }, + // line replacer + [this, tool_number](const std::string& line) { + if (GCodeReader::GCodeLine::cmd_is(line, "M104")) { + GCodeReader::GCodeLine gline; + GCodeReader reader; + reader.parse_line(line, [&gline](GCodeReader& reader, const GCodeReader::GCodeLine& l) { gline = l; }); + + float val; + if (gline.has_value('T', val) && gline.raw().find("cooldown") != std::string::npos) { + if (static_cast(val) == tool_number) + return std::string("; removed M104\n"); + } + } + return line; } - return line; - }); + ); + } } };