From ccf58b3fc6de568339c0dfc4f2adc8928bb29754 Mon Sep 17 00:00:00 2001 From: "xun.zhang" Date: Wed, 12 Mar 2025 16:06:54 +0800 Subject: [PATCH] ENH: set cooling/heating rate as extruder param jira:NONE Signed-off-by: xun.zhang Change-Id: Ia5eb6ba5bea0351ebcc3867644a518fb5560e500 --- .../BBL/machine/Bambu Lab H2D 0.4 nozzle.json | 7 ++++- .../BBL/machine/fdm_bbl_3dp_002_common.json | 12 +++++++++ .../BBL/machine/fdm_machine_common.json | 8 ++++-- src/libslic3r/GCode/GCodeProcessor.cpp | 27 ++++++++++--------- src/libslic3r/GCode/GCodeProcessor.hpp | 20 +++++++------- src/libslic3r/PrintConfig.cpp | 14 ++++++---- src/libslic3r/PrintConfig.hpp | 4 +-- 7 files changed, 60 insertions(+), 32 deletions(-) diff --git a/resources/profiles/BBL/machine/Bambu Lab H2D 0.4 nozzle.json b/resources/profiles/BBL/machine/Bambu Lab H2D 0.4 nozzle.json index 0adef3406..03855590a 100644 --- a/resources/profiles/BBL/machine/Bambu Lab H2D 0.4 nozzle.json +++ b/resources/profiles/BBL/machine/Bambu Lab H2D 0.4 nozzle.json @@ -27,7 +27,12 @@ "0x0,325x0,325x320,0x320", "25x0,350x0,350x320,25x320" ], - "hotend_heating_rate": "3.6", + "hotend_heating_rate": [ + "3.6", + "3.6", + "3.6", + "3.6" + ], "machine_load_filament_time": "24", "machine_max_acceleration_x": [ "16000", diff --git a/resources/profiles/BBL/machine/fdm_bbl_3dp_002_common.json b/resources/profiles/BBL/machine/fdm_bbl_3dp_002_common.json index 3b3c169b0..a86aff036 100644 --- a/resources/profiles/BBL/machine/fdm_bbl_3dp_002_common.json +++ b/resources/profiles/BBL/machine/fdm_bbl_3dp_002_common.json @@ -66,6 +66,18 @@ "0" ], "head_wrap_detect_zone": [], + "hotend_cooling_rate": [ + "2", + "2", + "2", + "2" + ], + "hotend_heating_rate": [ + "2", + "2", + "2", + "2" + ], "long_retractions_when_cut": [ "0", "0", diff --git a/resources/profiles/BBL/machine/fdm_machine_common.json b/resources/profiles/BBL/machine/fdm_machine_common.json index 8e5b3852d..1b6a19638 100644 --- a/resources/profiles/BBL/machine/fdm_machine_common.json +++ b/resources/profiles/BBL/machine/fdm_machine_common.json @@ -24,8 +24,12 @@ "enable_long_retraction_when_cut" : "0", "enable_pre_heating": "0", "bed_temperature_formula" : "by_first_filament", - "hotend_cooling_rate": "2", - "hotend_heating_rate": "2", + "hotend_cooling_rate": [ + "2" + ], + "hotend_heating_rate": [ + "2" + ], "extruder_offset": [ "0x0" ], diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index 96d8bf381..557c13f38 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -1668,8 +1668,8 @@ void GCodeProcessor::apply_config(const PrintConfig& config) for (size_t idx = 0; idx < filament_count; ++idx) m_filament_types[idx] = config.filament_type.get_at(idx); - m_hotend_cooling_rate = config.hotend_cooling_rate.value; - m_hotend_heating_rate = config.hotend_heating_rate.value; + m_hotend_cooling_rate = config.hotend_cooling_rate.values; + m_hotend_heating_rate = config.hotend_heating_rate.values; m_enable_pre_heating = config.enable_pre_heating; m_physical_extruder_map = config.physical_extruder_map.values; @@ -1775,14 +1775,14 @@ void GCodeProcessor::apply_config(const DynamicPrintConfig& config) m_filament_types[idx] = filament_type->get_at(idx); } - const ConfigOptionFloat* hotend_cooling_rate = config.option("hotend_cooling_rate"); + const ConfigOptionFloatsNullable* hotend_cooling_rate = config.option("hotend_cooling_rate"); if (hotend_cooling_rate != nullptr) { - m_hotend_cooling_rate = hotend_cooling_rate->value; + m_hotend_cooling_rate = hotend_cooling_rate->values; } - const ConfigOptionFloat* hotend_heating_rate = config.option("hotend_heating_rate"); + const ConfigOptionFloatsNullable* hotend_heating_rate = config.option("hotend_heating_rate"); if (hotend_heating_rate != nullptr) { - m_hotend_heating_rate = hotend_heating_rate->value; + m_hotend_heating_rate = hotend_heating_rate->values; } const ConfigOptionBool* enable_pre_heating = config.option("enable_pre_heating"); @@ -2145,7 +2145,7 @@ void GCodeProcessor::reset() m_physical_extruder_map.clear(); m_filament_nozzle_temp.clear(); m_enable_pre_heating = false; - m_hotend_cooling_rate = m_hotend_heating_rate = 2.f; + m_hotend_cooling_rate = m_hotend_heating_rate = { 2.f }; m_highest_bed_temp = 0; @@ -5969,9 +5969,12 @@ void GCodeProcessor::PreCoolingInjector::inject_cooling_heating_command(TimeProc if (!apply_cooling_when_partial_free && complete_free_time_gap < inject_time_threshold) return; + float ext_heating_rate = heating_rate[block.extruder_id]; + float ext_cooling_rate = cooling_rate[block.extruder_id]; + if (is_tpu_filament(block.last_filament_id) && pre_cooling) { if (partial_free_move_lower < partial_free_move_upper) { - float max_cooling_temp = std::min(curr_temp, std::min(partial_free_cooling_thres, partial_free_time_gap * cooling_rate)); + float max_cooling_temp = std::min(curr_temp, std::min(partial_free_cooling_thres, partial_free_time_gap * ext_cooling_rate)); curr_temp -= max_cooling_temp; // set the temperature after doing cooling when post-extruding inserted_operation_lines[partial_free_move_lower->gcode_id].emplace_back(format_line_M104(curr_temp, block.extruder_id, "Multi extruder pre cooling in post extrusion"), TimeProcessor::InsertLineType::PreCooling); } @@ -5988,7 +5991,7 @@ void GCodeProcessor::PreCoolingInjector::inject_cooling_heating_command(TimeProc // only perform heating if (target_temp <= curr_temp) return; - float heating_start_time = move_iter_upper->time[valid_machine_id] - (target_temp - curr_temp) / heating_rate; + float heating_start_time = move_iter_upper->time[valid_machine_id] - (target_temp - curr_temp) / ext_heating_rate; auto heating_move_iter = std::upper_bound(move_iter_lower, move_iter_upper + 1, heating_start_time, [valid_machine_id = this->valid_machine_id](float time, const GCodeProcessorResult::MoveVertex& a) {return time < a.time[valid_machine_id]; }); if (heating_move_iter == move_iter_upper + 1 || heating_move_iter == move_iter_lower) { inserted_operation_lines[block.free_lower_gcode_id].emplace_back(format_line_M104(target_temp, block.extruder_id, "Multi extruder pre heating"), TimeProcessor::InsertLineType::PreHeating); @@ -6000,9 +6003,9 @@ void GCodeProcessor::PreCoolingInjector::inject_cooling_heating_command(TimeProc return; } // perform cooling first and then perform heating - float mid_temp = std::max(0.f, (curr_temp * heating_rate + target_temp * cooling_rate - complete_free_time_gap * cooling_rate * heating_rate) / (cooling_rate + heating_rate)); + float mid_temp = std::max(0.f, (curr_temp * ext_heating_rate + target_temp * ext_cooling_rate - complete_free_time_gap * ext_cooling_rate * ext_heating_rate) / (ext_cooling_rate + ext_heating_rate)); float heating_temp = target_temp - mid_temp; - float heating_start_time = move_iter_upper->time[valid_machine_id] - heating_temp / heating_rate; + float heating_start_time = move_iter_upper->time[valid_machine_id] - heating_temp / ext_heating_rate; auto heating_move_iter = std::upper_bound(move_iter_lower, move_iter_upper + 1, heating_start_time, [valid_machine_id = this->valid_machine_id](float time, const GCodeProcessorResult::MoveVertex& a) {return time < a.time[valid_machine_id]; }); if (heating_move_iter == move_iter_lower || heating_move_iter == move_iter_upper + 1) return; @@ -6010,7 +6013,7 @@ void GCodeProcessor::PreCoolingInjector::inject_cooling_heating_command(TimeProc --heating_move_iter; // get the insert pos of heat cmd and recalculate time gap and delta temp float real_cooling_time = heating_move_iter->time[valid_machine_id] - move_iter_lower->time[valid_machine_id]; - int real_delta_temp = std::min((int)(real_cooling_time * cooling_rate), (int)curr_temp); + int real_delta_temp = std::min((int)(real_cooling_time * ext_cooling_rate), (int)curr_temp); if (real_delta_temp == 0) return; inserted_operation_lines[block.free_lower_gcode_id].emplace_back(format_line_M104(curr_temp - real_delta_temp, block.extruder_id, "Multi extruder pre cooling"), TimeProcessor::InsertLineType::PreCooling); diff --git a/src/libslic3r/GCode/GCodeProcessor.hpp b/src/libslic3r/GCode/GCodeProcessor.hpp index 11bf4b0b3..e8804250f 100644 --- a/src/libslic3r/GCode/GCodeProcessor.hpp +++ b/src/libslic3r/GCode/GCodeProcessor.hpp @@ -691,8 +691,8 @@ namespace Slic3r { std::vector physical_extruder_map; size_t total_layer_num; - float cooling_rate{ 2.f }; // Celsius degree per second - float heating_rate{ 2.f }; // Celsius degree per second + std::vector cooling_rate{ 2.f }; // Celsius degree per second + std::vector heating_rate{ 2.f }; // Celsius degree per second float inject_time_threshold{ 30.f }; // only active pre cooling & heating if time gap is bigger than threshold float post_extrusion_cooling_threshold{ 30.f }; // threshold of temp if do cooling in post extrusion bool enable_pre_heating{ false }; @@ -705,8 +705,8 @@ namespace Slic3r { const std::vector& filament_nozzle_temp_, const std::vector& physical_extruder_map_, const size_t total_layer_num_, - const float cooling_rate_, - const float heating_rate_, + const std::vector& cooling_rate_, + const std::vector& heating_rate_, const float inject_time_threshold_, const bool enable_pre_heating_ ) : @@ -810,8 +810,8 @@ namespace Slic3r { int valid_machine_id_, float inject_time_threshold_, float partial_free_cooling_thres_, - float cooling_rate_, - float heating_rate_, + const std::vector& cooling_rate_, + const std::vector& heating_rate_, unsigned int machine_start_gcode_end_id_, unsigned int machine_end_gcode_start_id_ ) : @@ -840,8 +840,8 @@ namespace Slic3r { const int valid_machine_id; const float inject_time_threshold; const float partial_free_cooling_thres; // threshold of cooling temp during post extrusion - const float cooling_rate; - const float heating_rate; + const std::vector& cooling_rate; + const std::vector& heating_rate; const unsigned int machine_start_gcode_end_id; const unsigned int machine_end_gcode_start_id; @@ -1012,8 +1012,8 @@ namespace Slic3r { std::vector m_filament_lists; std::vector m_filament_nozzle_temp; std::vector m_filament_types; - float m_hotend_cooling_rate{ 2.f }; - float m_hotend_heating_rate{ 2.f }; + std::vector m_hotend_cooling_rate{ 2.f }; + std::vector m_hotend_heating_rate{ 2.f }; float m_enable_pre_heating{ false }; std::vector m_physical_extruder_map; diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 7ec660995..d7673d0c3 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -1772,11 +1772,13 @@ void PrintConfigDef::init_fff_params() def->mode = comAdvanced; def->set_default_value(new ConfigOptionFloat(5)); - def = this->add("hotend_cooling_rate", coFloat); - def->set_default_value(new ConfigOptionFloat(2)); + def = this->add("hotend_cooling_rate", coFloats); + def->nullable = true; + def->set_default_value(new ConfigOptionFloatsNullable{2}); - def = this->add("hotend_heating_rate", coFloat); - def->set_default_value(new ConfigOptionFloat(2)); + def = this->add("hotend_heating_rate", coFloats); + def->nullable = true; + def->set_default_value(new ConfigOptionFloatsNullable{2}); def = this->add("enable_pre_heating", coBool); def->set_default_value(new ConfigOptionBool(false)); @@ -5658,7 +5660,9 @@ std::set printer_options_with_variant_1 = { "nozzle_volume", "nozzle_type", "printer_extruder_id", - "printer_extruder_variant" + "printer_extruder_variant", + "hotend_cooling_rate", + "hotend_heating_rate" }; //options with silient mode diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index e0444cbb4..f59a973dc 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -1050,8 +1050,8 @@ PRINT_CONFIG_CLASS_DEFINE( ((ConfigOptionBool, enable_pre_heating)) ((ConfigOptionEnum, bed_temperature_formula)) ((ConfigOptionInts, physical_extruder_map)) - ((ConfigOptionFloat, hotend_cooling_rate)) - ((ConfigOptionFloat, hotend_heating_rate)) + ((ConfigOptionFloatsNullable, hotend_cooling_rate)) + ((ConfigOptionFloatsNullable, hotend_heating_rate)) ((ConfigOptionFloats, filament_minimal_purge_on_wipe_tower)) // BBS ((ConfigOptionBool, scan_first_layer))