From cf01c142de3ad2d0c8c071074f2b8473cd44ac65 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Tue, 7 Aug 2012 21:08:56 +0200 Subject: [PATCH] Make retraction configurable for each extruder --- lib/Slic3r/Config.pm | 61 +++++++++++++++++++++++++----------------- lib/Slic3r/Extruder.pm | 7 +++++ lib/Slic3r/GCode.pm | 27 ++++++++++--------- lib/Slic3r/GUI/Tab.pm | 5 +++- slic3r.pl | 10 +++---- 5 files changed, 67 insertions(+), 43 deletions(-) diff --git a/lib/Slic3r/Config.pm b/lib/Slic3r/Config.pm index b44a111cd..771c6f57a 100644 --- a/lib/Slic3r/Config.pm +++ b/lib/Slic3r/Config.pm @@ -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 @@ -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' => { @@ -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' => { @@ -126,8 +129,8 @@ 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' => { @@ -135,8 +138,8 @@ our $Options = { 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' => { @@ -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' => { @@ -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], }, @@ -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 @@ -727,7 +740,7 @@ END sidetext => 'mm', cli => 'bed-size=s', type => 'point', - serialize => sub { join ',', @{$_[0]} }, + serialize => $serialize_comma, deserialize => sub { [ split /[,x]/, $_[0] ] }, default => [200,200], }, @@ -735,7 +748,7 @@ END label => 'Copies (grid)', cli => 'duplicate-grid=s', type => 'point', - serialize => sub { join ',', @{$_[0]} }, + serialize => $serialize_comma, deserialize => sub { [ split /[,x]/, $_[0] ] }, default => [1,1], }, diff --git a/lib/Slic3r/Extruder.pm b/lib/Slic3r/Extruder.pm index 20d10d0db..73493c9ee 100644 --- a/lib/Slic3r/Extruder.pm +++ b/lib/Slic3r/Extruder.pm @@ -5,10 +5,12 @@ 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 { @@ -16,6 +18,11 @@ sub _build_e_per_mm3 { 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, @_); diff --git a/lib/Slic3r/GCode.pm b/lib/Slic3r/GCode.pm index f42f005d0..a479ef265 100644 --- a/lib/Slic3r/GCode.pm +++ b/lib/Slic3r/GCode.pm @@ -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'), }}, ); @@ -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/; @@ -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}) { @@ -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 @@ -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; @@ -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) diff --git a/lib/Slic3r/GUI/Tab.pm b/lib/Slic3r/GUI/Tab.pm index 6dc19c2bd..7396c7792 100644 --- a/lib/Slic3r/GUI/Tab.pm +++ b/lib/Slic3r/GUI/Tab.pm @@ -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; diff --git a/slic3r.pl b/slic3r.pl index 90da6aac8..99896256a 100755 --- a/slic3r.pl +++ b/slic3r.pl @@ -227,14 +227,14 @@ $j 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