From dcdb5056fe33d408471a209aca77196ce114b13a Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Tue, 22 Nov 2016 22:26:08 +0100 Subject: [PATCH] Fixed regression causing slowdown_below_layer_time to be ignored. #3515 #3443 --- lib/Slic3r/GCode/CoolingBuffer.pm | 2 +- t/cooling.t | 27 ++++++++++++++++++++++++++- xs/src/libslic3r/GCode.cpp | 7 ++++++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/lib/Slic3r/GCode/CoolingBuffer.pm b/lib/Slic3r/GCode/CoolingBuffer.pm index 19fb8d7a8..bb1292b39 100644 --- a/lib/Slic3r/GCode/CoolingBuffer.pm +++ b/lib/Slic3r/GCode/CoolingBuffer.pm @@ -53,7 +53,7 @@ sub flush { * ($elapsed - $self->config->slowdown_below_layer_time) / ($self->config->fan_below_layer_time - $self->config->slowdown_below_layer_time); #/ } - Slic3r::debugf " fan = %d%%, speed = %d%%\n", $fan_speed, $speed_factor * 100; + Slic3r::debugf " fan = %d%%, speed = %f%%\n", $fan_speed, $speed_factor * 100; if ($speed_factor < 1) { $gcode =~ s/^(?=.*?;_EXTRUDE_SET_SPEED)(?!.*?;_WIPE)(? 11; +plan tests => 12; BEGIN { use FindBin; use lib "$FindBin::Bin/../lib"; } +use List::Util qw(first); use Slic3r; use Slic3r::Test; @@ -135,4 +136,28 @@ $config->set('disable_fan_first_layers', 0); ok !$bridge_with_no_fan, 'bridge fan is turned on for all bridges'; } +{ + my $config = Slic3r::Config->new_from_defaults; + $config->set('cooling', 1); + $config->set('fan_below_layer_time', 0); + $config->set('slowdown_below_layer_time', 10); + $config->set('min_print_speed', 0); + $config->set('start_gcode', ''); + + my $print = Slic3r::Test::init_print('20mm_cube', config => $config); + my @layer_times = (0); # in seconds + Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub { + my ($self, $cmd, $args, $info) = @_; + + if ($cmd eq 'G1') { + if ($info->{dist_Z}) { + push @layer_times, 0; + } + $layer_times[-1] += abs($info->{dist_XY} || $info->{dist_E} || $info->{dist_Z} || 0) / ($args->{F} // $self->F) * 60; + } + }); + my $all_below = !defined first { $_ > 0 && $_ < $config->slowdown_below_layer_time } @layer_times; + ok $all_below, 'slowdown_below_layer_time is honored'; +} + __END__ diff --git a/xs/src/libslic3r/GCode.cpp b/xs/src/libslic3r/GCode.cpp index 220384632..9a71b2a64 100644 --- a/xs/src/libslic3r/GCode.cpp +++ b/xs/src/libslic3r/GCode.cpp @@ -632,8 +632,13 @@ GCode::travel_to(const Point &point, ExtrusionRole role, std::string comment) for (Lines::const_iterator line = lines.begin(); line != lines.end(); ++line) gcode += this->writer.travel_to_xy(this->point_to_gcode(line->b), comment); + /* While this makes the estimate more accurate, CoolingBuffer calculates the slowdown + factor on the whole elapsed time but only alters non-travel moves, thus the resulting + time is still shorter than the configured threshold. We could create a new + elapsed_travel_time but we would still need to account for bridges, retractions, wipe etc. if (this->config.cooling) - this->elapsed_time += travel.length() / this->config.get_abs_value("travel_speed"); + this->elapsed_time += unscale(travel.length()) / this->config.get_abs_value("travel_speed"); + */ return gcode; }