flowrate.pl 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/perl -i
  2. #
  3. # Post-processing script for calculating flow rate for each move
  4. use strict;
  5. use warnings;
  6. use constant PI => 3.141592653589793238;
  7. my @filament_diameter = split /,/, $ENV{SLIC3R_FILAMENT_DIAMETER};
  8. my $E = 0;
  9. my $T = 0;
  10. my ($X, $Y, $F);
  11. while (<>) {
  12. if (/^G1.*? F([0-9.]+)/) {
  13. $F = $1;
  14. }
  15. if (/^G1 X([0-9.-]+) Y([0-9.-]+).*? E([0-9.-]+)/) {
  16. my ($x, $y, $e) = ($1, $2, $3);
  17. my $e_length = $e - $E;
  18. if ($e_length > 0 && defined $X && defined $Y) {
  19. my $dist = sqrt( (($x-$X)**2) + (($y-$Y)**2) );
  20. if ($dist > 0) {
  21. my $mm_per_mm = $e_length / $dist; # dE/dXY
  22. my $mm3_per_mm = (($filament_diameter[$T] // 0) ** 2) * PI/4 * $mm_per_mm;
  23. my $vol_speed = $F/60 * $mm3_per_mm;
  24. my $comment = sprintf ' ; dXY = %.3fmm ; dE = %.5fmm ; dE/XY = %.5fmm/mm; volspeed = %.5fmm^3/sec',
  25. $dist, $e_length, $mm_per_mm, $vol_speed;
  26. s/(\R+)/$comment$1/;
  27. }
  28. }
  29. $E = $e;
  30. $X = $x;
  31. $Y = $y;
  32. }
  33. if (/^G1 X([0-9.]+) Y([0-9.]+)/) {
  34. $X = $1;
  35. $Y = $2;
  36. }
  37. if (/^G1.*? E([0-9.]+)/) {
  38. $E = $1;
  39. }
  40. if (/^G92 E0/) {
  41. $E = 0;
  42. }
  43. if (/^T(\d+)/) {
  44. $T = $1;
  45. }
  46. print;
  47. }
  48. __END__