From c70e8d486fc5ed72eafc43d5d39e9ad6c419b3f9 Mon Sep 17 00:00:00 2001 From: "salt.wei" Date: Tue, 1 Nov 2022 09:46:01 +0800 Subject: [PATCH] ENH: update jerk strategy according to printer Jerk handling has been changed in printer. Changed in slicer as well. Signed-off-by: salt.wei Change-Id: Ic3aef43a534a7f0b85b734e747dc3ca883faaa46 --- resources/profiles/BBL.json | 2 +- .../BBL/machine/fdm_bbl_3dp_001_common.json | 4 +- .../BBL/machine/fdm_machine_common.json | 2 +- src/libslic3r/GCode/GCodeProcessor.cpp | 78 ++++++++++++------- src/libslic3r/GCode/GCodeProcessor.hpp | 1 + 5 files changed, 56 insertions(+), 31 deletions(-) diff --git a/resources/profiles/BBL.json b/resources/profiles/BBL.json index 237bc1713..b627b4cbb 100644 --- a/resources/profiles/BBL.json +++ b/resources/profiles/BBL.json @@ -1,7 +1,7 @@ { "name": "Bambulab", "url": "http://www.bambulab.com/Parameters/vendor/BBL.json", - "version": "01.03.00.13", + "version": "01.04.00.01", "force_update": "0", "description": "the initial version of BBL configurations", "machine_model_list": [ diff --git a/resources/profiles/BBL/machine/fdm_bbl_3dp_001_common.json b/resources/profiles/BBL/machine/fdm_bbl_3dp_001_common.json index 4bc184053..b7df6c28a 100644 --- a/resources/profiles/BBL/machine/fdm_bbl_3dp_001_common.json +++ b/resources/profiles/BBL/machine/fdm_bbl_3dp_001_common.json @@ -93,8 +93,8 @@ "9" ], "machine_max_jerk_z": [ - "0.2", - "0.4" + "3", + "3" ], "machine_min_extruding_rate": [ "0", diff --git a/resources/profiles/BBL/machine/fdm_machine_common.json b/resources/profiles/BBL/machine/fdm_machine_common.json index 37891fb1a..31c0f357d 100644 --- a/resources/profiles/BBL/machine/fdm_machine_common.json +++ b/resources/profiles/BBL/machine/fdm_machine_common.json @@ -55,7 +55,7 @@ "8" ], "machine_max_jerk_z": [ - "0.4" + "3" ], "machine_min_extruding_rate": [ "0" diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index 783220a09..b2facc583 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -2740,23 +2740,30 @@ void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line) float v_factor = 1.0f; bool limited = false; - //BBS: currently jerk in x,y,z axis are combined to one value and be limited together in MC side - //So we only need to handle Z axis for (unsigned char a = X; a <= E; ++a) { // Limit an axis. We have to differentiate coasting from the reversal of an axis movement, or a full stop. - //BBS - float jerk = 0; if (a == X) { Vec3f exit_v = prev.feedrate * (prev.exit_direction); - exit_v(2, 0) = 0; if (prev_speed_larger) exit_v *= smaller_speed_factor; Vec3f entry_v = block.feedrate_profile.cruise * (curr.enter_direction); Vec3f jerk_v = entry_v - exit_v; - jerk = jerk_v.norm(); - } else if (a == Y || a == Z) { + jerk_v = Vec3f(abs(jerk_v.x()), abs(jerk_v.y()), abs(jerk_v.z())); + Vec3f max_xyz_jerk_v = get_xyz_max_jerk(static_cast(i)); + + for (size_t i = 0; i < 3; i++) + { + if (jerk_v[i] > max_xyz_jerk_v[i]) { + v_factor *= max_xyz_jerk_v[i] / jerk_v[i]; + jerk_v *= v_factor; + limited = true; + } + } + } + else if (a == Y || a == Z) { continue; - } else { + } + else { float v_exit = prev.axis_feedrate[a]; float v_entry = curr.axis_feedrate[a]; @@ -2769,7 +2776,7 @@ void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line) } // Calculate the jerk depending on whether the axis is coasting in the same direction or reversing a direction. - jerk = + float jerk = (v_exit > v_entry) ? (((v_entry > 0.0f) || (v_exit < 0.0f)) ? // coasting @@ -2782,12 +2789,13 @@ void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line) (v_entry - v_exit) : // axis reversal std::max(-v_exit, v_entry)); - } - float axis_max_jerk = get_axis_max_jerk(static_cast(i), static_cast(a)); - if (jerk > axis_max_jerk) { - v_factor *= axis_max_jerk / jerk; - limited = true; + + float axis_max_jerk = get_axis_max_jerk(static_cast(i), static_cast(a)); + if (jerk > axis_max_jerk) { + v_factor *= axis_max_jerk / jerk; + limited = true; + } } } @@ -3135,22 +3143,30 @@ void GCodeProcessor::process_G2_G3(const GCodeReader::GCodeLine& line) float v_factor = 1.0f; bool limited = false; - //BBS: currently jerk in x,y,z axis are combined to one value and be limited together in MC side - //So we only need to handle Z axis for (unsigned char a = X; a <= E; ++a) { //BBS: Limit an axis. We have to differentiate coasting from the reversal of an axis movement, or a full stop. - float jerk = 0; if (a == X) { Vec3f exit_v = prev.feedrate * (prev.exit_direction); - exit_v(2, 0) = 0; if (prev_speed_larger) exit_v *= smaller_speed_factor; Vec3f entry_v = block.feedrate_profile.cruise * (curr.enter_direction); Vec3f jerk_v = entry_v - exit_v; - jerk = jerk_v.norm(); - } else if (a == Y || a == Z) { + jerk_v = Vec3f(abs(jerk_v.x()), abs(jerk_v.y()), abs(jerk_v.z())); + Vec3f max_xyz_jerk_v = get_xyz_max_jerk(static_cast(i)); + + for (size_t i = 0; i < 3; i++) + { + if (jerk_v[i] > max_xyz_jerk_v[i]) { + v_factor *= max_xyz_jerk_v[i] / jerk_v[i]; + jerk_v *= v_factor; + limited = true; + } + } + } + else if (a == Y || a == Z) { continue; - } else { + } + else { float v_exit = prev.axis_feedrate[a]; float v_entry = curr.axis_feedrate[a]; @@ -3163,7 +3179,7 @@ void GCodeProcessor::process_G2_G3(const GCodeReader::GCodeLine& line) } //BBS: Calculate the jerk depending on whether the axis is coasting in the same direction or reversing a direction. - jerk = + float jerk = (v_exit > v_entry) ? (((v_entry > 0.0f) || (v_exit < 0.0f)) ? //BBS: coasting @@ -3175,12 +3191,13 @@ void GCodeProcessor::process_G2_G3(const GCodeReader::GCodeLine& line) (v_entry - v_exit) : //BBS: axis reversal std::max(-v_exit, v_entry)); - } - float axis_max_jerk = get_axis_max_jerk(static_cast(i), static_cast(a)); - if (jerk > axis_max_jerk) { - v_factor *= axis_max_jerk / jerk; - limited = true; + + float axis_max_jerk = get_axis_max_jerk(static_cast(i), static_cast(a)); + if (jerk > axis_max_jerk) { + v_factor *= axis_max_jerk / jerk; + limited = true; + } } } @@ -3857,6 +3874,13 @@ float GCodeProcessor::get_axis_max_jerk(PrintEstimatedStatistics::ETimeMode mode } } +Vec3f GCodeProcessor::get_xyz_max_jerk(PrintEstimatedStatistics::ETimeMode mode) const +{ + return Vec3f(get_option_value(m_time_processor.machine_limits.machine_max_jerk_x, static_cast(mode)), + get_option_value(m_time_processor.machine_limits.machine_max_jerk_y, static_cast(mode)), + get_option_value(m_time_processor.machine_limits.machine_max_jerk_z, static_cast(mode))); +} + float GCodeProcessor::get_retract_acceleration(PrintEstimatedStatistics::ETimeMode mode) const { size_t id = static_cast(mode); diff --git a/src/libslic3r/GCode/GCodeProcessor.hpp b/src/libslic3r/GCode/GCodeProcessor.hpp index 755f4d14e..f708b0d54 100644 --- a/src/libslic3r/GCode/GCodeProcessor.hpp +++ b/src/libslic3r/GCode/GCodeProcessor.hpp @@ -827,6 +827,7 @@ namespace Slic3r { float get_axis_max_feedrate(PrintEstimatedStatistics::ETimeMode mode, Axis axis) const; float get_axis_max_acceleration(PrintEstimatedStatistics::ETimeMode mode, Axis axis) const; float get_axis_max_jerk(PrintEstimatedStatistics::ETimeMode mode, Axis axis) const; + Vec3f get_xyz_max_jerk(PrintEstimatedStatistics::ETimeMode mode) const; float get_retract_acceleration(PrintEstimatedStatistics::ETimeMode mode) const; void set_retract_acceleration(PrintEstimatedStatistics::ETimeMode mode, float value); float get_acceleration(PrintEstimatedStatistics::ETimeMode mode) const;