Fix speed math for wipe, which was causing too fast retraction. Includes regression test. #1468

This commit is contained in:
Alessandro Ranellucci 2013-10-13 17:04:47 +02:00
parent bc0b9e1b72
commit 4c2c31b554
3 changed files with 22 additions and 8 deletions

View file

@ -41,6 +41,9 @@ sub _build_retract_speed_mm_min {
sub _build_scaled_wipe_distance { sub _build_scaled_wipe_distance {
my $self = shift; my $self = shift;
# how far do we move in XY at travel_speed for the time needed to consume
# retract_length at retract_speed?
# reduce feedrate a bit; travel speed is often too high to move on existing material # reduce feedrate a bit; travel speed is often too high to move on existing material
# too fast = ripping of existing material; too slow = short wipe path, thus more blob # too fast = ripping of existing material; too slow = short wipe path, thus more blob
return scale($self->retract_length / $self->retract_speed * $Slic3r::Config->travel_speed * 0.8); return scale($self->retract_length / $self->retract_speed * $Slic3r::Config->travel_speed * 0.8);

View file

@ -485,19 +485,23 @@ sub retract {
: [undef, $self->z + $self->extruder->retract_lift, 0, 'lift plate during travel']; : [undef, $self->z + $self->extruder->retract_lift, 0, 'lift plate during travel'];
# check that we have a positive wipe length # check that we have a positive wipe length
if ($wipe_path && (my $total_wipe_length = $wipe_path->length)) { if ($wipe_path) {
$self->speed('travel'); $self->speed($self->speeds->{travel} * 0.8);
# subdivide the retraction # subdivide the retraction
my $retracted = 0; my $retracted = 0;
for (1 .. $#$wipe_path) { foreach my $line (@{$wipe_path->lines}) {
my $segment_length = $wipe_path->[$_-1]->distance_to($wipe_path->[$_]); my $segment_length = $line->length;
$retracted += my $e = $retract->[2] * ($segment_length / $total_wipe_length); # reduce retraction length a bit to avoid effective retraction speed to be greater than the configured one
$gcode .= $self->G1($wipe_path->[$_], undef, $e, $retract->[3] . ";_WIPE"); # due to rounding
my $e = $retract->[2] * ($segment_length / $self->extruder->scaled_wipe_distance) * 0.95;
$retracted += $e;
$gcode .= $self->G1($line->b, undef, $e, $retract->[3] . ";_WIPE");
} }
if ($retracted > $retract->[2]) { if ($retracted > $retract->[2]) {
# if we retracted less than we had to, retract the remainder # if we retracted less than we had to, retract the remainder
# TODO: add regression test # TODO: add regression test
$self->speed('retract');
$gcode .= $self->G1(undef, undef, $retract->[2] - $retracted, $comment); $gcode .= $self->G1(undef, undef, $retract->[2] - $retracted, $comment);
} }
} else { } else {

View file

@ -1,4 +1,4 @@
use Test::More tests => 2; use Test::More tests => 3;
use strict; use strict;
use warnings; use warnings;
@ -7,6 +7,7 @@ BEGIN {
use lib "$FindBin::Bin/../lib"; use lib "$FindBin::Bin/../lib";
} }
use List::Util qw(first);
use Slic3r; use Slic3r;
use Slic3r::Geometry qw(scale); use Slic3r::Geometry qw(scale);
use Slic3r::Test; use Slic3r::Test;
@ -27,12 +28,18 @@ use Slic3r::Test;
my $print = Slic3r::Test::init_print('20mm_cube', config => $config); my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
my $have_wipe = 0; my $have_wipe = 0;
my @retract_speeds = ();
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub { Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
my ($self, $cmd, $args, $info) = @_; my ($self, $cmd, $args, $info) = @_;
$have_wipe = 1 if $info->{retracting} && $info->{dist_XY} > 0; if ($info->{retracting} && $info->{dist_XY} > 0) {
$have_wipe = 1;
my $move_time = $info->{dist_XY} / ($args->{F} // $self->F);
push @retract_speeds, abs($info->{dist_E}) / $move_time;
}
}); });
ok $have_wipe, "wipe"; ok $have_wipe, "wipe";
ok !defined (first { abs($_ - $config->retract_speed->[0]*60) < 5 } @retract_speeds), 'wipe moves don\'t retract faster than configured speed';
} }
__END__ __END__