New --perimeter-feed-rate and --retract-before-travel options. Includes some refactoring and fixes.

This commit is contained in:
Alessandro Ranellucci 2011-10-02 09:57:37 +02:00
parent 55f2247cd9
commit 21d287504c
6 changed files with 97 additions and 44 deletions

View File

@ -73,7 +73,7 @@ The author is Alessandro Ranellucci (me).
--help Output this usage screen and exit --help Output this usage screen and exit
Printer options: Printer options:
--nozzle-diameter Diameter of nozzle in mm (default: 0.45) --nozzle-diameter Diameter of nozzle in mm (default: 0.55)
--print-center Coordinates of the point to center the print around --print-center Coordinates of the point to center the print around
(default: 100,100) (default: 100,100)
--use-relative-e-distances --use-relative-e-distances
@ -90,9 +90,11 @@ The author is Alessandro Ranellucci (me).
Speed options: Speed options:
--print-feed-rate Speed of print moves in mm/sec (default: 60) --print-feed-rate Speed of print moves in mm/sec (default: 60)
--travel-feed-rate Speed of non-print moves in mm/sec (default: 130) --travel-feed-rate Speed of non-print moves in mm/sec (default: 130)
--perimeter-feed-rate
Speed of print moves for perimeters in mm/sec (default: 60)
--bottom-layer-speed-ratio --bottom-layer-speed-ratio
Factor to increase/decrease speeds on bottom Factor to increase/decrease speeds on bottom
layer by (default: 0.6) layer by (default: 0.3)
Accuracy options: Accuracy options:
--layer-height Layer height in mm (default: 0.4) --layer-height Layer height in mm (default: 0.4)
@ -104,15 +106,18 @@ The author is Alessandro Ranellucci (me).
(range: 1+, default: 3) (range: 1+, default: 3)
--fill-density Infill density (range: 0-1, default: 0.4) --fill-density Infill density (range: 0-1, default: 0.4)
--fill-angle Infill angle in degrees (range: 0-90, default: 0) --fill-angle Infill angle in degrees (range: 0-90, default: 0)
--temperature Extrusion temperature (default: 195) --temperature Extrusion temperature (default: 200)
Retraction options: Retraction options:
--retract-length Length of retraction in mm when pausing extrusion --retract-length Length of retraction in mm when pausing extrusion
(default: 2) (default: 1)
--retract-speed Speed for retraction in mm/sec (default: 40) --retract-speed Speed for retraction in mm/sec (default: 40)
--retract-restart-extra --retract-restart-extra
Additional amount of filament in mm to push after Additional amount of filament in mm to push after
compensating retraction (default: 0) compensating retraction (default: 0)
--retract-before-travel
Only retract before travel moves of this length (default: 1)
Skirt options: Skirt options:
--skirts Number of skirts to draw (default: 1) --skirts Number of skirts to draw (default: 1)
--skirt-distance Distance in mm between innermost skirt and object --skirt-distance Distance in mm between innermost skirt and object
@ -125,3 +130,4 @@ The author is Alessandro Ranellucci (me).
--multiply-x Number of items along X axis (1+, default: 1) --multiply-x Number of items along X axis (1+, default: 1)
--multiply-y Number of items along Y axis (1+, default: 1) --multiply-y Number of items along Y axis (1+, default: 1)
--multiply-distance Distance in mm between copies (default: 6) --multiply-distance Distance in mm between copies (default: 6)

View File

@ -26,7 +26,7 @@ use Slic3r::Surface;
use Slic3r::Surface::Collection; use Slic3r::Surface::Collection;
# printer options # printer options
our $nozzle_diameter = 0.5; our $nozzle_diameter = 0.55;
our $print_center = [100,100]; # object will be centered around this point our $print_center = [100,100]; # object will be centered around this point
our $use_relative_e_distances = 0; our $use_relative_e_distances = 0;
our $z_offset = 0; our $z_offset = 0;
@ -38,6 +38,7 @@ our $filament_packing_density = 0.85;
# speed options # speed options
our $print_feed_rate = 60; # mm/sec our $print_feed_rate = 60; # mm/sec
our $travel_feed_rate = 130; # mm/sec our $travel_feed_rate = 130; # mm/sec
our $perimeter_feed_rate = 30; # mm/sec
our $bottom_layer_speed_ratio = 0.3; our $bottom_layer_speed_ratio = 0.3;
# accuracy options # accuracy options
@ -57,6 +58,7 @@ our $temperature = 200;
our $retract_length = 1; # mm our $retract_length = 1; # mm
our $retract_restart_extra = 0; # mm our $retract_restart_extra = 0; # mm
our $retract_speed = 40; # mm/sec our $retract_speed = 40; # mm/sec
our $retract_before_travel = 1; # mm
# skirt options # skirt options
our $skirts = 1; our $skirts = 1;

