Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimisation: ERS - Reduce redundant gcode commands from extrusion rate smoothing #7398

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/libslic3r/GCode/PressureEqualizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,25 @@ void PressureEqualizer::output_gcode_line(const size_t line_idx)
if (*comment != ';')
comment = nullptr;

// Emit the line with lowered extrusion rates.
// get the gcode line length
float l = line.dist_xyz();
if (auto nSegments = size_t(ceil(l / m_max_segment_length)); nSegments == 1) { // Just update this segment.
// number of segments this line can be broken down to
auto nSegments = size_t(ceil(l / m_max_segment_length));

// Orca:
// Calculate the absolute difference in volumetric extrusion rate between the start and end point of the line.
// Quantize it to 1mm3/min (0.016mm3/sec).
int delta_volumetric_rate = std::round(fabs(line.volumetric_extrusion_rate_end - line.volumetric_extrusion_rate_start));

// Emit the line with lowered extrusion rates.
// Orca:
// First, check if the change in volumetric extrusion rate is trivial (less than 10mm3/min -> 0.16mm3/sec (5mm/sec speed for a 0.25 mm nozzle).
// Or if the line size is equal in length with the smallest segment.
// If so, then emit the line as a single extrusion, i.e. dont split into segments.
if ( nSegments == 1 || delta_volumetric_rate < 10) {
push_line_to_output(line_idx, line.feedrate() * line.volumetric_correction_avg(), comment);
} else {
} else // The line needs to be split the line into segments and apply extrusion rate smoothing
{
bool accelerating = line.volumetric_extrusion_rate_start < line.volumetric_extrusion_rate_end;
// Update the initial and final feed rate values.
line.pos_start[4] = line.volumetric_extrusion_rate_start * line.pos_end[4] / line.volumetric_extrusion_rate;
Expand Down Expand Up @@ -769,7 +783,8 @@ void PressureEqualizer::push_line_to_output(const size_t line_idx, float new_fee
// Orca: sanity check, 1 mm/s is the minimum feedrate.
if (new_feedrate < 60)
new_feedrate = 60;
new_feedrate = std::round(new_feedrate);
// Quantize speed changes to a minimum of 1mm/sec, to reduce gcode volume for trivial speed changes.
new_feedrate = std::round(new_feedrate / 60.0) * 60.0;
const GCodeLine &line = m_gcode_lines[line_idx];
if (line_idx > 0 && output_buffer_length > 0) {
const std::string prev_line_str = std::string(output_buffer.begin() + int(this->output_buffer_prev_length),
Expand Down