2014-10-25 08:42:07 +00:00
|
|
|
|
package Slic3r::GCode::Writer;
|
2014-10-18 15:59:52 +00:00
|
|
|
|
use Moo;
|
|
|
|
|
|
|
|
|
|
use List::Util qw(min max first);
|
2014-10-21 18:16:45 +00:00
|
|
|
|
use Slic3r::Geometry qw(X Y epsilon);
|
2014-10-18 15:59:52 +00:00
|
|
|
|
|
2014-10-25 08:42:07 +00:00
|
|
|
|
has 'config' => (is => 'ro', default => sub { Slic3r::Config::GCode->new });
|
|
|
|
|
has 'multiple_extruders' => (is => 'rw', default => sub { 0 });
|
2014-10-18 15:59:52 +00:00
|
|
|
|
has '_extrusion_axis' => (is => 'rw', default => sub { 'E' });
|
|
|
|
|
has '_extruders' => (is => 'ro', default => sub {{}});
|
2014-10-25 08:42:07 +00:00
|
|
|
|
has '_extruder' => (is => 'rw', reader => 'extruder');
|
2014-10-18 15:59:52 +00:00
|
|
|
|
has '_last_acceleration' => (is => 'rw', default => sub { 0 });
|
|
|
|
|
has '_last_fan_speed' => (is => 'rw', default => sub { 0 });
|
2014-10-21 18:16:45 +00:00
|
|
|
|
has '_lifted' => (is => 'rw', default => sub { 0 });
|
|
|
|
|
has '_pos' => (is => 'rw', default => sub { Slic3r::Pointf3->new });
|
2014-10-18 15:59:52 +00:00
|
|
|
|
|
|
|
|
|
sub apply_print_config {
|
|
|
|
|
my ($self, $print_config) = @_;
|
|
|
|
|
|
2014-10-25 08:42:07 +00:00
|
|
|
|
$self->config->apply_print_config($print_config);
|
2014-10-18 15:59:52 +00:00
|
|
|
|
|
2014-10-25 08:42:07 +00:00
|
|
|
|
if ($self->config->gcode_flavor eq 'mach3') {
|
2014-10-18 15:59:52 +00:00
|
|
|
|
$self->_extrusion_axis('A');
|
2014-10-25 08:42:07 +00:00
|
|
|
|
} elsif ($self->config->gcode_flavor eq 'no-extrusion') {
|
2014-10-18 15:59:52 +00:00
|
|
|
|
$self->_extrusion_axis('');
|
|
|
|
|
} else {
|
2014-10-25 08:42:07 +00:00
|
|
|
|
$self->_extrusion_axis($self->config->extrusion_axis);
|
2014-10-18 15:59:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub set_extruders {
|
|
|
|
|
my ($self, $extruder_ids) = @_;
|
|
|
|
|
|
|
|
|
|
foreach my $i (@$extruder_ids) {
|
|
|
|
|
$self->_extruders->{$i} = my $e = Slic3r::Extruder->new($i, $self->config);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# we enable support for multiple extruder if any extruder greater than 0 is used
|
|
|
|
|
# (even if prints only uses that one) since we need to output Tx commands
|
|
|
|
|
# first extruder has index 0
|
2014-10-25 08:42:07 +00:00
|
|
|
|
$self->multiple_extruders(max(@$extruder_ids) > 0);
|
2014-10-18 15:59:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-28 20:47:09 +00:00
|
|
|
|
sub preamble {
|
|
|
|
|
my ($self) = @_;
|
|
|
|
|
|
|
|
|
|
my $gcode = "";
|
|
|
|
|
|
|
|
|
|
if ($self->config->gcode_flavor ne 'makerware') {
|
|
|
|
|
$gcode .= "G21 ; set units to millimeters\n";
|
|
|
|
|
$gcode .= "G90 ; use absolute coordinates\n";
|
|
|
|
|
}
|
|
|
|
|
if ($self->config->gcode_flavor =~ /^(?:reprap|teacup)$/) {
|
|
|
|
|
if ($self->config->use_relative_e_distances) {
|
|
|
|
|
$gcode .= "M83 ; use relative distances for extrusion\n";
|
|
|
|
|
} else {
|
|
|
|
|
$gcode .= "M82 ; use absolute distances for extrusion\n";
|
|
|
|
|
}
|
|
|
|
|
$gcode .= $self->reset_e(1);
|
|
|
|
|
}
|
|
|
|
|
return $gcode;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-18 15:59:52 +00:00
|
|
|
|
sub set_temperature {
|
|
|
|
|
my ($self, $temperature, $wait, $tool) = @_;
|
|
|
|
|
|
2014-10-25 08:42:07 +00:00
|
|
|
|
return "" if $wait && $self->config->gcode_flavor =~ /^(?:makerware|sailfish)$/;
|
2014-10-18 15:59:52 +00:00
|
|
|
|
|
2014-10-25 08:42:07 +00:00
|
|
|
|
my ($code, $comment) = ($wait && $self->config->gcode_flavor ne 'teacup')
|
2014-10-18 15:59:52 +00:00
|
|
|
|
? ('M109', 'wait for temperature to be reached')
|
|
|
|
|
: ('M104', 'set temperature');
|
|
|
|
|
my $gcode = sprintf "$code %s%d %s; $comment\n",
|
2014-10-25 08:42:07 +00:00
|
|
|
|
($self->config->gcode_flavor eq 'mach3' ? 'P' : 'S'), $temperature,
|
|
|
|
|
(defined $tool && ($self->multiple_extruders || $self->config->gcode_flavor =~ /^(?:makerware|sailfish)$/)) ? "T$tool " : "";
|
2014-10-18 15:59:52 +00:00
|
|
|
|
|
|
|
|
|
$gcode .= "M116 ; wait for temperature to be reached\n"
|
2014-10-25 08:42:07 +00:00
|
|
|
|
if $self->config->gcode_flavor eq 'teacup' && $wait;
|
2014-10-18 15:59:52 +00:00
|
|
|
|
|
|
|
|
|
return $gcode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub set_bed_temperature {
|
|
|
|
|
my ($self, $temperature, $wait) = @_;
|
|
|
|
|
|
2014-10-25 08:42:07 +00:00
|
|
|
|
my ($code, $comment) = ($wait && $self->config->gcode_flavor ne 'teacup')
|
|
|
|
|
? (($self->config->gcode_flavor =~ /^(?:makerware|sailfish)$/ ? 'M109' : 'M190'), 'wait for bed temperature to be reached')
|
2014-10-18 15:59:52 +00:00
|
|
|
|
: ('M140', 'set bed temperature');
|
|
|
|
|
my $gcode = sprintf "$code %s%d ; $comment\n",
|
2014-10-25 08:42:07 +00:00
|
|
|
|
($self->config->gcode_flavor eq 'mach3' ? 'P' : 'S'), $temperature;
|
2014-10-18 15:59:52 +00:00
|
|
|
|
|
|
|
|
|
$gcode .= "M116 ; wait for bed temperature to be reached\n"
|
2014-10-25 08:42:07 +00:00
|
|
|
|
if $self->config->gcode_flavor eq 'teacup' && $wait;
|
2014-10-18 15:59:52 +00:00
|
|
|
|
|
|
|
|
|
return $gcode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub set_fan {
|
|
|
|
|
my ($self, $speed, $dont_save) = @_;
|
|
|
|
|
|
|
|
|
|
if ($self->_last_fan_speed != $speed || $dont_save) {
|
|
|
|
|
$self->_last_fan_speed($speed) if !$dont_save;
|
|
|
|
|
if ($speed == 0) {
|
2014-10-25 08:42:07 +00:00
|
|
|
|
my $code = $self->config->gcode_flavor eq 'teacup'
|
2014-10-18 15:59:52 +00:00
|
|
|
|
? 'M106 S0'
|
2014-10-25 08:42:07 +00:00
|
|
|
|
: $self->config->gcode_flavor =~ /^(?:makerware|sailfish)$/
|
2014-10-18 15:59:52 +00:00
|
|
|
|
? 'M127'
|
|
|
|
|
: 'M107';
|
2014-10-25 08:42:07 +00:00
|
|
|
|
return sprintf "$code%s\n", ($self->config->gcode_comments ? ' ; disable fan' : '');
|
2014-10-18 15:59:52 +00:00
|
|
|
|
} else {
|
2014-10-25 08:42:07 +00:00
|
|
|
|
if ($self->config->gcode_flavor =~ /^(?:makerware|sailfish)$/) {
|
|
|
|
|
return sprintf "M126%s\n", ($self->config->gcode_comments ? ' ; enable fan' : '');
|
2014-10-18 15:59:52 +00:00
|
|
|
|
} else {
|
2014-10-25 08:42:07 +00:00
|
|
|
|
return sprintf "M106 %s%d%s\n", ($self->config->gcode_flavor eq 'mach3' ? 'P' : 'S'),
|
|
|
|
|
(255 * $speed / 100), ($self->config->gcode_comments ? ' ; enable fan' : '');
|
2014-10-18 15:59:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub set_acceleration {
|
|
|
|
|
my ($self, $acceleration) = @_;
|
|
|
|
|
|
|
|
|
|
return "" if !$acceleration || $acceleration == $self->_last_acceleration;
|
|
|
|
|
|
|
|
|
|
$self->_last_acceleration($acceleration);
|
|
|
|
|
return sprintf "M204 S%s%s\n",
|
2014-10-25 08:42:07 +00:00
|
|
|
|
$acceleration, ($self->config->gcode_comments ? ' ; adjust acceleration' : '');
|
2014-10-18 15:59:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-21 18:16:45 +00:00
|
|
|
|
sub update_progress {
|
2014-11-06 20:06:09 +00:00
|
|
|
|
my ($self, $num, $tot, $allow_100) = @_;
|
2014-10-21 18:16:45 +00:00
|
|
|
|
|
2014-10-25 08:42:07 +00:00
|
|
|
|
return "" if $self->config->gcode_flavor !~ /^(?:makerware|sailfish)$/;
|
2014-11-06 20:06:09 +00:00
|
|
|
|
|
|
|
|
|
my $percent = int($num/$tot*100);
|
|
|
|
|
$percent = min($percent, 99) if !$allow_100;
|
2014-10-21 18:16:45 +00:00
|
|
|
|
return sprintf "M73 P%s%s\n",
|
2014-11-06 20:06:09 +00:00
|
|
|
|
$percent,
|
2014-10-21 18:16:45 +00:00
|
|
|
|
$self->_comment('update progress');
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-18 15:59:52 +00:00
|
|
|
|
sub need_toolchange {
|
|
|
|
|
my ($self, $extruder_id) = @_;
|
|
|
|
|
|
|
|
|
|
# return false if this extruder was already selected
|
|
|
|
|
return (!defined $self->_extruder) || ($self->_extruder->id != $extruder_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub set_extruder {
|
|
|
|
|
my ($self, $extruder_id) = @_;
|
|
|
|
|
|
|
|
|
|
return "" if !$self->need_toolchange;
|
2014-10-25 08:42:07 +00:00
|
|
|
|
return $self->toolchange($extruder_id);
|
2014-10-18 15:59:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-25 08:42:07 +00:00
|
|
|
|
sub toolchange {
|
2014-10-18 15:59:52 +00:00
|
|
|
|
my ($self, $extruder_id) = @_;
|
|
|
|
|
|
|
|
|
|
# set the new extruder
|
|
|
|
|
$self->_extruder($self->_extruders->{$extruder_id});
|
|
|
|
|
|
|
|
|
|
# return the toolchange command
|
|
|
|
|
# if we are running a single-extruder setup, just set the extruder and return nothing
|
|
|
|
|
my $gcode = "";
|
2014-10-25 08:42:07 +00:00
|
|
|
|
if ($self->multiple_extruders) {
|
2014-10-18 15:59:52 +00:00
|
|
|
|
$gcode .= sprintf "%s%d%s\n",
|
2014-10-25 08:42:07 +00:00
|
|
|
|
($self->config->gcode_flavor eq 'makerware'
|
2014-10-18 15:59:52 +00:00
|
|
|
|
? 'M135 T'
|
2014-10-25 08:42:07 +00:00
|
|
|
|
: $self->config->gcode_flavor eq 'sailfish'
|
2014-10-18 15:59:52 +00:00
|
|
|
|
? 'M108 T'
|
|
|
|
|
: 'T'),
|
|
|
|
|
$extruder_id,
|
2014-10-25 08:42:07 +00:00
|
|
|
|
($self->config->gcode_comments ? ' ; change extruder' : '');
|
2014-10-18 15:59:52 +00:00
|
|
|
|
|
2014-10-21 18:16:45 +00:00
|
|
|
|
$gcode .= $self->reset_e(1);
|
2014-10-18 15:59:52 +00:00
|
|
|
|
}
|
|
|
|
|
return $gcode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub reset_e {
|
2014-10-21 18:16:45 +00:00
|
|
|
|
my ($self, $force) = @_;
|
2014-10-18 15:59:52 +00:00
|
|
|
|
|
|
|
|
|
return "" if $self->config->gcode_flavor =~ /^(?:mach3|makerware|sailfish)$/;
|
|
|
|
|
|
2014-10-21 18:16:45 +00:00
|
|
|
|
if (defined $self->_extruder) {
|
|
|
|
|
return "" if $self->_extruder->E == 0 && !$force;
|
|
|
|
|
$self->_extruder->set_E(0) if $self->_extruder;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-25 08:42:07 +00:00
|
|
|
|
if ($self->_extrusion_axis ne '' && !$self->config->use_relative_e_distances) {
|
|
|
|
|
return sprintf "G92 %s0%s\n", $self->config->extrusion_axis, ($self->config->gcode_comments ? ' ; reset extrusion distance' : '');
|
2014-10-18 15:59:52 +00:00
|
|
|
|
} else {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-21 18:16:45 +00:00
|
|
|
|
sub _comment {
|
|
|
|
|
my ($self, $comment) = @_;
|
|
|
|
|
|
|
|
|
|
return "" if (!defined $comment) || ($comment eq '') || !$self->config->gcode_comments;
|
|
|
|
|
return " ; $comment";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub set_speed {
|
|
|
|
|
my ($self, $F, $comment) = @_;
|
|
|
|
|
|
|
|
|
|
return sprintf "G1 F%.3f%s\n",
|
|
|
|
|
$F,
|
|
|
|
|
$self->_comment($comment);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub travel_to_xy {
|
|
|
|
|
my ($self, $pointf, $comment) = @_;
|
|
|
|
|
|
|
|
|
|
$self->_pos->set_x($pointf->x);
|
|
|
|
|
$self->_pos->set_y($pointf->y); # ))
|
|
|
|
|
return sprintf "G1 X%.3f Y%.3f F%.3f%s\n",
|
|
|
|
|
@$pointf,
|
2014-10-25 08:42:07 +00:00
|
|
|
|
$self->config->travel_speed*60,
|
2014-10-21 18:16:45 +00:00
|
|
|
|
$self->_comment($comment);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub travel_to_xyz {
|
|
|
|
|
my ($self, $pointf3, $comment) = @_;
|
|
|
|
|
|
|
|
|
|
# If target Z is lower than current Z but higher than nominal Z we
|
|
|
|
|
# don't perform the Z move but we only move in the XY plane and
|
|
|
|
|
# adjust the nominal Z by reducing the lift amount that will be
|
|
|
|
|
# used for unlift.
|
|
|
|
|
if (!$self->will_move_z($pointf3->z)) {
|
|
|
|
|
my $nominal_z = $self->_pos->z - $self->_lifted;
|
|
|
|
|
$self->_lifted($self->_lifted - ($pointf3->z - $nominal_z));
|
|
|
|
|
return $self->travel_to_xy(Slic3r::Pointf->new(@$pointf3[X,Y]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# In all the other cases, we perform an actual XYZ move and cancel
|
|
|
|
|
# the lift.
|
|
|
|
|
$self->_lifted(0);
|
|
|
|
|
return $self->_travel_to_xyz($pointf3, $comment);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub _travel_to_xyz {
|
|
|
|
|
my ($self, $pointf3, $comment) = @_;
|
|
|
|
|
|
|
|
|
|
$self->_pos($pointf3);
|
|
|
|
|
return sprintf "G1 X%.3f Y%.3f Z%.3f F%.3f%s\n",
|
|
|
|
|
@$pointf3,
|
2014-10-25 08:42:07 +00:00
|
|
|
|
$self->config->travel_speed*60,
|
2014-10-21 18:16:45 +00:00
|
|
|
|
$self->_comment($comment);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub travel_to_z {
|
|
|
|
|
my ($self, $z, $comment) = @_;
|
|
|
|
|
|
|
|
|
|
# If target Z is lower than current Z but higher than nominal Z
|
|
|
|
|
# we don't perform the move but we only adjust the nominal Z by
|
|
|
|
|
# reducing the lift amount that will be used for unlift.
|
|
|
|
|
if (!$self->will_move_z($z)) {
|
|
|
|
|
my $nominal_z = $self->_pos->z - $self->_lifted;
|
|
|
|
|
$self->_lifted($self->_lifted - ($z - $nominal_z));
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# In all the other cases, we perform an actual Z move and cancel
|
|
|
|
|
# the lift.
|
|
|
|
|
$self->_lifted(0);
|
|
|
|
|
return $self->_travel_to_z($z, $comment);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub _travel_to_z {
|
|
|
|
|
my ($self, $z, $comment) = @_;
|
|
|
|
|
|
|
|
|
|
$self->_pos->set_z($z);
|
|
|
|
|
return sprintf "G1 Z%.3f F%.3f%s\n",
|
|
|
|
|
$z,
|
2014-10-25 08:42:07 +00:00
|
|
|
|
$self->config->travel_speed*60,
|
2014-10-21 18:16:45 +00:00
|
|
|
|
$self->_comment($comment);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub will_move_z {
|
|
|
|
|
my ($self, $z) = @_;
|
|
|
|
|
|
|
|
|
|
# If target Z is lower than current Z but higher than nominal Z
|
|
|
|
|
# we don't perform an actual Z move.
|
|
|
|
|
if ($self->_lifted > 0) {
|
|
|
|
|
my $nominal_z = $self->_pos->z - $self->_lifted;
|
|
|
|
|
if ($z >= $nominal_z && $z <= $self->_pos->z) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub extrude_to_xy {
|
|
|
|
|
my ($self, $pointf, $dE, $comment) = @_;
|
|
|
|
|
|
|
|
|
|
$self->_pos->set_x($pointf->x);
|
|
|
|
|
$self->_pos->set_y($pointf->y); # ))
|
|
|
|
|
$self->_extruder->extrude($dE);
|
|
|
|
|
return sprintf "G1 X%.3f Y%.3f %s%.5f%s\n",
|
|
|
|
|
@$pointf,
|
|
|
|
|
$self->_extrusion_axis,
|
|
|
|
|
$self->_extruder->E,
|
|
|
|
|
$self->_comment($comment);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub extrude_to_xyz {
|
|
|
|
|
my ($self, $pointf3, $dE, $comment) = @_;
|
|
|
|
|
|
|
|
|
|
$self->_pos($pointf3);
|
|
|
|
|
$self->_lifted(0);
|
|
|
|
|
$self->_extruder->extrude($dE);
|
|
|
|
|
return sprintf "G1 X%.3f Y%.3f Z%.3f %s%.5f%s\n",
|
|
|
|
|
@$pointf3,
|
|
|
|
|
$self->_extrusion_axis,
|
|
|
|
|
$self->_extruder->E,
|
|
|
|
|
$self->_comment($comment);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub retract {
|
|
|
|
|
my ($self) = @_;
|
|
|
|
|
|
|
|
|
|
return $self->_retract(
|
|
|
|
|
$self->_extruder->retract_length,
|
|
|
|
|
$self->_extruder->retract_restart_extra,
|
|
|
|
|
'retract',
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub retract_for_toolchange {
|
|
|
|
|
my ($self) = @_;
|
|
|
|
|
|
|
|
|
|
return $self->_retract(
|
|
|
|
|
$self->_extruder->retract_length_toolchange,
|
|
|
|
|
$self->_extruder->retract_restart_extra_toolchange,
|
|
|
|
|
'retract for toolchange',
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub _retract {
|
|
|
|
|
my ($self, $length, $restart_extra, $comment) = @_;
|
|
|
|
|
|
2014-10-25 08:42:07 +00:00
|
|
|
|
if ($self->config->use_firmware_retraction) {
|
2014-10-21 18:16:45 +00:00
|
|
|
|
return "G10 ; retract\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
my $gcode = "";
|
|
|
|
|
my $dE = $self->_extruder->retract($length, $restart_extra);
|
|
|
|
|
if ($dE != 0) {
|
|
|
|
|
$gcode = sprintf "G1 %s%.5f F%.3f%s\n",
|
|
|
|
|
$self->_extrusion_axis,
|
|
|
|
|
$self->_extruder->E,
|
|
|
|
|
$self->_extruder->retract_speed_mm_min,
|
2014-10-25 08:42:07 +00:00
|
|
|
|
$self->_comment($comment);
|
2014-10-21 18:16:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$gcode .= "M103 ; extruder off\n"
|
2014-10-25 08:42:07 +00:00
|
|
|
|
if $self->config->gcode_flavor eq 'makerware';
|
2014-10-21 18:16:45 +00:00
|
|
|
|
|
|
|
|
|
return $gcode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub unretract {
|
|
|
|
|
my ($self, $comment) = @_;
|
|
|
|
|
|
|
|
|
|
my $gcode = "";
|
|
|
|
|
|
|
|
|
|
$gcode .= "M101 ; extruder on\n"
|
2014-10-25 08:42:07 +00:00
|
|
|
|
if $self->config->gcode_flavor eq 'makerware';
|
2014-10-21 18:16:45 +00:00
|
|
|
|
|
2014-10-25 08:42:07 +00:00
|
|
|
|
if ($self->config->use_firmware_retraction) {
|
2014-10-21 18:16:45 +00:00
|
|
|
|
$gcode .= "G11 ; unretract\n";
|
|
|
|
|
$gcode .= $self->reset_e;
|
|
|
|
|
return $gcode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
my $dE = $self->_extruder->unretract;
|
|
|
|
|
if ($dE != 0) {
|
|
|
|
|
# use G1 instead of G0 because G0 will blend the restart with the previous travel move
|
|
|
|
|
$gcode .= sprintf "G1 %s%.5f F%.3f%s\n",
|
|
|
|
|
$self->_extrusion_axis,
|
|
|
|
|
$self->_extruder->E,
|
|
|
|
|
$self->_extruder->retract_speed_mm_min,
|
|
|
|
|
$self->_comment($comment);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $gcode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# If this method is called more than once before calling unlift(),
|
|
|
|
|
# it will not perform subsequent lifts, even if Z was raised manually
|
|
|
|
|
# (i.e. with travel_to_z()) and thus _lifted was reduced.
|
|
|
|
|
sub lift {
|
|
|
|
|
my ($self) = @_;
|
|
|
|
|
|
2014-10-25 08:42:07 +00:00
|
|
|
|
if ($self->_lifted == 0 && $self->config->retract_lift->[0] > 0) {
|
|
|
|
|
my $to_lift = $self->config->retract_lift->[0];
|
2014-10-21 18:16:45 +00:00
|
|
|
|
$self->_lifted($to_lift);
|
|
|
|
|
return $self->_travel_to_z($self->_pos->z + $to_lift, 'lift Z');
|
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub unlift {
|
|
|
|
|
my ($self) = @_;
|
|
|
|
|
|
|
|
|
|
my $gcode = "";
|
|
|
|
|
if ($self->_lifted > 0) {
|
|
|
|
|
$gcode .= $self->_travel_to_z($self->_pos->z - $self->_lifted, 'restore layer Z');
|
|
|
|
|
$self->_lifted(0);
|
|
|
|
|
}
|
|
|
|
|
return $gcode;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-25 08:42:07 +00:00
|
|
|
|
sub hasmultiple_extruders {
|
2014-10-18 15:59:52 +00:00
|
|
|
|
my ($self) = @_;
|
2014-10-25 08:42:07 +00:00
|
|
|
|
return $self->multiple_extruders;
|
2014-10-18 15:59:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub extruders {
|
|
|
|
|
my ($self) = @_;
|
|
|
|
|
return [ sort { $a->id <=> $b->id } values %{$self->_extruders} ];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
1;
|