View File

@ -6,7 +6,7 @@ has 'shift_y' => (is => 'ro', default => sub {0} );
has 'z' => (is => 'rw', default => sub {0} ); has 'z' => (is => 'rw', default => sub {0} );
has 'extrusion_distance' => (is => 'rw', default => sub {0} ); has 'extrusion_distance' => (is => 'rw', default => sub {0} );
has 'retracted' => (is => 'rw', default => sub {0} ); has 'retracted' => (is => 'rw', default => sub {1} ); # this spits out some plastic at start
has 'last_pos' => (is => 'rw', default => sub { [0,0] } ); has 'last_pos' => (is => 'rw', default => sub { [0,0] } );
# calculate speeds # calculate speeds
@ -18,6 +18,10 @@ has 'print_feed_rate' => (
is => 'ro', is => 'ro',
default => sub { $Slic3r::print_feed_rate * 60 }, # mm/min default => sub { $Slic3r::print_feed_rate * 60 }, # mm/min
); );
has 'perimeter_feed_rate' => (
is => 'ro',
default => sub { $Slic3r::perimeter_feed_rate * 60 }, # mm/min
);
has 'retract_speed' => ( has 'retract_speed' => (
is => 'ro', is => 'ro',
default => sub { $Slic3r::retract_speed * 60 }, # mm/min default => sub { $Slic3r::retract_speed * 60 }, # mm/min
@ -39,8 +43,12 @@ sub move_z {
my $self = shift; my $self = shift;
my ($z) = @_; my ($z) = @_;
# TODO: retraction my $gcode = "";
return $self->G1(undef, $z, 0, 'move to next layer');
$gcode .= $self->retract;
$gcode .= $self->G1(undef, $z, 0, 'move to next layer');
return $gcode;
} }
sub extrude_loop { sub extrude_loop {
@ -72,15 +80,17 @@ sub extrude {
$gcode .= "G92 E0 ; reset extrusion distance\n"; $gcode .= "G92 E0 ; reset extrusion distance\n";
} }
# retract
if (Slic3r::Geometry::distance_between_points($self->last_pos, $path->points->[0]->p)
>= $Slic3r::retract_before_travel) {
$gcode .= $self->retract;
}
# go to first point of extrusion path # go to first point of extrusion path
$gcode .= $self->G1($path->points->[0], undef, 0, "move to first $description point"); $gcode .= $self->G1($path->points->[0], undef, 0, "move to first $description point");
# compensate retraction # compensate retraction
if ($self->retracted) { $gcode .= $self->unretract if $self->retracted;
$gcode .= $self->G1(undef, undef, ($Slic3r::retract_length + $Slic3r::retract_restart_extra),
"compensate retraction");
$self->retracted(0);
}
# extrude while going to next points # extrude while going to next points
foreach my $line ($path->lines) { foreach my $line ($path->lines) {
@ -94,15 +104,26 @@ sub extrude {
$gcode .= $self->G1($line->b, undef, $e, $description); $gcode .= $self->G1($line->b, undef, $e, $description);
} }
# retract
if ($Slic3r::retract_length > 0) {
$gcode .= $self->G1(undef, undef, -$Slic3r::retract_length, "retract");
$self->retracted(1);
}
return $gcode; return $gcode;
} }
sub retract {
my $self = shift;
return "" unless $Slic3r::retract_length > 0
&& $self->extrusion_distance > 0
&& !$self->retracted;
$self->retracted(1);
return $self->G1(undef, undef, -$Slic3r::retract_length, "retract");
}
sub unretract {
my $self = shift;
$self->retracted(0);
return $self->G1(undef, undef, ($Slic3r::retract_length + $Slic3r::retract_restart_extra),
"compensate retraction");
}
sub G1 { sub G1 {
my $self = shift; my $self = shift;
my ($point, $z, $e, $comment) = @_; my ($point, $z, $e, $comment) = @_;
@ -116,7 +137,7 @@ sub G1 {
($point->y * $Slic3r::resolution) + $self->shift_y; #** ($point->y * $Slic3r::resolution) + $self->shift_y; #**
$self->last_pos($point->p); $self->last_pos($point->p);
} }
if ($z && $z != $self->z) { if (defined $z && $z != $self->z) {
$self->z($z); $self->z($z);
$gcode .= sprintf " Z%.${dec}f", $z; $gcode .= sprintf " Z%.${dec}f", $z;
} }
@ -129,11 +150,12 @@ sub G1 {
if ($e) { if ($e) {
$self->extrusion_distance(0) if $Slic3r::use_relative_e_distances; $self->extrusion_distance(0) if $Slic3r::use_relative_e_distances;
$self->extrusion_distance($self->extrusion_distance + $e); $self->extrusion_distance($self->extrusion_distance + $e);
$gcode .= sprintf " F%.${dec}f E%.5f", my $speed = $self->print_feed_rate * $speed_multiplier;
$e < 0 $speed = $self->retract_speed if $comment =~ /retract/;
? $self->retract_speed $speed = $self->perimeter_feed_rate * $speed_multiplier if $comment =~ /perimeter/;
: ($self->print_feed_rate * $speed_multiplier),
$self->extrusion_distance; $gcode .= sprintf " F%.${dec}f E%.5f", $speed, $self->extrusion_distance;
} else { } else {
$gcode .= sprintf " F%.${dec}f", ($self->travel_feed_rate * $speed_multiplier); $gcode .= sprintf " F%.${dec}f", ($self->travel_feed_rate * $speed_multiplier);
} }

View File

@ -26,6 +26,32 @@ has 'layers' => (
default => sub { [] }, default => sub { [] },
); );
sub new_from_stl {
my $self = shift;
my ($stl_file) = @_;
my $print = Slic3r::STL->new->parse_file($stl_file);
print "\n==> PROCESSING SLICES:\n";
foreach my $layer (@{ $print->layers }) {
printf "\nProcessing layer %d:\n", $layer->id;
# build polylines of lines which do not already belong to a surface
my $polylines = $layer->make_polylines;
# build surfaces of polylines (distinguishing contours from holes)
$layer->make_surfaces($polylines);
# merge surfaces having a common line
$layer->merge_contiguous_surfaces;
}
# detect which surfaces are near external layers
$print->discover_horizontal_shells;
return $print;
}
sub layer_count { sub layer_count {
my $self = shift; my $self = shift;
return scalar @{ $self->layers }; return scalar @{ $self->layers };

View File

@ -90,23 +90,6 @@ sub parse_file {
} }
} }
print "\n==> PROCESSING SLICES:\n";
foreach my $layer (@{ $print->layers }) {
printf "\nProcessing layer %d:\n", $layer->id;
# build polylines of lines which do not already belong to a surface
my $polylines = $layer->make_polylines;
# build surfaces of polylines (distinguishing contours from holes)
$layer->make_surfaces($polylines);
# merge surfaces having a common line
$layer->merge_contiguous_surfaces;
}
# detect which surfaces are near external layers
$print->discover_horizontal_shells;
return $print; return $print;
} }

