2016-09-26 10:50:05 +00:00
|
|
|
use Test::More tests => 26;
|
2012-11-21 19:41:14 +00:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
BEGIN {
|
|
|
|
use FindBin;
|
|
|
|
use lib "$FindBin::Bin/../lib";
|
2017-08-18 07:58:50 +00:00
|
|
|
use local::lib "$FindBin::Bin/../local-lib";
|
2012-11-21 19:41:14 +00:00
|
|
|
}
|
|
|
|
|
2015-12-18 17:36:39 +00:00
|
|
|
use List::Util qw(any);
|
2012-11-21 19:41:14 +00:00
|
|
|
use Slic3r;
|
2012-12-21 12:25:03 +00:00
|
|
|
use Slic3r::Test qw(_eq);
|
2012-11-21 19:41:14 +00:00
|
|
|
|
2014-04-19 17:28:43 +00:00
|
|
|
{
|
2017-10-27 16:52:35 +00:00
|
|
|
my $config = Slic3r::Config::new_from_defaults;
|
2014-04-19 17:28:43 +00:00
|
|
|
my $duplicate = 1;
|
2012-12-04 23:39:40 +00:00
|
|
|
|
2014-04-19 17:28:43 +00:00
|
|
|
my $test = sub {
|
|
|
|
my ($conf) = @_;
|
|
|
|
$conf ||= $config;
|
2014-10-21 18:16:45 +00:00
|
|
|
|
2014-04-19 17:28:43 +00:00
|
|
|
my $print = Slic3r::Test::init_print('20mm_cube', config => $conf, duplicate => $duplicate);
|
2012-11-21 19:41:14 +00:00
|
|
|
|
2014-04-19 17:28:43 +00:00
|
|
|
my $tool = 0;
|
|
|
|
my @toolchange_count = (); # track first usages so that we don't expect retract_length_toolchange when extruders are used for the first time
|
|
|
|
my @retracted = (1); # ignore the first travel move from home to first point
|
|
|
|
my @retracted_length = (0);
|
|
|
|
my $lifted = 0;
|
2016-09-26 10:50:05 +00:00
|
|
|
my $lift_dist = 0; # track lifted distance for toolchanges and extruders with different retract_lift values
|
2014-04-19 17:28:43 +00:00
|
|
|
my $changed_tool = 0;
|
|
|
|
my $wait_for_toolchange = 0;
|
|
|
|
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
|
|
|
my ($self, $cmd, $args, $info) = @_;
|
2012-12-10 00:10:20 +00:00
|
|
|
|
2014-04-19 17:28:43 +00:00
|
|
|
if ($cmd =~ /^T(\d+)/) {
|
|
|
|
$tool = $1;
|
|
|
|
$changed_tool = 1;
|
|
|
|
$wait_for_toolchange = 0;
|
|
|
|
$toolchange_count[$tool] //= 0;
|
|
|
|
$toolchange_count[$tool]++;
|
|
|
|
} elsif ($cmd =~ /^G[01]$/ && !$args->{Z}) { # ignore lift taking place after retraction
|
|
|
|
fail 'toolchange happens right after retraction' if $wait_for_toolchange;
|
2012-12-05 00:27:21 +00:00
|
|
|
}
|
2014-04-19 17:28:43 +00:00
|
|
|
|
|
|
|
if ($info->{dist_Z}) {
|
|
|
|
# lift move or lift + change layer
|
2014-05-09 12:24:35 +00:00
|
|
|
if (_eq($info->{dist_Z}, $print->print->config->get_at('retract_lift', $tool))
|
|
|
|
|| (_eq($info->{dist_Z}, $conf->layer_height + $print->print->config->get_at('retract_lift', $tool)) && $print->print->config->get_at('retract_lift', $tool) > 0)) {
|
2014-10-21 19:41:11 +00:00
|
|
|
fail 'only lifting while retracted' if !$retracted[$tool];
|
2014-04-19 17:28:43 +00:00
|
|
|
fail 'double lift' if $lifted;
|
|
|
|
$lifted = 1;
|
2016-09-26 10:50:05 +00:00
|
|
|
$lift_dist = $info->{dist_Z};
|
2014-04-19 17:28:43 +00:00
|
|
|
}
|
|
|
|
if ($info->{dist_Z} < 0) {
|
|
|
|
fail 'going down only after lifting' if !$lifted;
|
|
|
|
fail 'going down by the same amount of the lift or by the amount needed to get to next layer'
|
2016-09-26 10:50:05 +00:00
|
|
|
if !_eq($info->{dist_Z}, -$lift_dist)
|
|
|
|
&& !_eq($info->{dist_Z}, -lift_dist + $conf->layer_height);
|
|
|
|
$lift_dist = 0;
|
2014-04-19 17:28:43 +00:00
|
|
|
$lifted = 0;
|
|
|
|
}
|
|
|
|
fail 'move Z at travel speed' if ($args->{F} // $self->F) != $conf->travel_speed * 60;
|
2012-12-05 00:27:21 +00:00
|
|
|
}
|
2014-04-19 17:28:43 +00:00
|
|
|
if ($info->{retracting}) {
|
|
|
|
$retracted[$tool] = 1;
|
|
|
|
$retracted_length[$tool] += -$info->{dist_E};
|
2014-05-09 12:24:35 +00:00
|
|
|
if (_eq($retracted_length[$tool], $print->print->config->get_at('retract_length', $tool))) {
|
2014-04-19 17:28:43 +00:00
|
|
|
# okay
|
2014-05-09 12:24:35 +00:00
|
|
|
} elsif (_eq($retracted_length[$tool], $print->print->config->get_at('retract_length_toolchange', $tool))) {
|
2014-04-19 17:28:43 +00:00
|
|
|
$wait_for_toolchange = 1;
|
|
|
|
} else {
|
|
|
|
fail 'retracted by the correct amount';
|
|
|
|
}
|
2012-12-21 14:14:44 +00:00
|
|
|
}
|
2014-04-19 17:28:43 +00:00
|
|
|
if ($info->{extruding}) {
|
|
|
|
fail 'only extruding while not lifted' if $lifted;
|
|
|
|
if ($retracted[$tool]) {
|
2014-05-09 12:24:35 +00:00
|
|
|
my $expected_amount = $retracted_length[$tool] + $print->print->config->get_at('retract_restart_extra', $tool);
|
2014-04-19 17:28:43 +00:00
|
|
|
if ($changed_tool && $toolchange_count[$tool] > 1) {
|
2014-05-09 12:24:35 +00:00
|
|
|
$expected_amount = $print->print->config->get_at('retract_length_toolchange', $tool) + $print->print->config->get_at('retract_restart_extra_toolchange', $tool);
|
2014-04-19 17:28:43 +00:00
|
|
|
$changed_tool = 0;
|
|
|
|
}
|
2014-10-21 18:16:45 +00:00
|
|
|
fail 'unretracted by the correct amount' && exit
|
2014-04-19 17:28:43 +00:00
|
|
|
if !_eq($info->{dist_E}, $expected_amount);
|
|
|
|
$retracted[$tool] = 0;
|
|
|
|
$retracted_length[$tool] = 0;
|
2012-12-10 00:10:20 +00:00
|
|
|
}
|
2012-12-04 23:39:40 +00:00
|
|
|
}
|
2014-05-09 12:24:35 +00:00
|
|
|
if ($info->{travel} && $info->{dist_XY} >= $print->print->config->get_at('retract_before_travel', $tool)) {
|
2014-04-19 17:28:43 +00:00
|
|
|
fail 'retracted before long travel move' if !$retracted[$tool];
|
|
|
|
}
|
|
|
|
});
|
2012-12-04 23:39:40 +00:00
|
|
|
|
2014-04-19 17:28:43 +00:00
|
|
|
1;
|
|
|
|
};
|
2012-12-04 23:39:40 +00:00
|
|
|
|
2018-03-28 08:16:04 +00:00
|
|
|
$config->set('nozzle_diameter', [0.6,0.6,0.6,0.6]);
|
2014-04-19 17:28:43 +00:00
|
|
|
$config->set('first_layer_height', $config->layer_height);
|
|
|
|
$config->set('first_layer_speed', '100%');
|
|
|
|
$config->set('start_gcode', ''); # to avoid dealing with the nozzle lift in start G-code
|
|
|
|
$config->set('retract_length', [1.5]);
|
|
|
|
$config->set('retract_before_travel', [3]);
|
|
|
|
$config->set('only_retract_when_crossing_perimeters', 0);
|
2012-11-21 19:41:14 +00:00
|
|
|
|
2014-04-19 17:28:43 +00:00
|
|
|
my $retract_tests = sub {
|
|
|
|
my ($descr) = @_;
|
2012-12-05 10:52:52 +00:00
|
|
|
|
2014-04-19 17:28:43 +00:00
|
|
|
ok $test->(), "retraction$descr";
|
2012-12-05 10:52:52 +00:00
|
|
|
|
2014-04-19 17:28:43 +00:00
|
|
|
my $conf = $config->clone;
|
|
|
|
$conf->set('retract_restart_extra', [1]);
|
|
|
|
ok $test->($conf), "restart extra length$descr";
|
2012-12-05 10:52:52 +00:00
|
|
|
|
2014-04-19 17:28:43 +00:00
|
|
|
$conf->set('retract_restart_extra', [-1]);
|
|
|
|
ok $test->($conf), "negative restart extra length$descr";
|
2012-12-21 14:25:08 +00:00
|
|
|
|
2016-09-26 10:50:05 +00:00
|
|
|
$conf->set('retract_lift', [1, 2]);
|
2014-04-19 17:28:43 +00:00
|
|
|
ok $test->($conf), "lift$descr";
|
|
|
|
};
|
|
|
|
|
|
|
|
$retract_tests->('');
|
2012-11-21 19:41:14 +00:00
|
|
|
|
2014-04-19 17:28:43 +00:00
|
|
|
$duplicate = 2;
|
|
|
|
$retract_tests->(' (duplicate)');
|
2012-12-10 00:10:20 +00:00
|
|
|
|
2014-04-19 17:28:43 +00:00
|
|
|
$duplicate = 1;
|
|
|
|
$config->set('infill_extruder', 2);
|
|
|
|
$config->set('skirts', 4);
|
|
|
|
$config->set('skirt_height', 3);
|
|
|
|
$retract_tests->(' (dual extruder with multiple skirt layers)');
|
|
|
|
}
|
2012-12-05 00:27:21 +00:00
|
|
|
|
2014-04-19 17:28:43 +00:00
|
|
|
{
|
2017-10-27 16:52:35 +00:00
|
|
|
my $config = Slic3r::Config::new_from_defaults;
|
2014-11-05 00:16:26 +00:00
|
|
|
$config->set('start_gcode', ''); # prevent any default priming Z move from affecting our lift detection
|
|
|
|
$config->set('retract_length', [0]);
|
2014-04-19 17:28:43 +00:00
|
|
|
$config->set('retract_layer_change', [0]);
|
2014-11-05 00:16:26 +00:00
|
|
|
$config->set('retract_lift', [0.2]);
|
2014-04-19 17:28:43 +00:00
|
|
|
|
|
|
|
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
|
|
|
my $retracted = 0;
|
|
|
|
my $layer_changes_with_retraction = 0;
|
2014-11-05 00:16:26 +00:00
|
|
|
my $retractions = my $z_restores = 0;
|
2014-04-19 17:28:43 +00:00
|
|
|
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
|
|
|
my ($self, $cmd, $args, $info) = @_;
|
|
|
|
|
|
|
|
if ($info->{retracting}) {
|
|
|
|
$retracted = 1;
|
2014-11-05 00:16:26 +00:00
|
|
|
$retractions++;
|
2014-04-19 17:28:43 +00:00
|
|
|
} elsif ($info->{extruding} && $retracted) {
|
|
|
|
$retracted = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($info->{dist_Z} && $retracted) {
|
|
|
|
$layer_changes_with_retraction++;
|
|
|
|
}
|
2014-11-05 00:16:26 +00:00
|
|
|
if ($info->{dist_Z} && $args->{Z} < $self->Z) {
|
|
|
|
$z_restores++;
|
|
|
|
}
|
2014-04-19 17:28:43 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
is $layer_changes_with_retraction, 0, 'no retraction on layer change';
|
2014-11-05 00:16:26 +00:00
|
|
|
is $retractions, 0, 'no retractions';
|
|
|
|
is $z_restores, 0, 'no lift';
|
2014-04-19 17:28:43 +00:00
|
|
|
}
|
2012-12-10 00:10:20 +00:00
|
|
|
|
2014-11-06 23:26:39 +00:00
|
|
|
{
|
2017-10-27 16:52:35 +00:00
|
|
|
my $config = Slic3r::Config::new_from_defaults;
|
2014-11-06 23:26:39 +00:00
|
|
|
$config->set('use_firmware_retraction', 1);
|
|
|
|
|
|
|
|
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
|
|
|
my $retracted = 0;
|
|
|
|
my $double_retractions = my $double_unretractions = 0;
|
|
|
|
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
|
|
|
my ($self, $cmd, $args, $info) = @_;
|
|
|
|
|
|
|
|
if ($cmd eq 'G10') {
|
|
|
|
$double_retractions++ if $retracted;
|
|
|
|
$retracted = 1;
|
|
|
|
} elsif ($cmd eq 'G11') {
|
|
|
|
$double_unretractions++ if !$retracted;
|
|
|
|
$retracted = 0;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
is $double_retractions, 0, 'no double retractions';
|
|
|
|
is $double_unretractions, 0, 'no double unretractions';
|
|
|
|
}
|
|
|
|
|
2014-11-23 18:28:18 +00:00
|
|
|
{
|
2017-10-27 16:52:35 +00:00
|
|
|
my $config = Slic3r::Config::new_from_defaults;
|
2014-11-23 18:28:18 +00:00
|
|
|
$config->set('use_firmware_retraction', 1);
|
|
|
|
$config->set('retract_length', [0]);
|
|
|
|
|
|
|
|
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
|
|
|
my $retracted = 0;
|
|
|
|
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
|
|
|
my ($self, $cmd, $args, $info) = @_;
|
|
|
|
|
|
|
|
if ($cmd eq 'G10') {
|
|
|
|
$retracted = 1;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ok $retracted, 'retracting also when --retract-length is 0 but --use-firmware-retraction is enabled';
|
|
|
|
}
|
|
|
|
|
2015-12-18 17:36:39 +00:00
|
|
|
{
|
2017-10-27 16:52:35 +00:00
|
|
|
my $config = Slic3r::Config::new_from_defaults;
|
2018-03-28 08:16:04 +00:00
|
|
|
$config->set('nozzle_diameter', [0.6,0.6,0.6,0.6]);
|
2015-12-18 17:36:39 +00:00
|
|
|
$config->set('start_gcode', '');
|
2016-09-26 10:50:05 +00:00
|
|
|
$config->set('retract_lift', [3, 4]);
|
2015-12-18 17:36:39 +00:00
|
|
|
|
|
|
|
my @lifted_at = ();
|
2015-12-19 11:44:22 +00:00
|
|
|
my $test = sub {
|
2015-12-19 14:00:56 +00:00
|
|
|
my $print = Slic3r::Test::init_print('20mm_cube', config => $config, duplicate => 2);
|
2015-12-19 11:44:22 +00:00
|
|
|
@lifted_at = ();
|
|
|
|
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
|
|
|
|
my ($self, $cmd, $args, $info) = @_;
|
2015-12-18 17:36:39 +00:00
|
|
|
|
2015-12-19 11:44:22 +00:00
|
|
|
if ($cmd eq 'G1' && $info->{dist_Z} < 0) {
|
|
|
|
push @lifted_at, $info->{new_Z};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-09-26 10:50:05 +00:00
|
|
|
$config->set('retract_lift_above', [0, 0]);
|
|
|
|
$config->set('retract_lift_below', [0, 0]);
|
2015-12-19 11:44:22 +00:00
|
|
|
$test->();
|
|
|
|
ok !!@lifted_at, 'lift takes place when above/below == 0';
|
2015-12-18 17:36:39 +00:00
|
|
|
|
2016-09-26 10:50:05 +00:00
|
|
|
$config->set('retract_lift_above', [5, 6]);
|
|
|
|
$config->set('retract_lift_below', [15, 13]);
|
2015-12-19 11:44:22 +00:00
|
|
|
$test->();
|
|
|
|
ok !!@lifted_at, 'lift takes place when above/below != 0';
|
2015-12-18 17:36:39 +00:00
|
|
|
ok !(any { $_ < $config->get_at('retract_lift_above', 0) } @lifted_at),
|
|
|
|
'Z is not lifted below the configured value';
|
|
|
|
ok !(any { $_ > $config->get_at('retract_lift_below', 0) } @lifted_at),
|
|
|
|
'Z is not lifted above the configured value';
|
2016-09-26 10:50:05 +00:00
|
|
|
|
|
|
|
# check lifting with different values for 2. extruder
|
|
|
|
$config->set('perimeter_extruder', 2);
|
|
|
|
$config->set('infill_extruder', 2);
|
|
|
|
$config->set('retract_lift_above', [0, 0]);
|
|
|
|
$config->set('retract_lift_below', [0, 0]);
|
|
|
|
$test->();
|
|
|
|
ok !!@lifted_at, 'lift takes place when above/below == 0 for 2. extruder';
|
|
|
|
|
|
|
|
$config->set('retract_lift_above', [5, 6]);
|
|
|
|
$config->set('retract_lift_below', [15, 13]);
|
|
|
|
$test->();
|
|
|
|
ok !!@lifted_at, 'lift takes place when above/below != 0 for 2. extruder';
|
|
|
|
ok !(any { $_ < $config->get_at('retract_lift_above', 1) } @lifted_at),
|
|
|
|
'Z is not lifted below the configured value for 2. extruder';
|
|
|
|
ok !(any { $_ > $config->get_at('retract_lift_below', 1) } @lifted_at),
|
|
|
|
'Z is not lifted above the configured value for 2. extruder';
|
2015-12-18 17:36:39 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 08:16:04 +00:00
|
|
|
__END__
|