From 170d29a7890c2e255843e601b095c31b734cf7a5 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 25 Feb 2012 21:56:36 +0100 Subject: [PATCH] New --cooling option and checkbox to enable/disable fan and cooling control --- README.markdown | 1 + lib/Slic3r.pm | 1 + lib/Slic3r/Config.pm | 5 ++++ lib/Slic3r/Extruder.pm | 3 +-- lib/Slic3r/GUI/SkeinPanel.pm | 2 +- lib/Slic3r/Print.pm | 44 +++++++++++++++++++----------------- slic3r.pl | 1 + 7 files changed, 33 insertions(+), 24 deletions(-) diff --git a/README.markdown b/README.markdown index 7d1fed624..9c79563f8 100644 --- a/README.markdown +++ b/README.markdown @@ -164,6 +164,7 @@ The author is Alessandro Ranellucci (me). --retract-lift Lift Z by the given distance in mm when retracting (default: 0) Cooling options: + --cooling Enable fan and cooling control --min-fan-speed Minimum fan speed (default: 35%) --max-fan-speed Maximum fan speed (default: 100%) --bridge-fan-speed Fan speed to use when bridging (default: 100%) diff --git a/lib/Slic3r.pm b/lib/Slic3r.pm index 3b62ecc9b..bb2c1ac8e 100644 --- a/lib/Slic3r.pm +++ b/lib/Slic3r.pm @@ -115,6 +115,7 @@ our $retract_before_travel = 2; # mm our $retract_lift = 0; # mm # cooling options +our $cooling = 0; our $min_fan_speed = 35; our $max_fan_speed = 100; our $bridge_fan_speed = 100; diff --git a/lib/Slic3r/Config.pm b/lib/Slic3r/Config.pm index 80ba87ea1..b3172572c 100644 --- a/lib/Slic3r/Config.pm +++ b/lib/Slic3r/Config.pm @@ -293,6 +293,11 @@ our $Options = { }, # cooling options + 'cooling' => { + label => 'Enable cooling', + cli => 'cooling', + type => 'bool', + }, 'min_fan_speed' => { label => 'Min fan speed (%)', cli => 'min-fan-speed=i', diff --git a/lib/Slic3r/Extruder.pm b/lib/Slic3r/Extruder.pm index 785dca6ea..c1ce91bc2 100644 --- a/lib/Slic3r/Extruder.pm +++ b/lib/Slic3r/Extruder.pm @@ -158,8 +158,7 @@ sub extrude_path { } } - # TODO: optimize: avoid calculation if cooling is disabled - if (1) { + if ($Slic3r::cooling) { $self->elapsed_time($self->elapsed_time + (unscale($path_length) / $self->speeds->{$self->last_speed} * 60)); } diff --git a/lib/Slic3r/GUI/SkeinPanel.pm b/lib/Slic3r/GUI/SkeinPanel.pm index d0fc516e8..6714933a4 100644 --- a/lib/Slic3r/GUI/SkeinPanel.pm +++ b/lib/Slic3r/GUI/SkeinPanel.pm @@ -49,7 +49,7 @@ sub new { }, cooling => { title => 'Cooling', - options => [qw(min_fan_speed max_fan_speed bridge_fan_speed fan_below_layer_time slowdown_below_layer_time min_print_speed disable_fan_first_layers)], + options => [qw(cooling min_fan_speed max_fan_speed bridge_fan_speed fan_below_layer_time slowdown_below_layer_time min_print_speed disable_fan_first_layers)], label_width => 300, }, skirt => { diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index 540c44d90..753c971a4 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -660,33 +660,35 @@ sub export_gcode { } last if !$layer_gcode; - my $layer_time = $extruder->elapsed_time; my $fan_speed = 0; my $speed_factor = 1; - Slic3r::debugf "Layer %d estimated printing time: %d seconds\n", $layer->id, $layer_time; - if ($layer_time < $Slic3r::fan_below_layer_time) { - if ($layer_time < $Slic3r::slowdown_below_layer_time) { - $fan_speed = $Slic3r::max_fan_speed; - $speed_factor = $layer_time / $Slic3r::slowdown_below_layer_time; - } else { - $fan_speed = $Slic3r::max_fan_speed - ($Slic3r::max_fan_speed - $Slic3r::min_fan_speed) - * ($layer_time - $Slic3r::slowdown_below_layer_time) - / ($Slic3r::fan_below_layer_time - $Slic3r::slowdown_below_layer_time); #/ + if ($Slic3r::cooling) { + my $layer_time = $extruder->elapsed_time; + Slic3r::debugf "Layer %d estimated printing time: %d seconds\n", $layer->id, $layer_time; + if ($layer_time < $Slic3r::fan_below_layer_time) { + if ($layer_time < $Slic3r::slowdown_below_layer_time) { + $fan_speed = $Slic3r::max_fan_speed; + $speed_factor = $layer_time / $Slic3r::slowdown_below_layer_time; + } else { + $fan_speed = $Slic3r::max_fan_speed - ($Slic3r::max_fan_speed - $Slic3r::min_fan_speed) + * ($layer_time - $Slic3r::slowdown_below_layer_time) + / ($Slic3r::fan_below_layer_time - $Slic3r::slowdown_below_layer_time); #/ + } } + Slic3r::debugf " fan = %d%%, speed = %d%%\n", $fan_speed, $speed_factor * 100; + + if ($speed_factor < 1) { + $layer_gcode =~ s/^(?=.*? [XY])(G1 .*?F)(\d+(?:\.\d+)?)/ + my $new_speed = $2 * $speed_factor; + $1 . sprintf("%.${dec}f", $new_speed < $min_print_speed ? $min_print_speed : $new_speed) + /gexm; + } + $fan_speed = 0 if $layer->id < $Slic3r::disable_fan_first_layers; + $layer_gcode = $extruder->set_fan($fan_speed) . $layer_gcode; } - Slic3r::debugf " fan = %d%%, speed = %d%%\n", $fan_speed, $speed_factor * 100; - - if ($speed_factor < 1) { - $layer_gcode =~ s/^(?=.*? [XY])(G1 .*?F)(\d+(?:\.\d+)?)/ - my $new_speed = $2 * $speed_factor; - $1 . sprintf("%.${dec}f", $new_speed < $min_print_speed ? $min_print_speed : $new_speed) - /gexm; - } - $fan_speed = 0 if $layer->id < $Slic3r::disable_fan_first_layers; - $layer_gcode = $extruder->set_fan($fan_speed) . $layer_gcode; # bridge fan speed - if ($Slic3r::bridge_fan_speed == 0 || $layer->id < $Slic3r::disable_fan_first_layers) { + if (!$Slic3r::cooling || $Slic3r::bridge_fan_speed == 0 || $layer->id < $Slic3r::disable_fan_first_layers) { $layer_gcode =~ s/^_BRIDGE_FAN_(?:START|END)\n//gm; } else { $layer_gcode =~ s/^_BRIDGE_FAN_START\n/ $extruder->set_fan($Slic3r::bridge_fan_speed, 1) /gmex; diff --git a/slic3r.pl b/slic3r.pl index 36b2ec495..eeef4cbcc 100755 --- a/slic3r.pl +++ b/slic3r.pl @@ -182,6 +182,7 @@ Usage: slic3r.pl [ OPTIONS ] file.stl --retract-lift Lift Z by the given distance in mm when retracting (default: $Slic3r::retract_lift) Cooling options: + --cooling Enable fan and cooling control --min-fan-speed Minimum fan speed (default: $Slic3r::min_fan_speed%) --max-fan-speed Maximum fan speed (default: $Slic3r::max_fan_speed%) --bridge-fan-speed Fan speed to use when bridging (default: $Slic3r::bridge_fan_speed%)