Some fixes to the cooling logic and new test suite for cooling

This commit is contained in:
Alessandro Ranellucci 2013-05-31 12:18:33 +02:00
parent da76496988
commit 5c7dd2cf78
4 changed files with 110 additions and 7 deletions

View File

@ -66,6 +66,7 @@ t/clean_polylines.t
t/clipper.t
t/collinear.t
t/combineinfill.t
t/cooling.t
t/custom_gcode.t
t/dynamic.t
t/fill.t

View File

@ -6,7 +6,7 @@ has 'gcodegen' => (is => 'ro', required => 1);
has 'gcode' => (is => 'rw', default => sub {""});
has 'elapsed_time' => (is => 'rw', default => sub {0});
has 'layer_id' => (is => 'rw');
has 'last_z' => (is => 'rw');
has 'last_z' => (is => 'rw', default => sub { {} }); # obj_id => z (basically a 'last seen' table)
has 'min_print_speed' => (is => 'lazy');
sub _build_min_print_speed {
@ -16,15 +16,17 @@ sub _build_min_print_speed {
sub append {
my $self = shift;
my ($gcode, $layer) = @_;
my ($gcode, $obj_id, $layer_id, $print_z) = @_;
# TODO: differentiate $obj_id between normal layers and support layers
my $return = "";
if (defined $self->last_z && $self->last_z != $layer->print_z) {
if (exists $self->last_z->{$obj_id} && $self->last_z->{$obj_id} != $print_z) {
$return = $self->flush;
}
$self->layer_id($layer->id);
$self->last_z($layer->print_z);
$self->layer_id($layer_id);
$self->last_z->{$obj_id} = $print_z;
$self->gcode($self->gcode . $gcode);
$self->elapsed_time($self->elapsed_time + $self->gcodegen->elapsed_time);
$self->gcodegen->elapsed_time(0);
@ -39,6 +41,7 @@ sub flush {
my $elapsed = $self->elapsed_time;
$self->gcode("");
$self->elapsed_time(0);
$self->last_z({}); # reset the whole table otherwise we would compute overlapping times
my $fan_speed = $self->config->fan_always_on ? $self->config->min_fan_speed : 0;
my $speed_factor = 1;

View File

@ -794,7 +794,12 @@ sub write_gcode {
if $Slic3r::Config->first_layer_bed_temperature;
$print_first_layer_temperature->();
}
print $fh $buffer->append($layer_gcode->process_layer($layer, [$copy]), $layer);
print $fh $buffer->append(
$layer_gcode->process_layer($layer, [$copy]),
$layer->object."",
$layer->id,
$layer->print_z,
);
}
print $fh $buffer->flush;
$finished_objects++;
@ -807,7 +812,12 @@ sub write_gcode {
);
my @layers = sort { $a->print_z <=> $b->print_z } map @{$_->layers}, @{$self->objects};
foreach my $layer (@layers) {
print $fh $buffer->append($layer_gcode->process_layer($layer, $layer->object->copies), $layer);
print $fh $buffer->append(
$layer_gcode->process_layer($layer, $layer->object->copies),
$layer->object."",
$layer->id,
$layer->print_z,
);
}
print $fh $buffer->flush;
}

89
t/cooling.t Normal file
View File

@ -0,0 +1,89 @@
use Test::More;
use strict;
use warnings;
plan tests => 8;
BEGIN {
use FindBin;
use lib "$FindBin::Bin/../lib";
}
use Slic3r;
sub buffer {
my $config = shift || Slic3r::Config->new_from_defaults;
my $buffer = Slic3r::GCode::CoolingBuffer->new(
config => $config,
gcodegen => Slic3r::GCode->new(config => $config, layer_count => 10),
);
return $buffer;
}
my $config = Slic3r::Config->new_from_defaults;
$config->set('disable_fan_first_layers', 0);
{
my $buffer = buffer($config);
$buffer->gcodegen->elapsed_time($buffer->config->slowdown_below_layer_time + 1);
my $gcode = $buffer->append('G1 X100 E1 F3000', 0, 0, 0.4) . $buffer->flush;
like $gcode, qr/F3000/, 'speed is not altered when elapsed time is greater than slowdown threshold';
}
{
my $buffer = buffer($config);
$buffer->gcodegen->elapsed_time($buffer->config->slowdown_below_layer_time - 1);
my $gcode = $buffer->append("G1 X50 F2500\nG1 X100 E1 F3000\nG1 E4 F400", 0, 0, 0.4) . $buffer->flush;
unlike $gcode, qr/F3000/, 'speed is altered when elapsed time is lower than slowdown threshold';
like $gcode, qr/F2500/, 'speed is not altered for travel moves';
like $gcode, qr/F400/, 'speed is not altered for extruder-only moves';
}
{
my $buffer = buffer($config);
$buffer->gcodegen->elapsed_time($buffer->config->fan_below_layer_time + 1);
my $gcode = $buffer->append('G1 X100 E1 F3000', 0, 0, 0.4) . $buffer->flush;
unlike $gcode, qr/M106/, 'fan is not activated when elapsed time is greater than fan threshold';
}
{
my $buffer = buffer($config);
my $gcode = "";
for my $obj_id (0 .. 1) {
# use an elapsed time which is < the slowdown threshold but greater than it when summed twice
$buffer->gcodegen->elapsed_time($buffer->config->slowdown_below_layer_time - 1);
$gcode .= $buffer->append("G1 X100 E1 F3000\n", $obj_id, 0, 0.4);
}
$gcode .= $buffer->flush;
like $gcode, qr/F3000/, 'slowdown is computed on all objects printing at same Z';
}
{
my $buffer = buffer($config);
my $gcode = "";
for my $layer_id (0 .. 1) {
for my $obj_id (0 .. 1) {
# use an elapsed time which is < the threshold but greater than it when summed twice
$buffer->gcodegen->elapsed_time($buffer->config->fan_below_layer_time - 1);
$gcode .= $buffer->append("G1 X100 E1 F3000\n", $obj_id, $layer_id, 0.4 + 0.4*$layer_id + 0.1*$obj_id); # print same layer at distinct heights
}
}
$gcode .= $buffer->flush;
unlike $gcode, qr/M106/, 'fan activation is computed on all objects printing at different Z';
}
{
my $buffer = buffer($config);
my $gcode = "";
for my $layer_id (0 .. 1) {
for my $obj_id (0 .. 1) {
# use an elapsed time which is < the threshold even when summed twice
$buffer->gcodegen->elapsed_time($buffer->config->fan_below_layer_time/2 - 1);
$gcode .= $buffer->append("G1 X100 E1 F3000\n", $obj_id, $layer_id, 0.4 + 0.4*$layer_id + 0.1*$obj_id); # print same layer at distinct heights
}
}
$gcode .= $buffer->flush;
like $gcode, qr/M106/, 'fan activation is computed on all objects printing at different Z';
}
__END__