PrusaSlicer-NonPlainar/t/retraction.t

132 lines
5.0 KiB
Perl
Raw Normal View History

use Test::More tests => 16;
2012-11-21 19:41:14 +00:00
use strict;
use warnings;
BEGIN {
use FindBin;
use lib "$FindBin::Bin/../lib";
}
use Slic3r;
2012-12-21 12:25:03 +00:00
use Slic3r::Test qw(_eq);
2012-11-21 19:41:14 +00:00
2012-12-04 23:39:40 +00:00
my $config = Slic3r::Config->new_from_defaults;
my $test = sub {
2012-12-05 10:52:52 +00:00
my ($conf) = @_;
$conf ||= $config;
2012-12-05 11:01:48 +00:00
my $print = Slic3r::Test::init_print('20mm_cube', config => $conf);
2012-11-21 19:41:14 +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);
2012-12-05 00:27:21 +00:00
my $lifted = 0;
my $changed_tool = 0;
my $wait_for_toolchange = 0;
Slic3r::GCode::Reader->new(gcode => Slic3r::Test::gcode($print))->parse(sub {
2012-11-21 19:41:14 +00:00
my ($self, $cmd, $args, $info) = @_;
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
if ($info->{dist_Z}) {
# lift move or lift + change layer
if (_eq($info->{dist_Z}, $print->extruders->[$tool]->retract_lift)
|| (_eq($info->{dist_Z}, $conf->layer_height + $print->extruders->[$tool]->retract_lift) && $print->extruders->[$tool]->retract_lift > 0)) {
fail 'only lifting while retracted' if !$retracted[$tool] && !($conf->g0 && $info->{retracting});
fail 'double lift' if $lifted;
2012-12-05 00:27:21 +00:00
$lifted = 1;
}
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'
if !_eq($info->{dist_Z}, -$print->extruders->[$tool]->retract_lift)
&& !_eq($info->{dist_Z}, -$print->extruders->[$tool]->retract_lift + $conf->layer_height);
2012-12-05 00:27:21 +00:00
$lifted = 0;
}
2013-04-08 20:23:51 +00:00
fail 'move Z at travel speed' if ($args->{F} // $self->F) != $conf->travel_speed * 60;
2012-12-05 00:27:21 +00:00
}
2012-11-21 19:41:14 +00:00
if ($info->{retracting}) {
$retracted[$tool] = 1;
$retracted_length[$tool] += -$info->{dist_E};
if (_eq($retracted_length[$tool], $print->extruders->[$tool]->retract_length)) {
# okay
} elsif (_eq($retracted_length[$tool], $print->extruders->[$tool]->retract_length_toolchange)) {
$wait_for_toolchange = 1;
} else {
fail 'retracted by the correct amount';
}
2012-12-05 10:52:52 +00:00
fail 'combining retraction and travel with G0'
2012-12-05 11:01:48 +00:00
if $cmd ne 'G0' && $conf->g0 && ($info->{dist_Z} || $info->{dist_XY});
2012-11-21 19:41:14 +00:00
}
if ($info->{extruding}) {
2012-12-05 00:27:21 +00:00
fail 'only extruding while not lifted' if $lifted;
if ($retracted[$tool]) {
my $expected_amount = $retracted_length[$tool] + $print->extruders->[$tool]->retract_restart_extra;
if ($changed_tool && $toolchange_count[$tool] > 1) {
$expected_amount = $print->extruders->[$tool]->retract_length_toolchange + $print->extruders->[$tool]->retract_restart_extra_toolchange;
$changed_tool = 0;
}
2012-12-04 23:39:40 +00:00
fail 'unretracted by the correct amount'
2012-12-21 12:25:03 +00:00
if !_eq($info->{dist_E}, $expected_amount);
$retracted[$tool] = 0;
$retracted_length[$tool] = 0;
2012-12-04 23:39:40 +00:00
}
2012-11-21 19:41:14 +00:00
}
if ($info->{travel} && $info->{dist_XY} >= $print->extruders->[$tool]->retract_before_travel) {
fail 'retracted before long travel move' if !$retracted[$tool];
2012-11-21 19:41:14 +00:00
}
});
2012-12-04 23:39:40 +00:00
1;
};
$config->set('first_layer_height', $config->layer_height);
2013-04-08 20:23:51 +00:00
$config->set('first_layer_speed', '100%');
2013-03-09 21:05:41 +00:00
$config->set('start_gcode', ''); # to avoid dealing with the nozzle lift in start G-code
2012-12-04 23:39:40 +00:00
$config->set('retract_length', [1.5]);
$config->set('retract_before_travel', [3]);
2013-03-07 15:24:25 +00:00
$config->set('only_retract_when_crossing_perimeters', 0);
2012-11-21 19:41:14 +00:00
2012-12-05 10:52:52 +00:00
my $retract_tests = sub {
my ($descr) = @_;
ok $test->(), "retraction$descr";
my $conf = $config->clone;
$conf->set('retract_restart_extra', [1]);
ok $test->($conf), "restart extra length$descr";
$conf->set('retract_restart_extra', [-1]);
ok $test->($conf), "negative restart extra length$descr";
2012-12-05 10:52:52 +00:00
$conf->set('retract_lift', [1]);
ok $test->($conf), "lift$descr";
};
2012-11-21 19:41:14 +00:00
2012-12-05 10:52:52 +00:00
$retract_tests->('');
$config->set('duplicate', 2);
$retract_tests->(' (duplicate)');
2012-12-05 10:52:52 +00:00
$config->set('g0', 1);
$retract_tests->(' (G0 and duplicate)');
2012-12-05 00:27:21 +00:00
$config->set('duplicate', 1);
$config->set('g0', 0);
$config->set('infill_extruder', 2);
$config->set('skirts', 4);
$config->set('skirt_height', 3);
$retract_tests->(' (dual extruder with multiple skirt layers)');
2012-11-21 19:41:14 +00:00
__END__