1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
use Test::More;
use strict;
use warnings;
plan tests => 11;
BEGIN {
use FindBin;
use lib "$FindBin::Bin/../lib";
}
use Slic3r;
use Slic3r::Test;
sub buffer {
my $config = shift || Slic3r::Config->new;
my $print_config = Slic3r::Config::Print->new;
$print_config->apply_dynamic($config);
my $gcodegen = Slic3r::GCode->new;
$gcodegen->apply_print_config($print_config);
$gcodegen->set_layer_count(10);
my $buffer = Slic3r::GCode::CoolingBuffer->new(
config => $print_config,
gcodegen => $gcodegen,
);
return $buffer;
}
my $config = Slic3r::Config->new_from_defaults;
$config->set('disable_fan_first_layers', 0);
{
my $buffer = buffer($config);
$buffer->gcodegen->set_elapsed_time($buffer->config->slowdown_below_layer_time + 1);
my $gcode = $buffer->append('G1 F3000;_EXTRUDE_SET_SPEED\nG1 X100 E1', 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->set_elapsed_time($buffer->config->slowdown_below_layer_time - 1);
my $gcode = $buffer->append(
"G1 X50 F2500\n" .
"G1 F3000;_EXTRUDE_SET_SPEED\n" .
"G1 X100 E1\n" .
"G1 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->set_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->set_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->set_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->set_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';
}
{
my $config = Slic3r::Config->new_from_defaults;
$config->set('cooling', 1);
$config->set('bridge_fan_speed', 100);
$config->set('fan_below_layer_time', 0);
$config->set('slowdown_below_layer_time', 0);
$config->set('bridge_speed', 99);
$config->set('top_solid_layers', 1); # internal bridges use solid_infil speed
$config->set('bottom_solid_layers', 1); # internal bridges use solid_infil speed
$config->set('vibration_limit', 30); # test that fan is turned on even when vibration limit (or other G-code post-processor) is enabled
my $print = Slic3r::Test::init_print('overhang', config => $config);
my $fan = 0;
my $fan_with_incorrect_speeds = my $fan_with_incorrect_print_speeds = 0;
my $bridge_with_no_fan = 0;
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
my ($self, $cmd, $args, $info) = @_;
if ($cmd eq 'M106') {
$fan = $args->{S};
$fan_with_incorrect_speeds++ if $fan != 255;
} elsif ($cmd eq 'M107') {
$fan = 0;
} elsif ($info->{extruding} && $info->{dist_XY} > 0) {
$fan_with_incorrect_print_speeds++
if ($fan > 0) && ($args->{F} // $self->F) != 60*$config->bridge_speed;
$bridge_with_no_fan++
if !$fan && ($args->{F} // $self->F) == 60*$config->bridge_speed;
}
});
ok !$fan_with_incorrect_speeds, 'bridge fan speed is applied correctly';
ok !$fan_with_incorrect_print_speeds, 'bridge fan is only turned on for bridges';
ok !$bridge_with_no_fan, 'bridge fan is turned on for all bridges';
}
__END__
|