~ubuntu-branches/ubuntu/utopic/slic3r/utopic

« back to all changes in this revision

Viewing changes to t/cooling.t

  • Committer: Package Import Robot
  • Author(s): Chow Loong Jin
  • Date: 2014-06-17 01:27:26 UTC
  • Revision ID: package-import@ubuntu.com-20140617012726-2wrs4zdo251nr4vg
Tags: upstream-1.1.4+dfsg
ImportĀ upstreamĀ versionĀ 1.1.4+dfsg

Show diffs side-by-side

added added

removed removed

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