Skip to content

Commit

Permalink
Make retraction configurable for each extruder
Browse files Browse the repository at this point in the history
  • Loading branch information
alranel committed Aug 7, 2012
1 parent 63e77fc commit cf01c14
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 43 deletions.
61 changes: 37 additions & 24 deletions lib/Slic3r/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ use constant PI => 4 * atan2(1, 1);
# cemetery of old config settings
our @Ignore = qw(duplicate_x duplicate_y multiply_x multiply_y support_material_tool);

my $serialize_comma = sub { join ',', @{$_[0]} };
my $deserialize_comma = sub { [ split /,/, $_[0] ] };

our $Options = {

# miscellaneous options
Expand Down Expand Up @@ -52,8 +55,8 @@ our $Options = {
sidetext => 'mm',
cli => 'print-center=s',
type => 'point',
serialize => sub { join ',', @{$_[0]} },
deserialize => sub { [ split /[,x]/, $_[0] ] },
serialize => $serialize_comma,
deserialize => $deserialize_comma,
default => [100,100],
},
'gcode_flavor' => {
Expand Down Expand Up @@ -116,8 +119,8 @@ our $Options = {
cli => 'nozzle-diameter=f@',
type => 'f',
sidetext => 'mm',
serialize => sub { join ',', @{$_[0]} },
deserialize => sub { [ split /,/, $_[0] ] },
serialize => $serialize_comma,
deserialize => $deserialize_comma,
default => [0.5],
},
'filament_diameter' => {
Expand All @@ -126,17 +129,17 @@ our $Options = {
sidetext => 'mm',
cli => 'filament-diameter=f@',
type => 'f',
serialize => sub { join ',', @{$_[0]} },
deserialize => sub { [ split /,/, $_[0] ] },
serialize => $serialize_comma,
deserialize => $deserialize_comma,
default => [3],
},
'extrusion_multiplier' => {
label => 'Extrusion multiplier',
tooltip => 'This factor changes the amount of flow proportionally. You may need to tweak this setting to get nice surface finish and correct single wall widths. Usual values are between 0.9 and 1.1. If you think you need to change this more, check filament diameter and your firmware E steps.',
cli => 'extrusion-multiplier=f@',
type => 'f',
serialize => sub { join ',', @{$_[0]} },
deserialize => sub { [ split /,/, $_[0] ] },
serialize => $serialize_comma,
deserialize => $deserialize_comma,
default => [1],
},
'temperature' => {
Expand All @@ -146,8 +149,8 @@ our $Options = {
cli => 'temperature=i@',
type => 'i',
max => 300,
serialize => sub { join ',', @{$_[0]} },
deserialize => sub { [ split /,/, $_[0] ] },
serialize => $serialize_comma,
deserialize => $deserialize_comma,
default => [200],
},
'first_layer_temperature' => {
Expand All @@ -156,8 +159,8 @@ our $Options = {
sidetext => '°C',
cli => 'first-layer-temperature=i@',
type => 'i',
serialize => sub { join ',', @{$_[0]} },
deserialize => sub { [ split /,/, $_[0] ] },
serialize => $serialize_comma,
deserialize => $deserialize_comma,
max => 300,
default => [200],
},
Expand Down Expand Up @@ -547,42 +550,52 @@ END
label => 'Length',
tooltip => 'When retraction is triggered, filament is pulled back by the specified amount (the length is measured on raw filament, before it enters the extruder).',
sidetext => 'mm (zero to disable)',
cli => 'retract-length=f',
cli => 'retract-length=f@',
type => 'f',
default => 1,
serialize => $serialize_comma,
deserialize => $deserialize_comma,
default => [1],
},
'retract_speed' => {
label => 'Speed',
tooltip => 'The speed for retractions (it only applies to the extruder motor).',
sidetext => 'mm/s',
cli => 'retract-speed=f',
cli => 'retract-speed=f@',
type => 'i',
max => 1000,
default => 30,
serialize => $serialize_comma,
deserialize => $deserialize_comma,
default => [30],
},
'retract_restart_extra' => {
label => 'Extra length on restart',
tooltip => 'When the retraction is compensated after the travel move, the extruder will push this additional amount of filament. This setting is rarely needed.',
sidetext => 'mm',
cli => 'retract-restart-extra=f',
cli => 'retract-restart-extra=f@',
type => 'f',
default => 0,
serialize => $serialize_comma,
deserialize => $deserialize_comma,
default => [0],
},
'retract_before_travel' => {
label => 'Minimum travel after retraction',
tooltip => 'Retraction is not triggered when travel moves are shorter than this length.',
sidetext => 'mm',
cli => 'retract-before-travel=f',
cli => 'retract-before-travel=f@',
type => 'f',
default => 2,
serialize => $serialize_comma,
deserialize => $deserialize_comma,
default => [2],
},
'retract_lift' => {
label => 'Lift Z',
tooltip => 'If you set this to a positive value, Z is quickly raised every time a retraction is triggered.',
sidetext => 'mm',
cli => 'retract-lift=f',
cli => 'retract-lift=f@',
type => 'f',
default => 0,
serialize => $serialize_comma,
deserialize => $deserialize_comma,
default => [0],
},

# cooling options
Expand Down Expand Up @@ -727,15 +740,15 @@ END
sidetext => 'mm',
cli => 'bed-size=s',
type => 'point',
serialize => sub { join ',', @{$_[0]} },
serialize => $serialize_comma,
deserialize => sub { [ split /[,x]/, $_[0] ] },
default => [200,200],
},
'duplicate_grid' => {
label => 'Copies (grid)',
cli => 'duplicate-grid=s',
type => 'point',
serialize => sub { join ',', @{$_[0]} },
serialize => $serialize_comma,
deserialize => sub { [ split /[,x]/, $_[0] ] },
default => [1,1],
},
Expand Down
7 changes: 7 additions & 0 deletions lib/Slic3r/Extruder.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,24 @@ use Slic3r::Geometry qw(PI);

use constant OPTIONS => [qw(
nozzle_diameter filament_diameter extrusion_multiplier temperature first_layer_temperature
retract_length retract_lift retract_speed retract_restart_extra retract_before_travel
)];
has $_ => (is => 'ro', required => 1) for @{&OPTIONS};

has 'e_per_mm3' => (is => 'lazy');
has 'retract_speed_mm_min' => (is => 'lazy');
has '_mm3_per_mm_cache' => (is => 'ro', default => sub {{}});

sub _build_e_per_mm3 {
my $self = shift;
return $self->extrusion_multiplier * (4 / (($self->filament_diameter ** 2) * PI));
}

sub _build_retract_speed_mm_min {
my $self = shift;
return $self->retract_speed * 60;
}

sub make_flow {
my $self = shift;
return Slic3r::Flow->new(nozzle_diameter => $self->nozzle_diameter, @_);
Expand Down
27 changes: 14 additions & 13 deletions lib/Slic3r/GCode.pm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ has 'speeds' => (
solid_infill => 60 * $Slic3r::Config->get_value('solid_infill_speed'),
top_solid_infill => 60 * $Slic3r::Config->get_value('top_solid_infill_speed'),
bridge => 60 * $Slic3r::Config->get_value('bridge_speed'),
retract => 60 * $Slic3r::Config->get_value('retract_speed'),
}},
);

Expand Down Expand Up @@ -137,7 +136,7 @@ sub extrude_path {
# specified by the user *and* to the maximum distance between infill lines
{
my $distance_from_last_pos = $self->last_pos->distance_to($path->points->[0]) * &Slic3r::SCALING_FACTOR;
my $distance_threshold = $Slic3r::Config->retract_before_travel;
my $distance_threshold = $self->extruder->retract_before_travel;
$distance_threshold = 2 * ($self->layer ? $self->layer->flow->width : $Slic3r::flow->width) / $Slic3r::Config->fill_density * sqrt(2)
if 0 && $Slic3r::Config->fill_density > 0 && $description =~ /fill/;

Expand Down Expand Up @@ -198,15 +197,15 @@ sub retract {
my $self = shift;
my %params = @_;

return "" unless $Slic3r::Config->retract_length > 0
return "" unless $self->extruder->retract_length > 0
&& !$self->retracted;

# prepare moves
$self->speed('retract');
my $retract = [undef, undef, -$Slic3r::Config->retract_length, "retract"];
my $lift = ($Slic3r::Config->retract_lift == 0 || defined $params{move_z})
my $retract = [undef, undef, -$self->extruder->retract_length, "retract"];
my $lift = ($self->extruder->retract_lift == 0 || defined $params{move_z})
? undef
: [undef, $self->z + $Slic3r::Config->retract_lift, 0, 'lift plate during retraction'];
: [undef, $self->z + $self->extruder->retract_lift, 0, 'lift plate during retraction'];

my $gcode = "";
if (($Slic3r::Config->g0 || $Slic3r::Config->gcode_flavor eq 'mach3') && $params{travel_to}) {
Expand All @@ -225,16 +224,16 @@ sub retract {
$gcode .= $self->G0(@$travel);
} else {
$gcode .= $self->G1(@$retract);
if (defined $params{move_z} && $Slic3r::Config->retract_lift > 0) {
my $travel = [undef, $params{move_z} + $Slic3r::Config->retract_lift, 0, 'move to next layer (' . $self->layer->id . ') and lift'];
if (defined $params{move_z} && $self->extruder->retract_lift > 0) {
my $travel = [undef, $params{move_z} + $self->extruder->retract_lift, 0, 'move to next layer (' . $self->layer->id . ') and lift'];
$gcode .= $self->G0(@$travel);
$self->lifted(1);
$self->lifted($self->extruder->retract_lift);
} elsif ($lift) {
$gcode .= $self->G1(@$lift);
}
}
$self->retracted(1);
$self->lifted(1) if $lift;
$self->lifted($self->extruder->retract_lift) if $lift;

# reset extrusion distance during retracts
# this makes sure we leave sufficient precision in the firmware
Expand All @@ -249,12 +248,12 @@ sub unretract {
my $gcode = "";

if ($self->lifted) {
$gcode .= $self->G0(undef, $self->z - $Slic3r::Config->retract_lift, 0, 'restore layer Z');
$gcode .= $self->G0(undef, $self->z - $self->lifted, 0, 'restore layer Z');
$self->lifted(0);
}

$self->speed('retract');
$gcode .= $self->G0(undef, undef, ($Slic3r::Config->retract_length + $Slic3r::Config->retract_restart_extra),
$gcode .= $self->G0(undef, undef, ($self->extruder->retract_length + $self->extruder->retract_restart_extra),
"compensate retraction");

return $gcode;
Expand Down Expand Up @@ -346,7 +345,9 @@ sub _Gx {
}

# apply the speed reduction for print moves on bottom layer
my $speed_f = $self->speeds->{$speed};
my $speed_f = $speed eq 'retract'
? ($self->extruder->retract_speed_mm_min)
: $self->speeds->{$speed};
if ($e && $self->layer->id == 0 && $comment !~ /retract/) {
$speed_f = $Slic3r::Config->first_layer_speed =~ /^(\d+(?:\.\d+)?)%$/
? ($speed_f * $1/100)
Expand Down
5 changes: 4 additions & 1 deletion lib/Slic3r/GUI/Tab.pm
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,10 @@ sub _build_extruder_pages {
},
{
title => 'Retraction',
options => [qw(retract_length retract_lift retract_speed retract_restart_extra retract_before_travel)],
options => [
map "${_}#${extruder_idx}",
qw(retract_length retract_lift retract_speed retract_restart_extra retract_before_travel)
],
},
]);
$self->{extruder_pages}[$extruder_idx]{disabled} = 0;
Expand Down
10 changes: 5 additions & 5 deletions slic3r.pl
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,14 @@ sub usage {
Retraction options:
--retract-length Length of retraction in mm when pausing extrusion
(default: $config->{retract_length})
--retract-speed Speed for retraction in mm/s (default: $config->{retract_speed})
(default: $config->{retract_length}[0])
--retract-speed Speed for retraction in mm/s (default: $config->{retract_speed}[0])
--retract-restart-extra
Additional amount of filament in mm to push after
compensating retraction (default: $config->{retract_restart_extra})
compensating retraction (default: $config->{retract_restart_extra}[0])
--retract-before-travel
Only retract before travel moves of this length in mm (default: $config->{retract_before_travel})
--retract-lift Lift Z by the given distance in mm when retracting (default: $config->{retract_lift})
Only retract before travel moves of this length in mm (default: $config->{retract_before_travel}[0])
--retract-lift Lift Z by the given distance in mm when retracting (default: $config->{retract_lift}[0])
Cooling options:
--cooling Enable fan and cooling control
Expand Down

0 comments on commit cf01c14

Please sign in to comment.