Fix retraction tests and fix retract_extra_length and lift in multiple extruders environments

This commit is contained in:
Alessandro Ranellucci 2012-12-21 15:14:44 +01:00
parent 701c98c5a7
commit dc4ada2374
4 changed files with 35 additions and 15 deletions

View file

@ -1,4 +1,4 @@
use Test::More tests => 9;
use Test::More tests => 12;
use strict;
use warnings;
@ -19,34 +19,46 @@ my $test = sub {
my $print = Slic3r::Test::init_print('20mm_cube', config => $conf);
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 $lifted = 0;
my $changed_tool = 0;
my $wait_for_toolchange = 0;
Slic3r::Test::GCodeReader->new(gcode => Slic3r::Test::gcode($print))->parse(sub {
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;
}
if ($info->{dist_Z}) {
# lift move or lift + change layer
if (_eq($info->{dist_Z}, $conf->retract_lift->[$tool])
|| (_eq($info->{dist_Z}, $conf->layer_height + $conf->retract_lift->[$tool]) && $conf->retract_lift->[$tool] > 0)) {
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});
$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'
if !_eq($info->{dist_Z}, -$conf->retract_lift->[$tool]);
if !_eq($info->{dist_Z}, -$print->extruders->[$tool]->retract_lift);
$lifted = 0;
}
}
if ($info->{retracting}) {
fail 'retracted by the correct amount'
if !_eq(-$info->{dist_E}, $conf->retract_length->[$tool]);
if (_eq(-$info->{dist_E}, $print->extruders->[$tool]->retract_length)) {
# okay
} elsif (_eq(-$info->{dist_E}, $print->extruders->[$tool]->retract_length_toolchange)) {
$wait_for_toolchange = 1;
} else {
fail 'retracted by the correct amount';
}
fail 'combining retraction and travel with G0'
if $cmd ne 'G0' && $conf->g0 && ($info->{dist_Z} || $info->{dist_XY});
$retracted[$tool] = 1;
@ -54,16 +66,17 @@ my $test = sub {
if ($info->{extruding}) {
fail 'only extruding while not lifted' if $lifted;
if ($retracted[$tool]) {
my $expected_amount = $conf->retract_length->[$tool] + $conf->retract_restart_extra->[$tool];
if ($changed_tool) {
$expected_amount = $conf->retract_length_toolchange->[$tool] + $conf->retract_restart_extra_toolchange->[$tool];
my $expected_amount = $print->extruders->[$tool]->retract_length + $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;
}
fail 'unretracted by the correct amount'
if !_eq($info->{dist_E}, $expected_amount);
$retracted[$tool] = 0;
}
}
if ($info->{travel} && $info->{dist_XY} >= $conf->retract_before_travel->[$tool]) {
if ($info->{travel} && $info->{dist_XY} >= $print->extruders->[$tool]->retract_before_travel) {
fail 'retracted before long travel move' if !$retracted[$tool];
}
});