New --cooling option and checkbox to enable/disable fan and cooling control

This commit is contained in:
Alessandro Ranellucci 2012-02-25 21:56:36 +01:00
parent 70e69be60a
commit 170d29a789
7 changed files with 33 additions and 24 deletions

View File

@ -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%)

View File

@ -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;

View File

@ -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',

View File

@ -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));
}

View File

@ -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 => {

View File

@ -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;
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;
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;
}
$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;

View File

@ -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%)