View File

@ -35,6 +35,7 @@ GetOptions(
# speed options # speed options
'print-feed-rate=i' => \$Slic3r::print_feed_rate, 'print-feed-rate=i' => \$Slic3r::print_feed_rate,
'travel-feed-rate=i' => \$Slic3r::travel_feed_rate, 'travel-feed-rate=i' => \$Slic3r::travel_feed_rate,
'perimeter-feed-rate=i' => \$Slic3r::perimeter_feed_rate,
'bottom-layer-speed-ratio=f' => \$Slic3r::bottom_layer_speed_ratio, 'bottom-layer-speed-ratio=f' => \$Slic3r::bottom_layer_speed_ratio,
# accuracy options # accuracy options
@ -49,7 +50,9 @@ GetOptions(
# retraction options # retraction options
'retract-length=f' => \$Slic3r::retract_length, 'retract-length=f' => \$Slic3r::retract_length,
'retract-speed=i' => \$Slic3r::retract_speed,
'retract-restart-extra=f' => \$Slic3r::retract_restart_extra, 'retract-restart-extra=f' => \$Slic3r::retract_restart_extra,
'retract-before-travel=f' => \$Slic3r::retract_before_travel,
# skirt options # skirt options
'skirts=i' => \$Slic3r::skirts, 'skirts=i' => \$Slic3r::skirts,
@ -82,6 +85,13 @@ GetOptions(
if $Slic3r::layer_height > $Slic3r::nozzle_diameter; if $Slic3r::layer_height > $Slic3r::nozzle_diameter;
$Slic3r::flow_width = ($Slic3r::nozzle_diameter**2) $Slic3r::flow_width = ($Slic3r::nozzle_diameter**2)
* $Slic3r::thickness_ratio * PI / (4 * $Slic3r::layer_height); * $Slic3r::thickness_ratio * PI / (4 * $Slic3r::layer_height);
my $max_flow_width = $Slic3r::layer_height + $Slic3r::nozzle_diameter;
if ($Slic3r::flow_width > $max_flow_width) {
$Slic3r::thickness_ratio = $max_flow_width / $Slic3r::flow_width;
$Slic3r::flow_width = $max_flow_width;
}
Slic3r::debugf "Flow width = $Slic3r::flow_width\n"; Slic3r::debugf "Flow width = $Slic3r::flow_width\n";
# --perimeters # --perimeters
@ -120,7 +130,6 @@ GetOptions(
if $Slic3r::multiply_distance < 1; if $Slic3r::multiply_distance < 1;
} }
my $stl_parser = Slic3r::STL->new;
my $action = 'skein'; my $action = 'skein';
if ($action eq 'skein') { if ($action eq 'skein') {
@ -129,7 +138,7 @@ if ($action eq 'skein') {
if $input_file !~ /\.stl$/i; if $input_file !~ /\.stl$/i;
my $t0 = [gettimeofday]; my $t0 = [gettimeofday];
my $print = $stl_parser->parse_file($input_file); my $print = Slic3r::Print->new_from_stl($input_file);
$print->extrude_perimeters; $print->extrude_perimeters;
$print->remove_small_features; $print->remove_small_features;
$print->extrude_fills; $print->extrude_fills;
@ -172,6 +181,8 @@ Usage: slic3r.pl [ OPTIONS ] file.stl
Speed options: Speed options:
--print-feed-rate Speed of print moves in mm/sec (default: $Slic3r::print_feed_rate) --print-feed-rate Speed of print moves in mm/sec (default: $Slic3r::print_feed_rate)
--travel-feed-rate Speed of non-print moves in mm/sec (default: $Slic3r::travel_feed_rate) --travel-feed-rate Speed of non-print moves in mm/sec (default: $Slic3r::travel_feed_rate)
--perimeter-feed-rate
Speed of print moves for perimeters in mm/sec (default: $Slic3r::print_feed_rate)
--bottom-layer-speed-ratio --bottom-layer-speed-ratio
Factor to increase/decrease speeds on bottom Factor to increase/decrease speeds on bottom
layer by (default: $Slic3r::bottom_layer_speed_ratio) layer by (default: $Slic3r::bottom_layer_speed_ratio)
@ -195,6 +206,9 @@ Usage: slic3r.pl [ OPTIONS ] file.stl
--retract-restart-extra --retract-restart-extra
Additional amount of filament in mm to push after Additional amount of filament in mm to push after
compensating retraction (default: $Slic3r::retract_restart_extra) compensating retraction (default: $Slic3r::retract_restart_extra)
--retract-before-travel
Only retract before travel moves of this length (default: $Slic3r::retract_before_travel)
Skirt options: Skirt options:
--skirts Number of skirts to draw (default: $Slic3r::skirts) --skirts Number of skirts to draw (default: $Slic3r::skirts)
--skirt-distance Distance in mm between innermost skirt and object --skirt-distance Distance in mm between innermost skirt and object