New G-code flavor for Sailfish (thanks to fros1y for working on it). #826

This commit is contained in:
Alessandro Ranellucci 2013-01-17 14:56:31 +01:00
parent 8001059390
commit 177347137f
6 changed files with 42 additions and 21 deletions

View File

@ -108,7 +108,7 @@ The author of the Silk icon set is Mark James.
(default: 100,100)
--z-offset Additional height in mm to add to vertical coordinates
(+/-, default: 0)
--gcode-flavor The type of G-code to generate (reprap/teacup/makerbot/mach3/no-extrusion,
--gcode-flavor The type of G-code to generate (reprap/teacup/makerbot/sailfish/mach3/no-extrusion,
default: reprap)
--use-relative-e-distances Enable this to get relative E values
--gcode-arcs Use G2/G3 commands for native arcs (experimental, not supported

View File

@ -64,8 +64,8 @@ our $Options = {
tooltip => 'Some G/M-code commands, including temperature control and others, are not universal. Set this option to your printer\'s firmware to get a compatible output. The "No extrusion" flavor prevents Slic3r from exporting any extrusion value at all.',
cli => 'gcode-flavor=s',
type => 'select',
values => [qw(reprap teacup makerbot mach3 no-extrusion)],
labels => ['RepRap (Marlin/Sprinter)', 'Teacup', 'MakerBot', 'Mach3/EMC', 'No extrusion'],
values => [qw(reprap teacup makerbot sailfish mach3 no-extrusion)],
labels => ['RepRap (Marlin/Sprinter)', 'Teacup', 'MakerBot', 'Sailfish', 'Mach3/EMC', 'No extrusion'],
default => 'reprap',
},
'use_relative_e_distances' => {

View File

@ -6,6 +6,7 @@ use Slic3r::ExtrusionPath ':roles';
use Slic3r::Geometry qw(scale unscale scaled_epsilon points_coincide PI X Y B);
has 'multiple_extruders' => (is => 'ro', default => sub {0} );
has 'layer_count' => (is => 'ro', required => 1 );
has 'layer' => (is => 'rw');
has 'move_z_callback' => (is => 'rw');
has 'shift_x' => (is => 'rw', default => sub {0} );
@ -65,6 +66,21 @@ sub set_shift {
$self->shift_y($shift[Y]);
}
sub change_layer {
my $self = shift;
my ($layer) = @_;
$self->layer($layer);
my $gcode = "";
if ($Slic3r::Config->gcode_flavor =~ /^(?:makerbot|sailfish)$/) {
$gcode .= sprintf "M73 P%s%s\n",
int(100 * ($layer->id / ($self->layer_count - 1))),
($Slic3r::Config->gcode_comments ? ' ; update progress' : '');
}
return $gcode;
}
# this method accepts Z in scaled coordinates
sub move_z {
my $self = shift;
@ -452,7 +468,10 @@ sub set_extruder {
# set the new extruder
$self->extruder($extruder);
$gcode .= sprintf "T%d%s\n", $extruder->id, ($Slic3r::Config->gcode_comments ? ' ; change extruder' : '');
$gcode .= sprintf "%s%d%s\n",
($Slic3r::Config->gcode_flavor =~ /^(?:makerbot|sailfish)$/ ? 'M108 T' : 'T'),
$extruder->id,
($Slic3r::Config->gcode_comments ? ' ; change extruder' : '');
$gcode .= $self->reset_e;
return $gcode;
@ -467,11 +486,17 @@ sub set_fan {
if ($speed == 0) {
my $code = $Slic3r::Config->gcode_flavor eq 'teacup'
? 'M106 S0'
: 'M107';
: $Slic3r::Config->gcode_flavor =~ /^(?:makerbot|sailfish)$/
? 'M127'
: 'M107';
return sprintf "$code%s\n", ($Slic3r::Config->gcode_comments ? ' ; disable fan' : '');
} else {
return sprintf "M106 %s%d%s\n", ($Slic3r::Config->gcode_flavor eq 'mach3' ? 'P' : 'S'),
(255 * $speed / 100), ($Slic3r::Config->gcode_comments ? ' ; enable fan' : '');
if ($Slic3r::Config->gcode_flavor =~ /^(?:makerbot|sailfish)$/) {
return sprintf "M126%s\n", ($Slic3r::Config->gcode_comments ? ' ; enable fan' : '');
} else {
return sprintf "M106 %s%d%s\n", ($Slic3r::Config->gcode_flavor eq 'mach3' ? 'P' : 'S'),
(255 * $speed / 100), ($Slic3r::Config->gcode_comments ? ' ; enable fan' : '');
}
}
}
return "";
@ -481,14 +506,14 @@ sub set_temperature {
my $self = shift;
my ($temperature, $wait, $tool) = @_;
return "" if $wait && $Slic3r::Config->gcode_flavor eq 'makerbot';
return "" if $wait && $Slic3r::Config->gcode_flavor =~ /^(?:makerbot|sailfish)$/;
my ($code, $comment) = ($wait && $Slic3r::Config->gcode_flavor ne 'teacup')
? ('M109', 'wait for temperature to be reached')
: ('M104', 'set temperature');
my $gcode = sprintf "$code %s%d %s; $comment\n",
($Slic3r::Config->gcode_flavor eq 'mach3' ? 'P' : 'S'), $temperature,
(defined $tool && $self->multiple_extruders) ? "T$tool " : "";
(defined $tool && ($self->multiple_extruders || $Slic3r::Config->gcode_flavor =~ /^(?:makerbot|sailfish)$/)) ? "T$tool " : "";
$gcode .= "M116 ; wait for temperature to be reached\n"
if $Slic3r::Config->gcode_flavor eq 'teacup' && $wait;
@ -501,8 +526,7 @@ sub set_bed_temperature {
my ($temperature, $wait) = @_;
my ($code, $comment) = ($wait && $Slic3r::Config->gcode_flavor ne 'teacup')
? (($Slic3r::Config->gcode_flavor eq 'makerbot' ? 'M109'
: 'M190'), 'wait for bed temperature to be reached')
? (($Slic3r::Config->gcode_flavor =~ /^(?:makerbot|sailfish)$/ ? 'M109' : 'M190'), 'wait for bed temperature to be reached')
: ('M140', 'set bed temperature');
my $gcode = sprintf "$code %s%d ; $comment\n",
($Slic3r::Config->gcode_flavor eq 'mach3' ? 'P' : 'S'), $temperature;

View File

@ -242,11 +242,7 @@ sub object_copies {
sub layer_count {
my $self = shift;
my $count = 0;
foreach my $object (@{$self->objects}) {
$count = @{$object->layers} if @{$object->layers} > $count;
}
return $count;
return max(map { scalar @{$_->layers} } @{$self->objects});
}
sub regions_count {
@ -675,7 +671,8 @@ sub write_gcode {
# set up our extruder object
my $gcodegen = Slic3r::GCode->new(
multiple_extruders => (@{$self->extruders} > 1),
multiple_extruders => (@{$self->extruders} > 1),
layer_count => $self->layer_count,
);
my $min_print_speed = 60 * $Slic3r::Config->min_print_speed;
my $dec = $gcodegen->dec;
@ -700,7 +697,7 @@ sub write_gcode {
print $fh "G21 ; set units to millimeters\n";
if ($Slic3r::Config->gcode_flavor =~ /^(?:reprap|teacup)$/) {
printf $fh $gcodegen->reset_e;
if ($Slic3r::Config->gcode_flavor =~ /^(?:reprap|makerbot)$/) {
if ($Slic3r::Config->gcode_flavor =~ /^(?:reprap|makerbot|sailfish)$/) {
if ($Slic3r::Config->use_relative_e_distances) {
print $fh "M83 ; use relative distances for extrusion\n";
} else {
@ -733,7 +730,7 @@ sub write_gcode {
}
# set new layer, but don't move Z as support material interfaces may need an intermediate one
$gcodegen->layer($self->objects->[$object_copies->[0][0]]->layers->[$layer_id]);
$gcode .= $gcodegen->change_layer($self->objects->[$object_copies->[0][0]]->layers->[$layer_id]);
$gcodegen->elapsed_time(0);
# prepare callback to call as soon as a Z command is generated

View File

@ -156,7 +156,7 @@ $j
(default: $config->{print_center}->[0],$config->{print_center}->[1])
--z-offset Additional height in mm to add to vertical coordinates
(+/-, default: $config->{z_offset})
--gcode-flavor The type of G-code to generate (reprap/teacup/makerbot/mach3/no-extrusion,
--gcode-flavor The type of G-code to generate (reprap/teacup/makerbot/sailfish/mach3/no-extrusion,
default: $config->{gcode_flavor})
--use-relative-e-distances Enable this to get relative E values
--gcode-arcs Use G2/G3 commands for native arcs (experimental, not supported

View File

@ -22,7 +22,7 @@ _arguments -S \
'*--nozzle-diameter[specify nozzle diameter]:nozzle diameter in mm' \
'--print-center[specify print center coordinates]:print center coordinates in mm,mm' \
'--z-offset[specify Z-axis offset]:Z-axis offset in mm' \
'--gcode-flavor[specify the type of G-code to generate]:G-code flavor:(reprap teacup makerbot mach3 no-extrusion)' \
'--gcode-flavor[specify the type of G-code to generate]:G-code flavor:(reprap teacup makerbot sailfish mach3 no-extrusion)' \
'(--use-relative-e-distances --no-use-relative-e-distances)'--{no-,}use-relative-e-distances'[disable/enable relative E values]' \
'--extrusion-axis[specify letter associated with the extrusion axis]:extrusion axis letter' \
'(--gcode-arcs --no-gcode-arcs)'--{no-,}gcode-arcs'[disable/enable G2/G3 commands for native arcs]' \