diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 6ec05e0fe7..3c9bcccd9a 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -1597,7 +1597,10 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato //BBS: open spaghetti detector // if (print.config().spaghetti_detector.value) file.write("M981 S1 P20000 ;open spaghetti detector\n"); - + if(m_config.enable_pressure_advance.value) + { + file.write_format("M900 K%.3f\nM900 S0\n",m_config.pressure_advance.values.front()); + } // Do all objects for each layer. if (print.config().print_sequence == PrintSequence::ByObject) { size_t finished_objects = 0; @@ -2499,6 +2502,12 @@ GCode::LayerResult GCode::process_layer( double acceleration = m_config.initial_layer_acceleration.value; gcode += m_writer.set_acceleration((unsigned int)floor(acceleration + 0.5)); } + + if (m_config.default_jerk.value > 0 && m_config.initial_layer_jerk.value > 0) { + double jerk = m_config.initial_layer_jerk.value; + gcode += m_writer.set_jerk_xy((unsigned int)floor(jerk + 0.5)); + } + } if (! first_layer && ! m_second_layer_things_done) { @@ -2521,6 +2530,12 @@ GCode::LayerResult GCode::process_layer( double acceleration = m_config.default_acceleration.value; gcode += m_writer.set_acceleration((unsigned int)floor(acceleration + 0.5)); } + + if (m_config.default_jerk.value > 0 && m_config.initial_layer_jerk.value > 0) { + double jerk = m_config.default_jerk.value; + gcode += m_writer.set_jerk_xy((unsigned int)floor(jerk + 0.5)); + } + // Transition from 1st to 2nd layer. Adjust nozzle temperatures as prescribed by the nozzle dependent // nozzle_temperature_initial_layer vs. temperature settings. for (const Extruder &extruder : m_writer.extruders()) { @@ -3235,9 +3250,13 @@ std::string GCode::extrude_loop(ExtrusionLoop loop, std::string description, dou } //BBS: don't reset acceleration when printing first layer. During first layer, acceleration is always same value. - if (!this->on_first_layer()) + if (!this->on_first_layer()){ // reset acceleration - gcode += m_writer.set_acceleration((unsigned int)(m_config.default_acceleration.value + 0.5)); + if(m_config.default_acceleration.value > 0) + gcode += m_writer.set_acceleration((unsigned int)(m_config.default_acceleration.value + 0.5)); + if(m_config.default_jerk.value > 0) + gcode += m_writer.set_jerk_xy((unsigned int)(m_config.default_jerk.value + 0.5)); + } // BBS if (m_wipe.enable) { @@ -3310,9 +3329,12 @@ std::string GCode::extrude_multi_path(ExtrusionMultiPath multipath, std::string m_wipe.path.reverse(); } //BBS: don't reset acceleration when printing first layer. During first layer, acceleration is always same value. - if (!this->on_first_layer()) + if (!this->on_first_layer()) { // reset acceleration gcode += m_writer.set_acceleration((unsigned int)floor(m_config.default_acceleration.value + 0.5)); + if(m_config.default_jerk.value > 0) + gcode += m_writer.set_jerk_xy((unsigned int)floor(m_config.default_jerk.value + 0.5)); + } return gcode; } @@ -3338,9 +3360,13 @@ std::string GCode::extrude_path(ExtrusionPath path, std::string description, dou m_wipe.path.reverse(); } //BBS: don't reset acceleration when printing first layer. During first layer, acceleration is always same value. - if (!this->on_first_layer()) + if (!this->on_first_layer()){ // reset acceleration gcode += m_writer.set_acceleration((unsigned int)floor(m_config.default_acceleration.value + 0.5)); + if(m_config.default_jerk.value > 0) + gcode += m_writer.set_jerk_xy((unsigned int)floor(m_config.default_jerk.value + 0.5)); + + } return gcode; } @@ -3551,6 +3577,23 @@ std::string GCode::_extrude(const ExtrusionPath &path, std::string description, gcode += m_writer.set_acceleration((unsigned int)floor(acceleration + 0.5)); } + // adjust X Y jerk + if (m_config.default_jerk.value > 0) { + double jerk; + if (this->on_first_layer() && m_config.initial_layer_jerk.value > 0) { + jerk = m_config.initial_layer_jerk.value; + } else if (m_config.outer_wall_jerk.value > 0 && is_external_perimeter(path.role())) { + jerk = m_config.outer_wall_jerk.value; + } else if (m_config.inner_wall_jerk.value > 0 && is_internal_perimeter(path.role())) { + jerk = m_config.inner_wall_jerk.value; + } else if (m_config.top_surface_jerk.value > 0 && is_top_surface(path.role())) { + jerk = m_config.top_surface_jerk.value; + } else { + jerk = m_config.default_jerk.value; + } + gcode += m_writer.set_jerk_xy((unsigned int)floor(jerk + 0.5)); + } + // calculate extrusion length per distance unit double e_per_mm = m_writer.extruder()->e_per_mm3() * path.mm3_per_mm; @@ -3763,7 +3806,34 @@ std::string GCode::travel_to(const Point &point, ExtrusionRole role, std::string bool could_be_wipe_disabled = false; // Save state of use_external_mp_once for the case that will be needed to call twice m_avoid_crossing_perimeters.travel_to. const bool used_external_mp_once = m_avoid_crossing_perimeters.used_external_mp_once(); + std::string gcode; + // SoftFever + if (this->on_first_layer()) { + if(m_config.default_acceleration.value > 0) + { + auto jerk = (unsigned int)floor(m_config.initial_layer_jerk.value + 0.5); + auto accel = (unsigned int)floor(m_config.initial_layer_acceleration.value + 0.5); + if(jerk > 0) + gcode += m_writer.set_jerk_xy(jerk); + + if(accel > 0) + gcode += m_writer.set_acceleration(accel); + } + } + else + { + if(m_config.default_jerk.value > 0) + { + auto jerk = (unsigned int)floor(m_config.travel_jerk.value + 0.5); + auto accel = (unsigned int)floor(m_config.travel_acceleration.value + 0.5); + if(jerk > 0) + gcode += m_writer.set_jerk_xy(jerk); + + if(accel > 0) + gcode += m_writer.set_acceleration(accel); + } + } // if a retraction would be needed, try to use reduce_crossing_wall to plan a // multi-hop travel path inside the configuration space if (needs_retraction @@ -3779,7 +3849,6 @@ std::string GCode::travel_to(const Point &point, ExtrusionRole role, std::string m_avoid_crossing_perimeters.reset_once_modifiers(); // generate G-code for the travel move - std::string gcode; if (needs_retraction) { if (m_config.reduce_crossing_wall && could_be_wipe_disabled) m_wipe.reset_path(); @@ -3810,9 +3879,9 @@ std::string GCode::travel_to(const Point &point, ExtrusionRole role, std::string if (i == travel.size() - 1 && !m_spiral_vase) { Vec2d dest2d = this->point_to_gcode(travel.points[i]); Vec3d dest3d(dest2d(0), dest2d(1), m_nominal_z); - gcode += m_writer.travel_to_xyz(dest3d, comment); + gcode += m_writer.travel_to_xyz(dest3d, comment+" travel_to_xyz"); } else { - gcode += m_writer.travel_to_xy(this->point_to_gcode(travel.points[i]), comment); + gcode += m_writer.travel_to_xy(this->point_to_gcode(travel.points[i]), comment+" travel_to_xy"); } } this->set_last_pos(travel.points.back()); diff --git a/src/libslic3r/GCodeWriter.cpp b/src/libslic3r/GCodeWriter.cpp index 4b0739b9c8..16231dc67d 100644 --- a/src/libslic3r/GCodeWriter.cpp +++ b/src/libslic3r/GCodeWriter.cpp @@ -15,7 +15,7 @@ namespace Slic3r { -const bool GCodeWriter::full_gcode_comment = false; +const bool GCodeWriter::full_gcode_comment = true; const double GCodeWriter::slope_threshold = 3 * PI / 180; void GCodeWriter::apply_print_config(const PrintConfig &print_config) @@ -24,6 +24,7 @@ void GCodeWriter::apply_print_config(const PrintConfig &print_config) m_single_extruder_multi_material = print_config.single_extruder_multi_material.value; bool is_marlin = print_config.gcode_flavor.value == gcfMarlinLegacy || print_config.gcode_flavor.value == gcfMarlinFirmware; m_max_acceleration = std::lrint(is_marlin ? print_config.machine_max_acceleration_extruding.values.front() : 0); + m_max_jerk = std::lrint(is_marlin ? std::min(print_config.machine_max_jerk_x.values.front(), print_config.machine_max_jerk_y.values.front()) : 0); } void GCodeWriter::set_extruders(std::vector extruder_ids) @@ -183,6 +184,26 @@ std::string GCodeWriter::set_acceleration(unsigned int acceleration) return gcode.str(); } +std::string GCodeWriter::set_jerk_xy(unsigned int jerk) +{ + // Clamp the jerk to the allowed maximum. + if (m_max_jerk > 0 && jerk > m_max_jerk) + jerk = m_max_jerk; + + if (jerk < 1 || jerk == m_last_jerk) + return std::string(); + + m_last_jerk = jerk; + + std::ostringstream gcode; + gcode << "M205 X" << jerk << " Y" << jerk; + if (GCodeWriter::full_gcode_comment) gcode << " ; adjust jerk"; + gcode << "\n"; + + return gcode.str(); + +} + std::string GCodeWriter::reset_e(bool force) { if (FLAVOR_IS(gcfMach3) diff --git a/src/libslic3r/GCodeWriter.hpp b/src/libslic3r/GCodeWriter.hpp index 23d3b5ec72..a845816096 100644 --- a/src/libslic3r/GCodeWriter.hpp +++ b/src/libslic3r/GCodeWriter.hpp @@ -26,6 +26,7 @@ public: multiple_extruders(false), m_extruder(nullptr), m_single_extruder_multi_material(false), m_last_acceleration(0), m_max_acceleration(0), + m_last_jerk(0), m_max_jerk(0), /*m_last_bed_temperature(0), */m_last_bed_temperature_reached(true), m_lifted(0), m_to_lift(0), @@ -51,6 +52,7 @@ public: // BBS std::string set_bed_temperature(std::vector temps_per_bed, int default_temp, bool wait = false); std::string set_acceleration(unsigned int acceleration); + std::string set_jerk_xy(unsigned int jerk); std::string reset_e(bool force = false); std::string update_progress(unsigned int num, unsigned int tot, bool allow_100 = false) const; // return false if this extruder was already selected @@ -104,6 +106,13 @@ private: // Limit for setting the acceleration, to respect the machine limits set for the Marlin firmware. // If set to zero, the limit is not in action. unsigned int m_max_acceleration; + unsigned int m_max_jerk; + unsigned int m_last_jerk; + + unsigned int m_travel_acceleration; + unsigned int m_travel_jerk; + + //BBS unsigned int m_last_additional_fan_speed; // BBS diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index d4e5377dcb..5ac4842fb0 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -658,7 +658,8 @@ static std::vector s_Preset_print_options { "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", "gap_infill_speed", "travel_speed", "travel_speed_z", "initial_layer_speed", - "outer_wall_acceleration", "inner_wall_acceleration", "initial_layer_acceleration", "top_surface_acceleration", "default_acceleration", "skirt_loops", "skirt_distance", "skirt_height", "draft_shield", + "outer_wall_acceleration", "inner_wall_acceleration", "initial_layer_acceleration", "top_surface_acceleration", "default_acceleration", "travel_acceleration", "skirt_loops", "skirt_distance", "skirt_height", "draft_shield", + "default_jerk", "outer_wall_jerk", "inner_wall_jerk", "top_surface_jerk", "initial_layer_jerk","travel_jerk", "brim_width", "brim_object_gap", "brim_type", "enable_support", "support_type", "support_threshold_angle", "enforce_support_layers", "raft_layers", "raft_first_layer_density", "raft_first_layer_expansion", "raft_contact_distance", "raft_expansion", "support_base_pattern", "support_base_pattern_spacing", "support_style", @@ -691,7 +692,7 @@ static std::vector s_Preset_print_options { static std::vector s_Preset_filament_options { /*"filament_colour", */"filament_diameter", "filament_type", "filament_soluble", "filament_is_support", "filament_max_volumetric_speed", - "filament_flow_ratio", "filament_density", "filament_cost", "filament_minimal_purge_on_wipe_tower", + "filament_flow_ratio", "enable_pressure_advance", "pressure_advance", "filament_density", "filament_cost", "filament_minimal_purge_on_wipe_tower", "chamber_temperature", "nozzle_temperature", "nozzle_temperature_initial_layer", // BBS "cool_plate_temp", "eng_plate_temp", "hot_plate_temp", "textured_plate_temp", "cool_plate_temp_initial_layer", "eng_plate_temp_initial_layer", "hot_plate_temp_initial_layer","textured_plate_temp_initial_layer", diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index 1d23d5808e..67360a4c2a 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -68,7 +68,9 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n //BBS: add bed_exclude_area "bed_exclude_area", "before_layer_change_gcode", - "enable_overhang_bridge_fan" + "enable_pressure_advance", + "pressure_advance", + "enable_overhang_bridge_fan", "overhang_fan_speed", "overhang_fan_threshold", "slow_down_for_layer_cooling", @@ -94,6 +96,7 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n "inner_wall_acceleration", "initial_layer_acceleration", "top_surface_acceleration", + "travel_acceleration", // BBS "cool_plate_temp_initial_layer", "eng_plate_temp_initial_layer", diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index c51bc55eb7..93f6e28730 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -1042,6 +1042,18 @@ void PrintConfigDef::init_fff_params() def->mode = comAdvanced; def->set_default_value(new ConfigOptionFloats { 1. }); + def = this->add("enable_pressure_advance", coBool); + def->label = L("Enable Pressure Advance"); + def->tooltip = L("Enable Pressure Advance"); + def->set_default_value(new ConfigOptionBool(false)); + + def = this->add("pressure_advance", coFloats); + def->label = L("Pressure advance"); + def->tooltip = L("Pressure Advnce(Klipper) AKA Linear Advance Factor(Marlin)"); + def->max = 2; + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionFloats { 0. }); + def = this->add("line_width", coFloat); def->label = L("Default"); def->category = L("Quality"); @@ -1266,6 +1278,14 @@ void PrintConfigDef::init_fff_params() def->mode = comAdvanced; def->set_default_value(new ConfigOptionFloat(7000)); + def = this->add("travel_acceleration", coFloat); + def->label = L("Travel"); + def->tooltip = L("Acceleration of travel moves"); + def->sidetext = L("mm/s²"); + def->min = 0; + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionFloat(15000)); + def = this->add("top_surface_acceleration", coFloat); def->label = L("Top surface"); def->tooltip = L("Acceleration of top surface infill. Using a lower value may improve top surface quality"); @@ -1282,6 +1302,54 @@ void PrintConfigDef::init_fff_params() def->mode = comAdvanced; def->set_default_value(new ConfigOptionFloat(300)); + def = this->add("default_jerk", coFloat); + def->label = L("default jerk"); + def->tooltip = L("Default jerk"); + def->sidetext = L("mm/s"); + def->min = 0; + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionFloat(0)); + + def = this->add("outer_wall_jerk", coFloat); + def->label = L("Outer wall"); + def->tooltip = L("Jerk of outer walls"); + def->sidetext = L("mm/s"); + def->min = 0; + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionFloat(9)); + + def = this->add("inner_wall_jerk", coFloat); + def->label = L("Inner wall"); + def->tooltip = L("Jerk of inner walls"); + def->sidetext = L("mm/s"); + def->min = 0; + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionFloat(9)); + + def = this->add("top_surface_jerk", coFloat); + def->label = L("Top surface"); + def->tooltip = L("Jerk for top surface"); + def->sidetext = L("mm/s"); + def->min = 1; + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionFloat(9)); + + def = this->add("initial_layer_jerk", coFloat); + def->label = L("Initial layer"); + def->tooltip = L("Jerk for initial layer"); + def->sidetext = L("mm/s"); + def->min = 1; + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionFloat(9)); + + def = this->add("travel_jerk", coFloat); + def->label = L("Travel"); + def->tooltip = L("Jerk for travel"); + def->sidetext = L("mm/s"); + def->min = 1; + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionFloat(9)); + def = this->add("initial_layer_line_width", coFloat); def->label = L("Initial layer"); def->category = L("Quality"); diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index bc96a644b2..c0b7622466 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -745,6 +745,8 @@ PRINT_CONFIG_CLASS_DEFINE( ((ConfigOptionString, machine_end_gcode)) ((ConfigOptionStrings, filament_end_gcode)) ((ConfigOptionFloats, filament_flow_ratio)) + ((ConfigOptionBool, enable_pressure_advance)) + ((ConfigOptionFloats, pressure_advance)) ((ConfigOptionFloats, filament_diameter)) ((ConfigOptionFloats, filament_density)) ((ConfigOptionStrings, filament_type)) @@ -830,9 +832,17 @@ PRINT_CONFIG_CLASS_DERIVED_DEFINE( ((ConfigOptionFloat, inner_wall_acceleration)) ((ConfigOptionFloat, top_surface_acceleration)) ((ConfigOptionFloat, initial_layer_acceleration)) + ((ConfigOptionFloat, travel_acceleration)) ((ConfigOptionFloat, initial_layer_line_width)) ((ConfigOptionFloat, initial_layer_print_height)) ((ConfigOptionFloat, initial_layer_speed)) + ((ConfigOptionFloat, default_jerk)) + ((ConfigOptionFloat, outer_wall_jerk)) + ((ConfigOptionFloat, inner_wall_jerk)) + ((ConfigOptionFloat, top_surface_jerk)) + ((ConfigOptionFloat, initial_layer_jerk)) + ((ConfigOptionFloat, travel_jerk)) + //BBS ((ConfigOptionFloat, initial_layer_infill_speed)) ((ConfigOptionInts, nozzle_temperature_initial_layer)) diff --git a/src/slic3r/GUI/ConfigManipulation.cpp b/src/slic3r/GUI/ConfigManipulation.cpp index b8e62eccc8..d35e16844a 100644 --- a/src/slic3r/GUI/ConfigManipulation.cpp +++ b/src/slic3r/GUI/ConfigManipulation.cpp @@ -483,9 +483,14 @@ void ConfigManipulation::toggle_print_fff_options(DynamicPrintConfig *config, co bool have_default_acceleration = config->opt_float("default_acceleration") > 0; //BBS - for (auto el : { "outer_wall_acceleration", "inner_wall_acceleration", "initial_layer_acceleration", "top_surface_acceleration" }) + for (auto el : { "outer_wall_acceleration", "inner_wall_acceleration", "initial_layer_acceleration", "top_surface_acceleration","travel_acceleration" }) toggle_field(el, have_default_acceleration); + bool have_default_jerk = config->opt_float("default_jerk") > 0; + + for (auto el : { "outer_wall_jerk", "inner_wall_jerk", "initial_layer_jerk", "top_surface_jerk","travel_jerk" }) + toggle_field(el, have_default_jerk); + bool have_skirt = config->opt_int("skirt_loops") > 0; toggle_field("skirt_height", have_skirt && config->opt_enum("draft_shield") != dsEnabled); for (auto el : { "skirt_distance", "draft_shield"}) diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 8140cac4ca..76ba1e0e9f 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -1841,11 +1841,20 @@ void TabPrint::build() optgroup->append_single_option_line("travel_speed"); optgroup = page->new_optgroup(L("Acceleration"), 15); + optgroup->append_single_option_line("default_acceleration"); optgroup->append_single_option_line("outer_wall_acceleration"); optgroup->append_single_option_line("inner_wall_acceleration"); optgroup->append_single_option_line("initial_layer_acceleration"); optgroup->append_single_option_line("top_surface_acceleration"); - optgroup->append_single_option_line("default_acceleration"); + optgroup->append_single_option_line("travel_acceleration"); + + optgroup = page->new_optgroup(L("Jerk"), 15); + optgroup->append_single_option_line("default_jerk"); + optgroup->append_single_option_line("outer_wall_jerk"); + optgroup->append_single_option_line("inner_wall_jerk"); + optgroup->append_single_option_line("top_surface_jerk"); + optgroup->append_single_option_line("initial_layer_jerk"); + optgroup->append_single_option_line("travel_jerk"); #ifdef HAS_PRESSURE_EQUALIZER optgroup->append_single_option_line("max_volumetric_extrusion_rate_slope_positive"); @@ -2442,6 +2451,10 @@ void TabFilament::build() //optgroup->append_single_option_line("filament_colour"); optgroup->append_single_option_line("filament_diameter"); optgroup->append_single_option_line("filament_flow_ratio"); + + optgroup->append_single_option_line("enable_pressure_advance"); + optgroup->append_single_option_line("pressure_advance"); + optgroup->append_single_option_line("filament_density"); optgroup->append_single_option_line("filament_cost"); //BBS @@ -2659,7 +2672,11 @@ void TabFilament::toggle_options() for (auto el : { "overhang_fan_speed", "overhang_fan_threshold" }) toggle_option(el, has_enable_overhang_bridge_fan); } - + if (m_active_page->title() == "Filament") + { + bool pa = m_config->opt_bool("enable_pressure_advance"); + toggle_option("pressure_advance", pa); + } if (m_active_page->title() == "Setting Overrides") update_filament_overrides_page(); }