From f0a03d7921efb753accebfbacb4aef553d1d6a37 Mon Sep 17 00:00:00 2001 From: igiannakas <59056762+igiannakas@users.noreply.github.com> Date: Tue, 19 Sep 2023 18:49:01 +0300 Subject: [PATCH] Introduced parameter smoothing segment length This parameter influences the number of division a line will undergo in response to the requirement to adhere to the extrusion rate flow adjustment. --- src/libslic3r/ExtrusionRole.cpp | 31 ----------------------- src/libslic3r/GCode/PressureEqualizer.cpp | 13 +++++----- src/libslic3r/GCode/PressureEqualizer.hpp | 4 +++ src/libslic3r/Preset.cpp | 2 +- src/libslic3r/Print.cpp | 1 + src/libslic3r/PrintConfig.cpp | 11 ++++++++ src/libslic3r/PrintConfig.hpp | 1 + src/slic3r/GUI/ConfigManipulation.cpp | 7 +++++ src/slic3r/GUI/Tab.cpp | 1 + 9 files changed, 32 insertions(+), 39 deletions(-) diff --git a/src/libslic3r/ExtrusionRole.cpp b/src/libslic3r/ExtrusionRole.cpp index 7cee48d97e..81dcee695b 100644 --- a/src/libslic3r/ExtrusionRole.cpp +++ b/src/libslic3r/ExtrusionRole.cpp @@ -12,37 +12,6 @@ namespace Slic3r { - -/* IG For reference only. Defined in Extrusion Entity hpp. Do not uncomment: - -// Each ExtrusionRole value identifies a distinct set of { extruder, speed } -enum ExtrusionRole : uint8_t { - erNone, - erPerimeter, - erExternalPerimeter, - erOverhangPerimeter, - erInternalInfill, - erSolidInfill, - erTopSolidInfill, - erBottomSurface, - erIroning, - erBridgeInfill, - erInternalBridgeInfill, - erGapFill, - erSkirt, - erBrim, - erSupportMaterial, - erSupportMaterialInterface, - erSupportTransition, - erWipeTower, - erCustom, - // Extrusion role for a collection with multiple extrusion roles. - erMixed, - erCount -}; - -*/ - // Convert a rich bitmask based ExtrusionRole to a less expressive ordinal GCodeExtrusionRole. // GCodeExtrusionRole is to be serialized into G-code and deserialized by G-code viewer, GCodeExtrusionRole extrusion_role_to_gcode_extrusion_role(ExtrusionRole role) diff --git a/src/libslic3r/GCode/PressureEqualizer.cpp b/src/libslic3r/GCode/PressureEqualizer.cpp index d5d28f472a..3216f3afcf 100644 --- a/src/libslic3r/GCode/PressureEqualizer.cpp +++ b/src/libslic3r/GCode/PressureEqualizer.cpp @@ -24,10 +24,6 @@ static const std::string EXTRUDE_END_TAG = ";_EXTRUDE_END"; static const std::string EXTRUDE_SET_SPEED_TAG = ";_EXTRUDE_SET_SPEED"; static const std::string EXTERNAL_PERIMETER_TAG = ";_EXTERNAL_PERIMETER"; -// Maximum segment length to split a long segment if the initial and the final flow rate differ. -// Smaller value means a smoother transition between two different flow rates. -static constexpr float max_segment_length = 1.0f; - // For how many GCode lines back will adjust a flow rate from the latest line. // Bigger values affect the GCode export speed a lot, and smaller values could // affect how distant will be propagated a flow rate adjustment. @@ -52,6 +48,8 @@ PressureEqualizer::PressureEqualizer(const Slic3r::GCodeConfig &config) : m_use_ m_current_extrusion_role = GCodeExtrusionRole::None; // Expect the first command to fill the nozzle (deretract). m_retracted = true; + + m_max_segment_length = 2.f; // Calculate filamet crossections for the multiple extruders. m_filament_crossections.clear(); @@ -67,6 +65,7 @@ PressureEqualizer::PressureEqualizer(const Slic3r::GCodeConfig &config) : m_use_ if(config.max_volumetric_extrusion_rate_slope.value > 0){ m_max_volumetric_extrusion_rate_slope_positive = float(config.max_volumetric_extrusion_rate_slope.value) * 60.f * 60.f; m_max_volumetric_extrusion_rate_slope_negative = float(config.max_volumetric_extrusion_rate_slope.value) * 60.f * 60.f; + m_max_segment_length = float(config.max_volumetric_extrusion_rate_slope_segment_length.value); } for (ExtrusionRateSlope &extrusion_rate_slope : m_max_volumetric_extrusion_rate_slopes) { @@ -489,7 +488,7 @@ void PressureEqualizer::output_gcode_line(const size_t line_idx) // Emit the line with lowered extrusion rates. float l = line.dist_xyz(); - if (auto nSegments = size_t(ceil(l / max_segment_length)); nSegments == 1) { // Just update this segment. + if (auto nSegments = size_t(ceil(l / m_max_segment_length)); nSegments == 1) { // Just update this segment. push_line_to_output(line_idx, line.feedrate() * line.volumetric_correction_avg(), comment); } else { bool accelerating = line.volumetric_extrusion_rate_start < line.volumetric_extrusion_rate_end; @@ -512,11 +511,11 @@ void PressureEqualizer::output_gcode_line(const size_t line_idx) // One may achieve higher print speeds if part of the segment is not speed limited. l_acc = t_acc * feed_avg; l_steady = l - l_acc; - if (l_steady < 0.5f * max_segment_length) { + if (l_steady < 0.5f * m_max_segment_length) { l_acc = l; l_steady = 0.f; } else - nSegments = size_t(ceil(l_acc / max_segment_length)); + nSegments = size_t(ceil(l_acc / m_max_segment_length)); } float pos_start[5]; float pos_end[5]; diff --git a/src/libslic3r/GCode/PressureEqualizer.hpp b/src/libslic3r/GCode/PressureEqualizer.hpp index 52d9023b75..1e9f013396 100644 --- a/src/libslic3r/GCode/PressureEqualizer.hpp +++ b/src/libslic3r/GCode/PressureEqualizer.hpp @@ -86,6 +86,10 @@ private: bool m_retracted; bool m_use_relative_e_distances; + // Maximum segment length to split a long segment if the initial and the final flow rate differ. + // Smaller value means a smoother transition between two different flow rates. + float m_max_segment_length; + // Indicate if extrude set speed block was opened using the tag ";_EXTRUDE_SET_SPEED" // or not (not opened, or it was closed using the tag ";_EXTRUDE_END"). bool opened_extrude_set_speed_block = false; diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 65aeae9c54..7568a015f0 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -725,7 +725,7 @@ static std::vector s_Preset_print_options { "ironing_type", "ironing_pattern", "ironing_flow", "ironing_speed", "ironing_spacing", "max_travel_detour_distance", "fuzzy_skin", "fuzzy_skin_thickness", "fuzzy_skin_point_distance", - "max_volumetric_extrusion_rate_slope", + "max_volumetric_extrusion_rate_slope", "max_volumetric_extrusion_rate_slope_segment_length", "inner_wall_speed", "outer_wall_speed", "sparse_infill_speed", "internal_solid_infill_speed", "top_surface_speed", "support_speed", "support_object_xy_distance", "support_interface_speed", "bridge_speed", "internal_bridge_speed", "gap_infill_speed", "travel_speed", "travel_speed_z", "initial_layer_speed", diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index 6a94e7f064..43d1c7cdcf 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -129,6 +129,7 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n "printable_height", "slow_down_min_speed", "max_volumetric_extrusion_rate_slope", + "max_volumetric_extrusion_rate_slope_segment_length", "reduce_infill_retraction", "filename_format", "retraction_minimum_travel", diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 3b80c8dc7c..0396886141 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -2490,6 +2490,17 @@ def = this->add("filament_loading_speed", coFloats); def->min = 0; def->mode = comAdvanced; def->set_default_value(new ConfigOptionFloat(0)); + + def = this->add("max_volumetric_extrusion_rate_slope_segment_length", coInt); + def->label = L("Smoothing segment length"); + def->tooltip = L("A lower value results in smoother extrusion rate transitions. However, this results in a significantly larger gcode file " + "and more instructions for the printer to process. \n\n" + "Default value of 2 works well for most cases. If your printer is stuttering, increase this value to reduce the number of adjustments made\n\n" + "Allowed values: 1-5"); + def->min = 1; + def->max = 5; + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionInt(2)); def = this->add("fan_min_speed", coInts); def->label = L("Fan speed"); diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index beea7a5783..57b82efd47 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -883,6 +883,7 @@ PRINT_CONFIG_CLASS_DEFINE( ((ConfigOptionString, layer_change_gcode)) ((ConfigOptionFloat, max_volumetric_extrusion_rate_slope)) + ((ConfigOptionInt, max_volumetric_extrusion_rate_slope_segment_length)) ((ConfigOptionPercents, retract_before_wipe)) ((ConfigOptionFloats, retraction_length)) diff --git a/src/slic3r/GUI/ConfigManipulation.cpp b/src/slic3r/GUI/ConfigManipulation.cpp index c92ff68558..35209f01b5 100644 --- a/src/slic3r/GUI/ConfigManipulation.cpp +++ b/src/slic3r/GUI/ConfigManipulation.cpp @@ -510,8 +510,15 @@ void ConfigManipulation::toggle_print_fff_options(DynamicPrintConfig *config, co auto gcflavor = preset_bundle->printers.get_edited_preset().config.option>("gcode_flavor")->value; bool have_volumetric_extrusion_rate_slope = config->option("max_volumetric_extrusion_rate_slope")->value > 0; + int have_volumetric_extrusion_rate_slope_segment_length = config->option("max_volumetric_extrusion_rate_slope_segment_length")->value; toggle_field("enable_arc_fitting", !have_volumetric_extrusion_rate_slope); + toggle_line("max_volumetric_extrusion_rate_slope_segment_length", have_volumetric_extrusion_rate_slope); if(have_volumetric_extrusion_rate_slope) config->set_key_value("enable_arc_fitting", new ConfigOptionBool(false)); + if(have_volumetric_extrusion_rate_slope_segment_length==0) { + DynamicPrintConfig new_conf = *config; + new_conf.set_key_value("max_volumetric_extrusion_rate_slope_segment_length", new ConfigOptionInt(1)); + apply(config, &new_conf); + } bool have_perimeters = config->opt_int("wall_loops") > 0; for (auto el : { "extra_perimeters_on_overhangs", "ensure_vertical_shell_thickness", "detect_thin_wall", "detect_overhang_wall", diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 9d8c576c80..370fcf2bc9 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -1998,6 +1998,7 @@ void TabPrint::build() optgroup = page->new_optgroup(L("Advanced"), L"param_advanced", 15); optgroup->append_single_option_line("max_volumetric_extrusion_rate_slope"); + optgroup->append_single_option_line("max_volumetric_extrusion_rate_slope_segment_length"); page = add_options_page(L("Support"), "support"); optgroup = page->new_optgroup(L("Support"), L"param_support");