2013-05-31 10:18:33 +00:00
|
|
|
use Test::More;
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
2018-04-25 20:06:44 +00:00
|
|
|
plan tests => 14;
|
2013-05-31 10:18:33 +00:00
|
|
|
|
|
|
|
BEGIN {
|
|
|
|
use FindBin;
|
|
|
|
use lib "$FindBin::Bin/../lib";
|
2017-08-18 07:58:50 +00:00
|
|
|
use local::lib "$FindBin::Bin/../local-lib";
|
2013-05-31 10:18:33 +00:00
|
|
|
}
|
|
|
|
|
2017-06-22 10:59:23 +00:00
|
|
|
use List::Util qw(none all);
|
2013-05-31 10:18:33 +00:00
|
|
|
use Slic3r;
|
2013-12-23 00:19:02 +00:00
|
|
|
use Slic3r::Test;
|
2013-05-31 10:18:33 +00:00
|
|
|
|
2016-12-21 22:09:58 +00:00
|
|
|
my $gcodegen;
|
2013-05-31 10:18:33 +00:00
|
|
|
sub buffer {
|
2017-06-30 15:05:58 +00:00
|
|
|
my $config = shift;
|
|
|
|
if (defined($config)) {
|
|
|
|
$config = $config->clone();
|
|
|
|
} else {
|
|
|
|
$config = Slic3r::Config->new;
|
|
|
|
}
|
|
|
|
my $config_override = shift;
|
|
|
|
foreach my $key (keys %{$config_override}) {
|
|
|
|
$config->set($key, ${$config_override}{$key});
|
|
|
|
}
|
|
|
|
|
2014-01-02 16:24:23 +00:00
|
|
|
my $print_config = Slic3r::Config::Print->new;
|
|
|
|
$print_config->apply_dynamic($config);
|
|
|
|
|
2016-12-21 22:09:58 +00:00
|
|
|
$gcodegen = Slic3r::GCode->new;
|
2015-07-01 19:47:17 +00:00
|
|
|
$gcodegen->apply_print_config($print_config);
|
|
|
|
$gcodegen->set_layer_count(10);
|
2017-06-30 17:07:14 +00:00
|
|
|
$gcodegen->set_extruders([ 0 ]);
|
2016-12-21 22:09:58 +00:00
|
|
|
return Slic3r::GCode::CoolingBuffer->new($gcodegen);
|
2013-05-31 10:18:33 +00:00
|
|
|
}
|
|
|
|
|
2017-06-30 15:05:58 +00:00
|
|
|
my $gcode1 = "G1 X100 E1 F3000\n";
|
|
|
|
my $print_time1 = 100 / (3000 / 60); # 2 sec
|
|
|
|
my $gcode2 = $gcode1 . "G1 X0 E1 F3000\n";
|
|
|
|
my $print_time2 = 2 * $print_time1; # 4 sec
|
|
|
|
|
2017-10-27 16:52:35 +00:00
|
|
|
my $config = Slic3r::Config::new_from_defaults;
|
2017-06-30 15:05:58 +00:00
|
|
|
# Default cooling settings.
|
|
|
|
$config->set('bridge_fan_speed', [ 100 ]);
|
|
|
|
$config->set('cooling', [ 1 ]);
|
|
|
|
$config->set('fan_always_on', [ 0 ]);
|
|
|
|
$config->set('fan_below_layer_time', [ 60 ]);
|
|
|
|
$config->set('max_fan_speed', [ 100 ]);
|
|
|
|
$config->set('min_print_speed', [ 10 ]);
|
|
|
|
$config->set('slowdown_below_layer_time', [ 5 ]);
|
|
|
|
# Default print speeds.
|
|
|
|
$config->set('bridge_speed', 60);
|
|
|
|
$config->set('external_perimeter_speed', '50%');
|
|
|
|
$config->set('first_layer_speed', 30);
|
|
|
|
$config->set('gap_fill_speed', 20);
|
|
|
|
$config->set('infill_speed', 80);
|
|
|
|
$config->set('perimeter_speed', 60);
|
|
|
|
$config->set('small_perimeter_speed', 15);
|
|
|
|
$config->set('solid_infill_speed', 20);
|
|
|
|
$config->set('top_solid_infill_speed', 15);
|
|
|
|
$config->set('max_print_speed', 80);
|
|
|
|
# Override for tests.
|
|
|
|
$config->set('disable_fan_first_layers', [ 0 ]);
|
2013-05-31 10:18:33 +00:00
|
|
|
|
|
|
|
{
|
2017-06-30 15:05:58 +00:00
|
|
|
my $gcode_src = "G1 F3000;_EXTRUDE_SET_SPEED\nG1 X100 E1";
|
|
|
|
# Print time of $gcode.
|
|
|
|
my $print_time = 100 / (3000 / 60);
|
|
|
|
my $buffer = buffer($config, { 'slowdown_below_layer_time' => [ $print_time * 0.999 ] });
|
|
|
|
my $gcode = $buffer->process_layer($gcode_src, 0);
|
2013-05-31 10:18:33 +00:00
|
|
|
like $gcode, qr/F3000/, 'speed is not altered when elapsed time is greater than slowdown threshold';
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2017-06-30 15:05:58 +00:00
|
|
|
my $gcode_src =
|
2016-04-10 08:24:27 +00:00
|
|
|
"G1 X50 F2500\n" .
|
|
|
|
"G1 F3000;_EXTRUDE_SET_SPEED\n" .
|
|
|
|
"G1 X100 E1\n" .
|
|
|
|
"G1 E4 F400",
|
2017-06-30 15:05:58 +00:00
|
|
|
# Print time of $gcode.
|
|
|
|
my $print_time = 50 / (2500 / 60) + 100 / (3000 / 60) + 4 / (400 / 60);
|
|
|
|
my $buffer = buffer($config, { 'slowdown_below_layer_time' => [ $print_time * 1.001 ] });
|
|
|
|
my $gcode = $buffer->process_layer($gcode_src, 0);
|
2013-05-31 10:18:33 +00:00
|
|
|
unlike $gcode, qr/F3000/, 'speed is altered when elapsed time is lower than slowdown threshold';
|
|
|
|
like $gcode, qr/F2500/, 'speed is not altered for travel moves';
|
|
|
|
like $gcode, qr/F400/, 'speed is not altered for extruder-only moves';
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2017-06-30 15:05:58 +00:00
|
|
|
my $buffer = buffer($config, {
|
|
|
|
'fan_below_layer_time' => [ $print_time1 * 0.88 ],
|
|
|
|
'slowdown_below_layer_time' => [ $print_time1 * 0.99 ]
|
|
|
|
});
|
|
|
|
my $gcode = $buffer->process_layer($gcode1, 0);
|
2013-05-31 10:18:33 +00:00
|
|
|
unlike $gcode, qr/M106/, 'fan is not activated when elapsed time is greater than fan threshold';
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2017-06-30 15:05:58 +00:00
|
|
|
my $gcode .= buffer($config, { 'slowdown_below_layer_time', [ $print_time2 * 0.99 ] })->process_layer($gcode2, 0);
|
2017-06-23 08:13:09 +00:00
|
|
|
like $gcode, qr/F3000/, 'slowdown is computed on all objects printing at the same Z';
|
2013-05-31 10:18:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2017-06-30 15:05:58 +00:00
|
|
|
# use an elapsed time which is < the threshold but greater than it when summed twice
|
|
|
|
my $buffer = buffer($config, {
|
|
|
|
'fan_below_layer_time' => [ $print_time2 * 0.65],
|
|
|
|
'slowdown_below_layer_time' => [ $print_time2 * 0.7 ]
|
|
|
|
});
|
|
|
|
my $gcode = $buffer->process_layer($gcode2, 0) .
|
|
|
|
$buffer->process_layer($gcode2, 1);
|
|
|
|
unlike $gcode, qr/M106/, 'fan is not activated on all objects printing at different Z';
|
2013-05-31 10:18:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2017-06-30 15:05:58 +00:00
|
|
|
# use an elapsed time which is < the threshold even when summed twice
|
|
|
|
my $buffer = buffer($config, {
|
|
|
|
'fan_below_layer_time' => [ $print_time2 + 1 ],
|
|
|
|
'slowdown_below_layer_time' => [ $print_time2 + 2 ]
|
|
|
|
});
|
|
|
|
my $gcode = $buffer->process_layer($gcode2, 0) .
|
|
|
|
$buffer->process_layer($gcode2, 1);
|
|
|
|
like $gcode, qr/M106/, 'fan is activated on all objects printing at different Z';
|
2013-05-31 10:18:33 +00:00
|
|
|
}
|
|
|
|
|
2017-06-30 17:07:14 +00:00
|
|
|
{
|
|
|
|
my $buffer = buffer($config, {
|
|
|
|
'cooling' => [ 1 , 0 ],
|
|
|
|
'fan_below_layer_time' => [ $print_time2 + 1, $print_time2 + 1 ],
|
|
|
|
'slowdown_below_layer_time' => [ $print_time2 + 2, $print_time2 + 2 ]
|
|
|
|
});
|
|
|
|
$buffer->gcodegen->set_extruders([ 0, 1 ]);
|
|
|
|
my $gcode = $buffer->process_layer($gcode1 . "T1\nG1 X0 E1 F3000\n", 0);
|
|
|
|
like $gcode, qr/^M106/, 'fan is activated for the 1st tool';
|
|
|
|
like $gcode, qr/.*M107/, 'fan is disabled for the 2nd tool';
|
|
|
|
}
|
|
|
|
|
2013-12-23 00:19:02 +00:00
|
|
|
{
|
2017-10-27 16:52:35 +00:00
|
|
|
my $config = Slic3r::Config::new_from_defaults;
|
2017-06-21 14:15:39 +00:00
|
|
|
$config->set('cooling', [ 1 ]);
|
|
|
|
$config->set('bridge_fan_speed', [ 100 ]);
|
|
|
|
$config->set('fan_below_layer_time', [ 0 ]);
|
|
|
|
$config->set('slowdown_below_layer_time', [ 0 ]);
|
2013-12-23 00:19:02 +00:00
|
|
|
$config->set('bridge_speed', 99);
|
|
|
|
$config->set('top_solid_layers', 1); # internal bridges use solid_infil speed
|
|
|
|
$config->set('bottom_solid_layers', 1); # internal bridges use solid_infil speed
|
|
|
|
|
|
|
|
my $print = Slic3r::Test::init_print('overhang', config => $config);
|
|
|
|
my $fan = 0;
|
|
|
|
my $fan_with_incorrect_speeds = my $fan_with_incorrect_print_speeds = 0;
|
|
|
|
my $bridge_with_no_fan = 0;
|
|
|
|
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
|
|
|
my ($self, $cmd, $args, $info) = @_;
|
|
|
|
|
|
|
|
if ($cmd eq 'M106') {
|
|
|
|
$fan = $args->{S};
|
|
|
|
$fan_with_incorrect_speeds++ if $fan != 255;
|
|
|
|
} elsif ($cmd eq 'M107') {
|
|
|
|
$fan = 0;
|
|
|
|
} elsif ($info->{extruding} && $info->{dist_XY} > 0) {
|
|
|
|
$fan_with_incorrect_print_speeds++
|
|
|
|
if ($fan > 0) && ($args->{F} // $self->F) != 60*$config->bridge_speed;
|
|
|
|
$bridge_with_no_fan++
|
|
|
|
if !$fan && ($args->{F} // $self->F) == 60*$config->bridge_speed;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
ok !$fan_with_incorrect_speeds, 'bridge fan speed is applied correctly';
|
|
|
|
ok !$fan_with_incorrect_print_speeds, 'bridge fan is only turned on for bridges';
|
|
|
|
ok !$bridge_with_no_fan, 'bridge fan is turned on for all bridges';
|
|
|
|
}
|
|
|
|
|
2016-12-21 22:09:58 +00:00
|
|
|
{
|
2017-10-27 16:52:35 +00:00
|
|
|
my $config = Slic3r::Config::new_from_defaults;
|
2017-06-21 14:15:39 +00:00
|
|
|
$config->set('cooling', [ 1 ]);
|
|
|
|
$config->set('fan_below_layer_time', [ 0 ]);
|
|
|
|
$config->set('slowdown_below_layer_time', [ 10 ]);
|
|
|
|
$config->set('min_print_speed', [ 0 ]);
|
2016-12-21 22:09:58 +00:00
|
|
|
$config->set('start_gcode', '');
|
2017-06-22 10:59:23 +00:00
|
|
|
$config->set('first_layer_speed', '100%');
|
|
|
|
$config->set('external_perimeter_speed', 99);
|
2016-12-21 22:09:58 +00:00
|
|
|
|
|
|
|
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
|
|
|
my @layer_times = (0); # in seconds
|
2017-06-22 10:59:23 +00:00
|
|
|
my %layer_external = (); # z => 1
|
2016-12-21 22:09:58 +00:00
|
|
|
Slic3r::GCode::Reader->new->parse(my $gcode = Slic3r::Test::gcode($print), sub {
|
|
|
|
my ($self, $cmd, $args, $info) = @_;
|
|
|
|
|
|
|
|
if ($cmd eq 'G1') {
|
|
|
|
if ($info->{dist_Z}) {
|
|
|
|
push @layer_times, 0;
|
2017-06-22 10:59:23 +00:00
|
|
|
$layer_external{ $args->{Z} } = 0;
|
2016-12-21 22:09:58 +00:00
|
|
|
}
|
|
|
|
$layer_times[-1] += abs($info->{dist_XY} || $info->{dist_E} || $info->{dist_Z} || 0) / ($args->{F} // $self->F) * 60;
|
2017-06-22 10:59:23 +00:00
|
|
|
if ($args->{F} && $args->{F} == $config->external_perimeter_speed*60) {
|
|
|
|
$layer_external{ $self->Z }++;
|
|
|
|
}
|
2016-12-21 22:09:58 +00:00
|
|
|
}
|
|
|
|
});
|
2017-06-22 10:59:23 +00:00
|
|
|
@layer_times = grep $_, @layer_times;
|
|
|
|
my $all_below = none { $_ < $config->slowdown_below_layer_time->[0] } @layer_times;
|
2016-12-21 22:09:58 +00:00
|
|
|
ok $all_below, 'slowdown_below_layer_time is honored';
|
2017-06-22 10:59:23 +00:00
|
|
|
|
|
|
|
# check that all layers have at least one unaltered external perimeter speed
|
2018-04-25 20:06:44 +00:00
|
|
|
# my $external = all { $_ > 0 } values %layer_external;
|
|
|
|
# ok $external, 'slowdown_below_layer_time does not alter external perimeters';
|
2016-12-21 22:09:58 +00:00
|
|
|
}
|
|
|
|
|
2013-05-31 10:18:33 +00:00
|
|
|
__END__
|