2011-09-26 09:42:08 +00:00
|
|
|
package Slic3r::Extruder;
|
|
|
|
use Moo;
|
|
|
|
|
2012-05-19 13:40:11 +00:00
|
|
|
use Slic3r::ExtrusionPath ':roles';
|
2012-02-25 20:01:00 +00:00
|
|
|
use Slic3r::Geometry qw(scale unscale);
|
2011-12-07 18:33:59 +00:00
|
|
|
|
2011-11-15 11:02:31 +00:00
|
|
|
has 'layer' => (is => 'rw');
|
2012-02-19 09:48:58 +00:00
|
|
|
has 'shift_x' => (is => 'rw', default => sub {0} );
|
|
|
|
has 'shift_y' => (is => 'rw', default => sub {0} );
|
2011-09-26 09:42:08 +00:00
|
|
|
has 'z' => (is => 'rw', default => sub {0} );
|
2012-02-25 20:01:00 +00:00
|
|
|
has 'speed' => (is => 'rw');
|
2011-09-26 09:42:08 +00:00
|
|
|
|
|
|
|
has 'extrusion_distance' => (is => 'rw', default => sub {0} );
|
2012-02-25 20:01:00 +00:00
|
|
|
has 'elapsed_time' => (is => 'rw', default => sub {0} ); # seconds
|
2011-12-20 14:29:15 +00:00
|
|
|
has 'total_extrusion_length' => (is => 'rw', default => sub {0} );
|
2011-10-02 07:57:37 +00:00
|
|
|
has 'retracted' => (is => 'rw', default => sub {1} ); # this spits out some plastic at start
|
2011-11-07 14:58:47 +00:00
|
|
|
has 'lifted' => (is => 'rw', default => sub {0} );
|
2011-11-26 16:01:00 +00:00
|
|
|
has 'last_pos' => (is => 'rw', default => sub { Slic3r::Point->new(0,0) } );
|
2012-02-25 20:01:00 +00:00
|
|
|
has 'last_speed' => (is => 'rw', default => sub {""});
|
|
|
|
has 'last_fan_speed' => (is => 'rw', default => sub {0});
|
2011-10-04 15:55:55 +00:00
|
|
|
has 'dec' => (is => 'ro', default => sub { 3 } );
|
2011-09-26 09:42:08 +00:00
|
|
|
|
2012-02-25 20:01:00 +00:00
|
|
|
# calculate speeds (mm/min)
|
|
|
|
has 'speeds' => (
|
2011-09-26 09:42:08 +00:00
|
|
|
is => 'ro',
|
2012-02-25 20:01:00 +00:00
|
|
|
default => sub {{
|
2012-06-06 17:57:16 +00:00
|
|
|
travel => 60 * Slic3r::Config->get('travel_speed'),
|
|
|
|
perimeter => 60 * Slic3r::Config->get('perimeter_speed'),
|
|
|
|
small_perimeter => 60 * Slic3r::Config->get('small_perimeter_speed'),
|
|
|
|
infill => 60 * Slic3r::Config->get('infill_speed'),
|
|
|
|
solid_infill => 60 * Slic3r::Config->get('solid_infill_speed'),
|
|
|
|
top_solid_infill => 60 * Slic3r::Config->get('top_solid_infill_speed'),
|
|
|
|
bridge => 60 * Slic3r::Config->get('bridge_speed'),
|
|
|
|
retract => 60 * Slic3r::Config->get('retract_speed'),
|
2012-02-25 20:01:00 +00:00
|
|
|
}},
|
2011-09-26 09:42:08 +00:00
|
|
|
);
|
|
|
|
|
2012-05-19 13:40:11 +00:00
|
|
|
my %role_speeds = (
|
2012-05-19 20:36:29 +00:00
|
|
|
&EXTR_ROLE_PERIMETER => 'perimeter',
|
|
|
|
&EXTR_ROLE_SMALLPERIMETER => 'small_perimeter',
|
|
|
|
&EXTR_ROLE_CONTOUR_INTERNAL_PERIMETER => 'perimeter',
|
|
|
|
&EXTR_ROLE_FILL => 'infill',
|
|
|
|
&EXTR_ROLE_SOLIDFILL => 'solid_infill',
|
2012-06-06 17:57:16 +00:00
|
|
|
&EXTR_ROLE_TOPSOLIDFILL => 'top_solid_infill',
|
2012-05-19 20:36:29 +00:00
|
|
|
&EXTR_ROLE_BRIDGE => 'bridge',
|
|
|
|
&EXTR_ROLE_SKIRT => 'perimeter',
|
|
|
|
&EXTR_ROLE_SUPPORTMATERIAL => 'perimeter',
|
2012-05-19 13:40:11 +00:00
|
|
|
);
|
|
|
|
|
2011-11-11 21:01:27 +00:00
|
|
|
use Slic3r::Geometry qw(points_coincide PI X Y);
|
2011-09-26 09:42:08 +00:00
|
|
|
|
2011-11-15 11:02:31 +00:00
|
|
|
sub change_layer {
|
2011-09-26 09:42:08 +00:00
|
|
|
my $self = shift;
|
2011-11-15 11:02:31 +00:00
|
|
|
my ($layer) = @_;
|
|
|
|
|
|
|
|
$self->layer($layer);
|
2012-04-16 12:05:38 +00:00
|
|
|
my $z = $Slic3r::z_offset + $layer->print_z * $Slic3r::scaling_factor;
|
2011-09-26 09:42:08 +00:00
|
|
|
|
2011-10-02 07:57:37 +00:00
|
|
|
my $gcode = "";
|
|
|
|
|
2011-11-14 11:45:20 +00:00
|
|
|
$gcode .= $self->retract(move_z => $z);
|
2012-05-01 13:06:19 +00:00
|
|
|
$gcode .= $self->G0(undef, $z, 0, 'move to next layer (' . $layer->id . ')')
|
2012-06-06 17:20:43 +00:00
|
|
|
if $self->z != $z && !$self->lifted;
|
2011-10-02 07:57:37 +00:00
|
|
|
|
2012-03-26 10:14:15 +00:00
|
|
|
$gcode .= Slic3r::Config->replace_options($Slic3r::layer_gcode) . "\n"
|
|
|
|
if $Slic3r::layer_gcode;
|
|
|
|
|
2011-10-02 07:57:37 +00:00
|
|
|
return $gcode;
|
2011-09-26 09:42:08 +00:00
|
|
|
}
|
|
|
|
|
2011-12-30 16:17:37 +00:00
|
|
|
sub extrude {
|
|
|
|
my $self = shift;
|
|
|
|
|
2012-05-19 17:40:51 +00:00
|
|
|
if ($_[0]->isa('Slic3r::ExtrusionLoop')) {
|
|
|
|
$self->extrude_loop(@_);
|
|
|
|
} else {
|
|
|
|
$_[0]->deserialize;
|
|
|
|
$self->extrude_path(@_);
|
|
|
|
}
|
2011-12-30 16:17:37 +00:00
|
|
|
}
|
|
|
|
|
2011-09-26 09:42:08 +00:00
|
|
|
sub extrude_loop {
|
|
|
|
my $self = shift;
|
|
|
|
my ($loop, $description) = @_;
|
2012-02-21 19:16:03 +00:00
|
|
|
|
|
|
|
# extrude all loops ccw
|
2012-05-19 15:57:38 +00:00
|
|
|
$loop->deserialize;
|
2012-02-21 19:16:03 +00:00
|
|
|
$loop->polygon->make_counter_clockwise;
|
|
|
|
|
2011-09-26 09:42:08 +00:00
|
|
|
# find the point of the loop that is closest to the current extruder position
|
2012-05-19 20:36:29 +00:00
|
|
|
# or randomize if requested
|
|
|
|
my $last_pos = $self->last_pos;
|
|
|
|
if ($Slic3r::randomize_start && $loop->role == EXTR_ROLE_CONTOUR_INTERNAL_PERIMETER) {
|
|
|
|
srand $self->layer->id * 10;
|
|
|
|
$last_pos = Slic3r::Point->new(scale $Slic3r::print_center->[X], scale $Slic3r::bed_size->[Y]);
|
|
|
|
$last_pos->rotate(rand(2*PI), $Slic3r::print_center);
|
|
|
|
}
|
|
|
|
my $start_at = $loop->nearest_point_to($last_pos);
|
2011-09-26 09:42:08 +00:00
|
|
|
|
|
|
|
# split the loop at the starting point and make a path
|
|
|
|
my $extrusion_path = $loop->split_at($start_at);
|
2012-05-19 15:57:38 +00:00
|
|
|
$extrusion_path->deserialize;
|
2011-09-26 09:42:08 +00:00
|
|
|
|
2012-05-13 20:56:40 +00:00
|
|
|
# clip the path to avoid the extruder to get exactly on the first point of the loop;
|
|
|
|
# if polyline was shorter than the clipping distance we'd get a null polyline, so
|
|
|
|
# we discard it in that case
|
2012-06-06 16:05:03 +00:00
|
|
|
$extrusion_path->clip_end(scale($self->layer ? $self->layer->flow->width : $Slic3r::flow->width) * 0.15);
|
2012-05-13 20:56:40 +00:00
|
|
|
return '' if !@{$extrusion_path->polyline};
|
2011-09-26 09:42:08 +00:00
|
|
|
|
|
|
|
# extrude along the path
|
2011-12-30 16:17:37 +00:00
|
|
|
return $self->extrude_path($extrusion_path, $description);
|
2011-09-26 09:42:08 +00:00
|
|
|
}
|
|
|
|
|
2011-12-30 16:17:37 +00:00
|
|
|
sub extrude_path {
|
2011-09-26 09:42:08 +00:00
|
|
|
my $self = shift;
|
2011-10-20 16:11:59 +00:00
|
|
|
my ($path, $description, $recursive) = @_;
|
|
|
|
|
2011-11-07 13:12:07 +00:00
|
|
|
$path->merge_continuous_lines;
|
|
|
|
|
|
|
|
# detect arcs
|
2011-10-20 16:11:59 +00:00
|
|
|
if ($Slic3r::gcode_arcs && !$recursive) {
|
|
|
|
my $gcode = "";
|
2012-06-07 17:53:27 +00:00
|
|
|
foreach my $arc_path ($path->detect_arcs) {
|
|
|
|
$arc_path->deserialize;
|
|
|
|
$gcode .= $self->extrude_path($arc_path, $description, 1);
|
|
|
|
}
|
2011-10-20 16:11:59 +00:00
|
|
|
return $gcode;
|
|
|
|
}
|
2011-09-26 09:42:08 +00:00
|
|
|
|
|
|
|
my $gcode = "";
|
|
|
|
|
2011-10-06 13:24:21 +00:00
|
|
|
# retract if distance from previous position is greater or equal to the one
|
|
|
|
# specified by the user *and* to the maximum distance between infill lines
|
2011-11-26 16:01:00 +00:00
|
|
|
{
|
2012-04-16 12:05:38 +00:00
|
|
|
my $distance_from_last_pos = $self->last_pos->distance_to($path->points->[0]) * $Slic3r::scaling_factor;
|
2011-11-26 16:01:00 +00:00
|
|
|
my $distance_threshold = $Slic3r::retract_before_travel;
|
2012-06-06 16:05:03 +00:00
|
|
|
$distance_threshold = 2 * ($self->layer ? $self->layer->flow->width : $Slic3r::flow->width) / $Slic3r::fill_density * sqrt(2)
|
2012-06-06 17:38:35 +00:00
|
|
|
if 0 && $Slic3r::fill_density > 0 && $description =~ /fill/;
|
2011-11-26 16:01:00 +00:00
|
|
|
|
|
|
|
if ($distance_from_last_pos >= $distance_threshold) {
|
|
|
|
$gcode .= $self->retract(travel_to => $path->points->[0]);
|
|
|
|
}
|
2011-10-02 07:57:37 +00:00
|
|
|
}
|
|
|
|
|
2011-09-26 09:42:08 +00:00
|
|
|
# go to first point of extrusion path
|
2011-11-14 11:15:32 +00:00
|
|
|
$gcode .= $self->G0($path->points->[0], undef, 0, "move to first $description point")
|
2011-10-20 16:11:59 +00:00
|
|
|
if !points_coincide($self->last_pos, $path->points->[0]);
|
2011-09-26 09:42:08 +00:00
|
|
|
|
|
|
|
# compensate retraction
|
2011-10-02 07:57:37 +00:00
|
|
|
$gcode .= $self->unretract if $self->retracted;
|
2011-10-20 16:11:59 +00:00
|
|
|
|
|
|
|
# calculate extrusion length per distance unit
|
2012-06-06 16:05:03 +00:00
|
|
|
my $s = $path->flow_spacing || $self->layer ? $self->layer->flow->spacing : $Slic3r::flow->spacing;
|
2012-01-30 13:03:12 +00:00
|
|
|
my $h = $path->depth_layers * $self->layer->height;
|
2012-06-06 16:05:03 +00:00
|
|
|
my $w = ($s - ($self->layer ? $self->layer->flow->min_spacing : $Slic3r::flow->min_spacing) * $Slic3r::overlap_factor) / (1 - $Slic3r::overlap_factor);
|
2011-12-17 18:52:34 +00:00
|
|
|
|
|
|
|
my $area;
|
2012-05-19 13:40:11 +00:00
|
|
|
if ($path->role == EXTR_ROLE_BRIDGE) {
|
2011-12-17 18:52:34 +00:00
|
|
|
$area = ($s**2) * PI/4;
|
|
|
|
} elsif ($w >= ($Slic3r::nozzle_diameter + $h)) {
|
|
|
|
# rectangle with semicircles at the ends
|
|
|
|
$area = $w * $h + ($h**2) / 4 * (PI - 4);
|
|
|
|
} else {
|
|
|
|
# rectangle with shrunk semicircles at the ends
|
|
|
|
$area = $Slic3r::nozzle_diameter * $h * (1 - PI/4) + $h * $w * PI/4;
|
|
|
|
}
|
2011-12-16 09:53:22 +00:00
|
|
|
|
2012-04-16 12:05:38 +00:00
|
|
|
my $e = $Slic3r::scaling_factor
|
2011-12-17 18:52:34 +00:00
|
|
|
* $area
|
2011-11-25 10:15:20 +00:00
|
|
|
* $Slic3r::extrusion_multiplier
|
2011-12-13 16:34:31 +00:00
|
|
|
* (4 / (($Slic3r::filament_diameter ** 2) * PI));
|
2011-10-20 16:11:59 +00:00
|
|
|
|
|
|
|
# extrude arc or line
|
2012-05-19 13:40:11 +00:00
|
|
|
$self->speed( $role_speeds{$path->role} || die "Unknown role: " . $path->role );
|
2012-02-25 20:01:00 +00:00
|
|
|
my $path_length = 0;
|
2011-10-20 16:11:59 +00:00
|
|
|
if ($path->isa('Slic3r::ExtrusionPath::Arc')) {
|
2012-02-25 20:01:00 +00:00
|
|
|
$path_length = $path->length;
|
2011-10-20 16:11:59 +00:00
|
|
|
$gcode .= $self->G2_G3($path->points->[-1], $path->orientation,
|
2012-02-25 20:01:00 +00:00
|
|
|
$path->center, $e * $path_length, $description);
|
2011-10-20 16:11:59 +00:00
|
|
|
} else {
|
|
|
|
foreach my $line ($path->lines) {
|
2012-02-25 20:01:00 +00:00
|
|
|
my $line_length = $line->length;
|
|
|
|
$path_length += $line_length;
|
|
|
|
$gcode .= $self->G1($line->b, undef, $e * $line_length, $description);
|
2011-10-20 16:11:59 +00:00
|
|
|
}
|
2011-09-26 09:42:08 +00:00
|
|
|
}
|
|
|
|
|
2012-02-25 20:56:36 +00:00
|
|
|
if ($Slic3r::cooling) {
|
2012-05-01 09:48:22 +00:00
|
|
|
my $path_time = unscale($path_length) / $self->speeds->{$self->last_speed} * 60;
|
2012-06-06 13:43:54 +00:00
|
|
|
if ($self->layer->id == 0) {
|
2012-06-07 09:38:54 +00:00
|
|
|
$path_time = $Slic3r::first_layer_speed =~ /^(\d+(?:\.\d+)?)%$/
|
2012-06-06 13:43:54 +00:00
|
|
|
? $path_time / ($1/100)
|
2012-06-06 13:52:21 +00:00
|
|
|
: unscale($path_length) / $Slic3r::first_layer_speed * 60;
|
2012-06-06 13:43:54 +00:00
|
|
|
}
|
2012-05-01 09:48:22 +00:00
|
|
|
$self->elapsed_time($self->elapsed_time + $path_time);
|
2012-02-25 20:01:00 +00:00
|
|
|
}
|
|
|
|
|
2011-09-26 09:42:08 +00:00
|
|
|
return $gcode;
|
|
|
|
}
|
|
|
|
|
2011-10-02 07:57:37 +00:00
|
|
|
sub retract {
|
|
|
|
my $self = shift;
|
2011-11-07 14:58:47 +00:00
|
|
|
my %params = @_;
|
|
|
|
|
2011-11-24 11:53:09 +00:00
|
|
|
return "" unless $Slic3r::retract_length > 0
|
2011-10-02 07:57:37 +00:00
|
|
|
&& !$self->retracted;
|
|
|
|
|
2011-11-14 11:15:32 +00:00
|
|
|
# prepare moves
|
2012-02-25 20:01:00 +00:00
|
|
|
$self->speed('retract');
|
2011-11-14 11:15:32 +00:00
|
|
|
my $retract = [undef, undef, -$Slic3r::retract_length, "retract"];
|
2011-11-28 18:59:39 +00:00
|
|
|
my $lift = ($Slic3r::retract_lift == 0 || defined $params{move_z})
|
2011-11-14 11:15:32 +00:00
|
|
|
? undef
|
|
|
|
: [undef, $self->z + $Slic3r::retract_lift, 0, 'lift plate during retraction'];
|
2011-10-11 15:53:50 +00:00
|
|
|
|
2011-11-14 11:15:32 +00:00
|
|
|
my $gcode = "";
|
2012-03-26 10:22:12 +00:00
|
|
|
if (($Slic3r::g0 || $Slic3r::gcode_flavor eq 'mach3') && $params{travel_to}) {
|
2011-11-14 11:15:32 +00:00
|
|
|
if ($lift) {
|
|
|
|
# combine lift and retract
|
|
|
|
$lift->[2] = $retract->[2];
|
|
|
|
$gcode .= $self->G0(@$lift);
|
|
|
|
} else {
|
|
|
|
# combine travel and retract
|
|
|
|
my $travel = [$params{travel_to}, undef, $retract->[2], 'travel and retract'];
|
|
|
|
$gcode .= $self->G0(@$travel);
|
|
|
|
}
|
2012-03-26 10:22:12 +00:00
|
|
|
} elsif (($Slic3r::g0 || $Slic3r::gcode_flavor eq 'mach3') && defined $params{move_z}) {
|
2011-11-14 11:45:20 +00:00
|
|
|
# combine Z change and retraction
|
|
|
|
my $travel = [undef, $params{move_z}, $retract->[2], 'change layer and retract'];
|
|
|
|
$gcode .= $self->G0(@$travel);
|
2011-11-14 11:15:32 +00:00
|
|
|
} else {
|
|
|
|
$gcode .= $self->G1(@$retract);
|
2012-06-17 17:36:02 +00:00
|
|
|
if (defined $params{move_z} && $Slic3r::retract_lift > 0) {
|
|
|
|
my $travel = [undef, $params{move_z} + $Slic3r::retract_lift, 0, 'move to next layer (' . $self->layer->id . ') and lift'];
|
|
|
|
$gcode .= $self->G0(@$travel);
|
|
|
|
$self->lifted(1);
|
|
|
|
} elsif ($lift) {
|
2011-11-14 11:15:32 +00:00
|
|
|
$gcode .= $self->G1(@$lift);
|
|
|
|
}
|
2011-11-07 14:58:47 +00:00
|
|
|
}
|
2011-11-14 11:15:32 +00:00
|
|
|
$self->retracted(1);
|
|
|
|
$self->lifted(1) if $lift;
|
2011-11-07 14:58:47 +00:00
|
|
|
|
2011-10-11 15:53:50 +00:00
|
|
|
# reset extrusion distance during retracts
|
|
|
|
# this makes sure we leave sufficient precision in the firmware
|
2012-06-24 19:05:21 +00:00
|
|
|
if (!$Slic3r::use_relative_e_distances && $Slic3r::gcode_flavor ne 'mach3') {
|
2012-04-16 18:06:53 +00:00
|
|
|
$gcode .= "G92 " . $Slic3r::extrusion_axis . "0\n" if $Slic3r::extrusion_axis;
|
2011-10-11 15:53:50 +00:00
|
|
|
$self->extrusion_distance(0);
|
|
|
|
}
|
2011-10-14 10:14:20 +00:00
|
|
|
|
|
|
|
return $gcode;
|
2011-10-02 07:57:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub unretract {
|
|
|
|
my $self = shift;
|
|
|
|
$self->retracted(0);
|
2011-11-07 14:58:47 +00:00
|
|
|
my $gcode = "";
|
|
|
|
|
|
|
|
if ($self->lifted) {
|
2011-11-14 11:45:20 +00:00
|
|
|
$gcode .= $self->G0(undef, $self->z - $Slic3r::retract_lift, 0, 'restore layer Z');
|
2011-11-07 14:58:47 +00:00
|
|
|
$self->lifted(0);
|
|
|
|
}
|
|
|
|
|
2012-02-25 20:01:00 +00:00
|
|
|
$self->speed('retract');
|
2011-11-14 11:45:20 +00:00
|
|
|
$gcode .= $self->G0(undef, undef, ($Slic3r::retract_length + $Slic3r::retract_restart_extra),
|
2011-10-02 07:57:37 +00:00
|
|
|
"compensate retraction");
|
2011-11-07 14:58:47 +00:00
|
|
|
|
|
|
|
return $gcode;
|
2011-10-02 07:57:37 +00:00
|
|
|
}
|
|
|
|
|
2012-02-10 13:53:44 +00:00
|
|
|
sub set_acceleration {
|
|
|
|
my $self = shift;
|
|
|
|
my ($acceleration) = @_;
|
2012-02-25 20:01:00 +00:00
|
|
|
return "" unless $Slic3r::acceleration;
|
2012-02-10 13:53:44 +00:00
|
|
|
|
|
|
|
return sprintf "M201 E%s%s\n",
|
|
|
|
$acceleration, ($Slic3r::gcode_comments ? ' ; adjust acceleration' : '');
|
|
|
|
}
|
|
|
|
|
2011-11-14 11:15:32 +00:00
|
|
|
sub G0 {
|
|
|
|
my $self = shift;
|
2012-03-26 10:22:12 +00:00
|
|
|
return $self->G1(@_) if !($Slic3r::g0 || $Slic3r::gcode_flavor eq 'mach3');
|
2012-02-25 20:01:00 +00:00
|
|
|
return $self->_G0_G1("G0", @_);
|
2011-11-14 11:15:32 +00:00
|
|
|
}
|
|
|
|
|
2011-09-26 09:42:08 +00:00
|
|
|
sub G1 {
|
2011-11-14 11:15:32 +00:00
|
|
|
my $self = shift;
|
2012-02-25 20:01:00 +00:00
|
|
|
return $self->_G0_G1("G1", @_);
|
2011-11-14 11:15:32 +00:00
|
|
|
}
|
|
|
|
|
2012-02-25 20:01:00 +00:00
|
|
|
sub _G0_G1 {
|
2011-09-26 09:42:08 +00:00
|
|
|
my $self = shift;
|
2012-02-25 20:01:00 +00:00
|
|
|
my ($gcode, $point, $z, $e, $comment) = @_;
|
2011-09-26 09:42:08 +00:00
|
|
|
my $dec = $self->dec;
|
|
|
|
|
|
|
|
if ($point) {
|
|
|
|
$gcode .= sprintf " X%.${dec}f Y%.${dec}f",
|
2012-04-16 12:05:38 +00:00
|
|
|
($point->x * $Slic3r::scaling_factor) + $self->shift_x,
|
|
|
|
($point->y * $Slic3r::scaling_factor) + $self->shift_y; #**
|
2011-10-12 12:54:49 +00:00
|
|
|
$self->last_pos($point);
|
2011-09-26 09:42:08 +00:00
|
|
|
}
|
2011-10-02 07:57:37 +00:00
|
|
|
if (defined $z && $z != $self->z) {
|
2011-09-26 09:42:08 +00:00
|
|
|
$self->z($z);
|
|
|
|
$gcode .= sprintf " Z%.${dec}f", $z;
|
|
|
|
}
|
|
|
|
|
2011-10-20 16:11:59 +00:00
|
|
|
return $self->_Gx($gcode, $e, $comment);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub G2_G3 {
|
|
|
|
my $self = shift;
|
|
|
|
my ($point, $orientation, $center, $e, $comment) = @_;
|
|
|
|
my $dec = $self->dec;
|
|
|
|
|
|
|
|
my $gcode = $orientation eq 'cw' ? "G2" : "G3";
|
|
|
|
|
|
|
|
$gcode .= sprintf " X%.${dec}f Y%.${dec}f",
|
2012-04-16 12:05:38 +00:00
|
|
|
($point->x * $Slic3r::scaling_factor) + $self->shift_x,
|
|
|
|
($point->y * $Slic3r::scaling_factor) + $self->shift_y; #**
|
2011-10-20 16:11:59 +00:00
|
|
|
|
|
|
|
# XY distance of the center from the start position
|
|
|
|
$gcode .= sprintf " I%.${dec}f J%.${dec}f",
|
2012-04-16 12:05:38 +00:00
|
|
|
($center->[X] - $self->last_pos->[X]) * $Slic3r::scaling_factor,
|
|
|
|
($center->[Y] - $self->last_pos->[Y]) * $Slic3r::scaling_factor;
|
2011-10-20 16:11:59 +00:00
|
|
|
|
2011-11-06 19:24:42 +00:00
|
|
|
$self->last_pos($point);
|
2011-10-20 16:11:59 +00:00
|
|
|
return $self->_Gx($gcode, $e, $comment);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub _Gx {
|
|
|
|
my $self = shift;
|
|
|
|
my ($gcode, $e, $comment) = @_;
|
|
|
|
my $dec = $self->dec;
|
|
|
|
|
2011-10-11 14:01:50 +00:00
|
|
|
# determine speed
|
2012-02-25 20:01:00 +00:00
|
|
|
my $speed = ($e ? $self->speed : 'travel');
|
2011-09-26 09:42:08 +00:00
|
|
|
|
2011-10-11 14:01:50 +00:00
|
|
|
# output speed if it's different from last one used
|
|
|
|
# (goal: reduce gcode size)
|
2012-02-25 20:01:00 +00:00
|
|
|
my $append_bridge_off = 0;
|
|
|
|
if ($speed ne $self->last_speed) {
|
|
|
|
if ($speed eq 'bridge') {
|
2012-03-03 21:16:38 +00:00
|
|
|
$gcode = ";_BRIDGE_FAN_START\n$gcode";
|
2012-02-25 20:01:00 +00:00
|
|
|
} elsif ($self->last_speed eq 'bridge') {
|
|
|
|
$append_bridge_off = 1;
|
|
|
|
}
|
2012-06-06 13:43:54 +00:00
|
|
|
|
|
|
|
# apply the speed reduction for print moves on bottom layer
|
|
|
|
my $speed_f = $self->speeds->{$speed};
|
|
|
|
if ($e && $self->layer->id == 0 && $comment !~ /retract/) {
|
2012-06-06 13:52:21 +00:00
|
|
|
$speed_f = $Slic3r::first_layer_speed =~ /^(\d+(?:\.\d+)?)%$/
|
2012-06-06 13:43:54 +00:00
|
|
|
? ($speed_f * $1/100)
|
2012-06-17 17:42:11 +00:00
|
|
|
: $Slic3r::first_layer_speed * 60;
|
2012-06-06 13:43:54 +00:00
|
|
|
}
|
|
|
|
$gcode .= sprintf " F%.${dec}f", $speed_f;
|
2012-02-25 20:01:00 +00:00
|
|
|
$self->last_speed($speed);
|
2011-10-11 14:01:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# output extrusion distance
|
2011-12-01 21:34:21 +00:00
|
|
|
if ($e && $Slic3r::extrusion_axis) {
|
2011-10-11 14:01:50 +00:00
|
|
|
$self->extrusion_distance(0) if $Slic3r::use_relative_e_distances;
|
|
|
|
$self->extrusion_distance($self->extrusion_distance + $e);
|
2011-12-20 14:29:15 +00:00
|
|
|
$self->total_extrusion_length($self->total_extrusion_length + $e);
|
2011-12-01 21:34:21 +00:00
|
|
|
$gcode .= sprintf " %s%.5f", $Slic3r::extrusion_axis, $self->extrusion_distance;
|
2011-10-11 14:01:50 +00:00
|
|
|
}
|
|
|
|
|
2011-12-14 18:49:21 +00:00
|
|
|
$gcode .= sprintf " ; %s", $comment if $comment && $Slic3r::gcode_comments;
|
2012-02-25 20:01:00 +00:00
|
|
|
if ($append_bridge_off) {
|
2012-03-03 21:16:38 +00:00
|
|
|
$gcode .= "\n;_BRIDGE_FAN_END";
|
2012-02-25 20:01:00 +00:00
|
|
|
}
|
2011-09-26 09:42:08 +00:00
|
|
|
return "$gcode\n";
|
|
|
|
}
|
|
|
|
|
2012-02-19 16:02:49 +00:00
|
|
|
sub set_tool {
|
|
|
|
my $self = shift;
|
|
|
|
my ($tool) = @_;
|
|
|
|
|
2012-05-01 12:44:40 +00:00
|
|
|
return $self->retract . sprintf "T%d%s\n", $tool, ($Slic3r::gcode_comments ? ' ; change tool' : '');
|
2012-02-19 16:02:49 +00:00
|
|
|
}
|
|
|
|
|
2012-02-25 20:01:00 +00:00
|
|
|
sub set_fan {
|
|
|
|
my $self = shift;
|
|
|
|
my ($speed, $dont_save) = @_;
|
|
|
|
|
|
|
|
if ($self->last_fan_speed != $speed || $dont_save) {
|
|
|
|
$self->last_fan_speed($speed) if !$dont_save;
|
|
|
|
if ($speed == 0) {
|
|
|
|
return sprintf "M107%s\n", ($Slic3r::gcode_comments ? ' ; disable fan' : '');
|
|
|
|
} else {
|
2012-03-27 08:26:10 +00:00
|
|
|
return sprintf "M106 %s%d%s\n", ($Slic3r::gcode_flavor eq 'mach3' ? 'P' : 'S'),
|
|
|
|
(255 * $speed / 100), ($Slic3r::gcode_comments ? ' ; enable fan' : '');
|
2012-02-25 20:01:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2012-05-20 18:07:39 +00:00
|
|
|
sub set_temperature {
|
|
|
|
my $self = shift;
|
|
|
|
my ($temperature, $wait) = @_;
|
|
|
|
|
|
|
|
return "" if $wait && $Slic3r::gcode_flavor eq 'makerbot';
|
|
|
|
|
|
|
|
my ($code, $comment) = $wait
|
|
|
|
? ('M109', 'wait for temperature to be reached')
|
|
|
|
: ('M104', 'set temperature');
|
|
|
|
return sprintf "$code %s%d ; $comment\n",
|
|
|
|
($Slic3r::gcode_flavor eq 'mach3' ? 'P' : 'S'), $temperature;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub set_bed_temperature {
|
|
|
|
my $self = shift;
|
|
|
|
my ($temperature, $wait) = @_;
|
|
|
|
|
|
|
|
my ($code, $comment) = $wait
|
2012-05-29 07:40:42 +00:00
|
|
|
? (($Slic3r::gcode_flavor eq 'makerbot' ? 'M109' : 'M190'), 'wait for bed temperature to be reached')
|
|
|
|
: ('M140', 'set bed temperature');
|
2012-05-20 18:07:39 +00:00
|
|
|
return sprintf "$code %s%d ; $comment\n",
|
|
|
|
($Slic3r::gcode_flavor eq 'mach3' ? 'P' : 'S'), $temperature;
|
|
|
|
}
|
|
|
|
|
2011-09-26 09:42:08 +00:00
|
|
|
1;
|