File: flowrate.pl

package info (click to toggle)
slic3r 1.3.0%2Bdfsg1-5.1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 8,552 kB
  • sloc: cpp: 63,126; perl: 21,512; ansic: 6,312; sh: 591; xml: 201; makefile: 37; python: 11
file content (53 lines) | stat: -rwxr-xr-x 1,352 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/perl -i

#
# Post-processing script for calculating flow rate for each move

use strict;
use warnings;

use constant PI => 3.141592653589793238;
my @filament_diameter = split /,/, $ENV{SLIC3R_FILAMENT_DIAMETER};

my $E = 0;
my $T = 0;
my ($X, $Y, $F);
while (<>) {
    if (/^G1.*? F([0-9.]+)/) {
        $F = $1;
    }
    if (/^G1 X([0-9.-]+) Y([0-9.-]+).*? E([0-9.-]+)/) {
        my ($x, $y, $e) = ($1, $2, $3);
        my $e_length = $e - $E;
        if ($e_length > 0 && defined $X && defined $Y) {
            my $dist = sqrt( (($x-$X)**2) + (($y-$Y)**2) );
            if ($dist > 0) {
                my $mm_per_mm   = $e_length / $dist;  # dE/dXY
                my $mm3_per_mm  = (($filament_diameter[$T] // 0) ** 2) * PI/4 * $mm_per_mm;
                my $vol_speed   = $F/60 * $mm3_per_mm;
                my $comment = sprintf ' ; dXY = %.3fmm ; dE = %.5fmm ; dE/XY = %.5fmm/mm; volspeed = %.5fmm^3/sec',
                    $dist, $e_length, $mm_per_mm, $vol_speed;
                s/(\R+)/$comment$1/;
            }
        }
        $E = $e;
        $X = $x;
        $Y = $y;
    }
    if (/^G1 X([0-9.]+) Y([0-9.]+)/) {
        $X = $1;
        $Y = $2;
    }
    if (/^G1.*? E([0-9.]+)/) {
        $E = $1;
    }
    if (/^G92 E0/) {
        $E = 0;
    }
    if (/^T(\d+)/) {
        $T = $1;
    }
    print;
}

__END__