Bugfix: retraction was still not working correctly at tool change

This commit is contained in:
Alessandro Ranellucci 2012-08-22 20:31:03 +02:00
parent edfdf236da
commit b35c41c1a3
2 changed files with 18 additions and 10 deletions

View File

@ -196,15 +196,18 @@ sub retract {
my $self = shift; my $self = shift;
my %params = @_; my %params = @_;
my ($length, $restart_extra) = $params{toolchange} # get the retraction length and abort if none
? ($self->extruder->retract_length_toolchange, $self->extruder->retract_restart_extra_toolchange) my ($length, $restart_extra, $comment) = $params{toolchange}
: ($self->extruder->retract_length, $self->extruder->retract_restart_extra); ? ($self->extruder->retract_length_toolchange, $self->extruder->retract_restart_extra_toolchange, "retract for tool change")
: ($self->extruder->retract_length, $self->extruder->retract_restart_extra, "retract");
return "" unless $length > 0 && !$self->extruder->retracted; # if we already retracted, reduce the required amount of retraction
$length -= $self->extruder->retracted;
return "" unless $length > 0;
# prepare moves # prepare moves
$self->speed('retract'); $self->speed('retract');
my $retract = [undef, undef, -$length, "retract"]; my $retract = [undef, undef, -$length, $comment];
my $lift = ($self->extruder->retract_lift == 0 || defined $params{move_z}) my $lift = ($self->extruder->retract_lift == 0 || defined $params{move_z})
? undef ? undef
: [undef, $self->z + $self->extruder->retract_lift, 0, 'lift plate during retraction']; : [undef, $self->z + $self->extruder->retract_lift, 0, 'lift plate during retraction'];
@ -217,12 +220,12 @@ sub retract {
$gcode .= $self->G0(@$lift); $gcode .= $self->G0(@$lift);
} else { } else {
# combine travel and retract # combine travel and retract
my $travel = [$params{travel_to}, undef, $retract->[2], 'travel and retract']; my $travel = [$params{travel_to}, undef, $retract->[2], "travel and $comment"];
$gcode .= $self->G0(@$travel); $gcode .= $self->G0(@$travel);
} }
} elsif (($Slic3r::Config->g0 || $Slic3r::Config->gcode_flavor eq 'mach3') && defined $params{move_z}) { } elsif (($Slic3r::Config->g0 || $Slic3r::Config->gcode_flavor eq 'mach3') && defined $params{move_z}) {
# combine Z change and retraction # combine Z change and retraction
my $travel = [undef, $params{move_z}, $retract->[2], 'change layer and retract']; my $travel = [undef, $params{move_z}, $retract->[2], "change layer and $comment"];
$gcode .= $self->G0(@$travel); $gcode .= $self->G0(@$travel);
} else { } else {
$gcode .= $self->G1(@$retract); $gcode .= $self->G1(@$retract);
@ -234,7 +237,7 @@ sub retract {
$gcode .= $self->G1(@$lift); $gcode .= $self->G1(@$lift);
} }
} }
$self->extruder->retracted($length + $restart_extra); $self->extruder->retracted($self->extruder->retracted + $length + $restart_extra);
$self->lifted($self->extruder->retract_lift) if $lift; $self->lifted($self->extruder->retract_lift) if $lift;
# reset extrusion distance during retracts # reset extrusion distance during retracts

View File

@ -569,8 +569,13 @@ sub write_gcode {
print $fh $gcodegen->set_tool(0); print $fh $gcodegen->set_tool(0);
print $fh $gcodegen->set_fan(0, 1) if $Slic3r::Config->cooling && $Slic3r::Config->disable_fan_first_layers; print $fh $gcodegen->set_fan(0, 1) if $Slic3r::Config->cooling && $Slic3r::Config->disable_fan_first_layers;
# this spits out some platic at start from the first extruder # this spits out some platic at start from each extruder when they are first used;
# (TODO: make this consistent in multi-head setups) # the primary extruder will compensate by the normal retraction length, while
# the others will compensate for their toolchange length + restart extra.
# this is a temporary solution as all extruders should use some kind of skirt
# to be put into a consistent state.
$_->retracted($_->retract_length_toolchange + $_->retract_restart_extra_toolchange)
for @{$Slic3r::extruders}[1 .. $#{$Slic3r::extruders}];
$gcodegen->retract; $gcodegen->retract;
# write start commands to file # write start commands to file