From d35226b889f5e51f928ce4adb088c2bac7c6d817 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20R=C3=B6ssler?= Date: Wed, 7 Jan 2015 21:20:58 +0100 Subject: [PATCH 1/6] added support Machinekit flavour GCode --- README.md | 6 +++--- slic3r.pl | 2 +- utils/zsh/functions/_slic3r | 2 +- xs/src/libslic3r/PrintConfig.cpp | 2 ++ xs/src/libslic3r/PrintConfig.hpp | 5 +++-- xs/t/15_config.t | 4 +++- 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index ee97e5b65..7095f56e2 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Slic3r [![Build Status](https://travis-ci.org/alexrj/Slic3r.png?branch=master)]( Slic3r takes 3D models (STL, OBJ, AMF) and converts them into G-code instructions for 3D printers. It's compatible with any modern printer based on the RepRap toolchain, including all those based on the Marlin, Sprinter and Repetier firmware. It also works -with Mach3 and LinuxCNC controllers. +with Mach3, LinuxCNC and Machinekit controllers. See the [project homepage](http://slic3r.org/) at slic3r.org and the [manual](http://manual.slic3r.org/) for more information. @@ -30,7 +30,7 @@ Key features are: * **multi-platform** (Linux/Mac/Win) and packaged as standalone-app with no dependencies required * complete **command-line interface** to use it with no GUI * multi-material **(multiple extruders)** object printing -* multiple G-code flavors supported (RepRap, Makerbot, Mach3 etc.) +* multiple G-code flavors supported (RepRap, Makerbot, Mach3, Machinekit etc.) * ability to plate **multiple objects having distinct print settings** * **multithread** processing * **STL auto-repair** (tolerance for broken models) @@ -130,7 +130,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/makerware/sailfish/mach3/no-extrusion, + --gcode-flavor The type of G-code to generate (reprap/teacup/makerware/sailfish/mach3/machinekit/no-extrusion, default: reprap) --use-relative-e-distances Enable this to get relative E values (default: no) --use-firmware-retraction Enable firmware-controlled retraction using G10/G11 (default: no) diff --git a/slic3r.pl b/slic3r.pl index 84590b197..810d61bf3 100755 --- a/slic3r.pl +++ b/slic3r.pl @@ -282,7 +282,7 @@ $j (default: 100,100) --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/makerware/sailfish/mach3/no-extrusion, + --gcode-flavor The type of G-code to generate (reprap/teacup/makerware/sailfish/mach3/machinekit/no-extrusion, default: $config->{gcode_flavor}) --use-relative-e-distances Enable this to get relative E values (default: no) --use-firmware-retraction Enable firmware-controlled retraction using G10/G11 (default: no) diff --git a/utils/zsh/functions/_slic3r b/utils/zsh/functions/_slic3r index 41a36963f..df1cecb03 100644 --- a/utils/zsh/functions/_slic3r +++ b/utils/zsh/functions/_slic3r @@ -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 makerware sailfish mach3 no-extrusion)' \ + '--gcode-flavor[specify the type of G-code to generate]:G-code flavor:(reprap teacup makerware sailfish mach3 machinekit 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]' \ diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index c7afe9fbc..f11d64dc2 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -380,12 +380,14 @@ PrintConfigDef::build_def() { Options["gcode_flavor"].enum_values.push_back("makerware"); Options["gcode_flavor"].enum_values.push_back("sailfish"); Options["gcode_flavor"].enum_values.push_back("mach3"); + Options["gcode_flavor"].enum_values.push_back("machinekit"); Options["gcode_flavor"].enum_values.push_back("no-extrusion"); Options["gcode_flavor"].enum_labels.push_back("RepRap (Marlin/Sprinter/Repetier)"); Options["gcode_flavor"].enum_labels.push_back("Teacup"); Options["gcode_flavor"].enum_labels.push_back("MakerWare (MakerBot)"); Options["gcode_flavor"].enum_labels.push_back("Sailfish (MakerBot)"); Options["gcode_flavor"].enum_labels.push_back("Mach3/LinuxCNC"); + Options["gcode_flavor"].enum_labels.push_back("Machinekit"); Options["gcode_flavor"].enum_labels.push_back("No extrusion"); Options["infill_acceleration"].type = coFloat; diff --git a/xs/src/libslic3r/PrintConfig.hpp b/xs/src/libslic3r/PrintConfig.hpp index 19ae75928..869ae5caa 100644 --- a/xs/src/libslic3r/PrintConfig.hpp +++ b/xs/src/libslic3r/PrintConfig.hpp @@ -6,7 +6,7 @@ namespace Slic3r { enum GCodeFlavor { - gcfRepRap, gcfTeacup, gcfMakerWare, gcfSailfish, gcfMach3, gcfNoExtrusion, + gcfRepRap, gcfTeacup, gcfMakerWare, gcfSailfish, gcfMach3, gcfMachinekit, gcfNoExtrusion, }; enum InfillPattern { @@ -29,6 +29,7 @@ template<> inline t_config_enum_values ConfigOptionEnum::get_enum_v keys_map["makerware"] = gcfMakerWare; keys_map["sailfish"] = gcfSailfish; keys_map["mach3"] = gcfMach3; + keys_map["machinekit"] = gcfMachinekit; keys_map["no-extrusion"] = gcfNoExtrusion; return keys_map; } @@ -410,7 +411,7 @@ class GCodeConfig : public virtual StaticPrintConfig std::string get_extrusion_axis() const { - if (this->gcode_flavor.value == gcfMach3) { + if ((this->gcode_flavor.value == gcfMach3) || (this->gcode_flavor.value == gcfMachinekit)) { return "A"; } else if (this->gcode_flavor.value == gcfNoExtrusion) { return ""; diff --git a/xs/t/15_config.t b/xs/t/15_config.t index e051d9a86..43bfe501c 100644 --- a/xs/t/15_config.t +++ b/xs/t/15_config.t @@ -4,7 +4,7 @@ use strict; use warnings; use Slic3r::XS; -use Test::More tests => 108; +use Test::More tests => 110; foreach my $config (Slic3r::Config->new, Slic3r::Config::Full->new) { $config->set('layer_height', 0.3); @@ -51,6 +51,8 @@ foreach my $config (Slic3r::Config->new, Slic3r::Config::Full->new) { is $config->serialize('gcode_flavor'), 'teacup', 'serialize enum'; $config->set_deserialize('gcode_flavor', 'mach3'); is $config->get('gcode_flavor'), 'mach3', 'deserialize enum (gcode_flavor)'; + $config->set_deserialize('gcode_flavor', 'machinekit'); + is $config->get('gcode_flavor'), 'machinekit', 'deserialize enum (gcode_flavor)'; $config->set_deserialize('fill_pattern', 'line'); is $config->get('fill_pattern'), 'line', 'deserialize enum (fill_pattern)'; From 32eff40422b5d066c5e46f28cd08b6db665fb6c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20R=C3=B6ssler?= Date: Fri, 6 Feb 2015 19:16:57 +0100 Subject: [PATCH 2/6] added retract and unretract command for Machinekit flavour --- xs/src/libslic3r/GCodeWriter.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/xs/src/libslic3r/GCodeWriter.cpp b/xs/src/libslic3r/GCodeWriter.cpp index 9aa7616a6..f1176d617 100644 --- a/xs/src/libslic3r/GCodeWriter.cpp +++ b/xs/src/libslic3r/GCodeWriter.cpp @@ -434,7 +434,10 @@ GCodeWriter::_retract(double length, double restart_extra, const std::string &co double dE = this->_extruder->retract(length, restart_extra); if (dE != 0) { if (this->config.use_firmware_retraction) { - gcode << "G10 ; retract\n"; + if (FLAVOR_IS(gcfMachinekit)) + gcode << "G22 ; retract\n"; + else + gcode << "G10 ; retract\n"; } else { gcode << "G1 " << this->_extrusion_axis << E_NUM(this->_extruder->E) << " F" << this->_extruder->retract_speed_mm_min; @@ -460,7 +463,10 @@ GCodeWriter::unretract() double dE = this->_extruder->unretract(); if (dE != 0) { if (this->config.use_firmware_retraction) { - gcode << "G11 ; unretract\n"; + if (FLAVOR_IS(gcfMachinekit)) + gcode << "G23 ; unretract\n"; + else + gcode << "G11 ; unretract\n"; gcode << this->reset_e(); } else { // use G1 instead of G0 because G0 will blend the restart with the previous travel move @@ -509,4 +515,4 @@ GCodeWriter::get_position() const REGISTER_CLASS(GCodeWriter, "GCode::Writer"); #endif -} \ No newline at end of file +} From d6feec808cf1f3512039eb01f4303b489cadb426 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20R=C3=B6ssler?= Date: Sat, 7 Feb 2015 12:35:35 +0100 Subject: [PATCH 3/6] enabling firmware retraction for Machinekit in GUI --- lib/Slic3r/Config.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Slic3r/Config.pm b/lib/Slic3r/Config.pm index e2739c421..bc0455889 100644 --- a/lib/Slic3r/Config.pm +++ b/lib/Slic3r/Config.pm @@ -243,7 +243,7 @@ sub validate { if !first { $_ eq $self->gcode_flavor } @{$Options->{gcode_flavor}{values}}; die "--use-firmware-retraction is only supported by Marlin firmware\n" - if $self->use_firmware_retraction && $self->gcode_flavor ne 'reprap'; + if $self->use_firmware_retraction && $self->gcode_flavor ne 'reprap' && $self->gcode_flavor ne 'machinekit'; die "--use-firmware-retraction is not compatible with --wipe\n" if $self->use_firmware_retraction && first {$_} @{$self->wipe}; From f2fa8cb63fa9ef6f8e307ccda36fa3e53e74eeed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20R=C3=B6ssler?= Date: Sat, 7 Feb 2015 12:36:29 +0100 Subject: [PATCH 4/6] added end_program() function to GCodeWriter --- xs/src/libslic3r/GCodeWriter.cpp | 9 +++++++++ xs/src/libslic3r/GCodeWriter.hpp | 1 + xs/xsp/GCodeWriter.xsp | 1 + 3 files changed, 11 insertions(+) diff --git a/xs/src/libslic3r/GCodeWriter.cpp b/xs/src/libslic3r/GCodeWriter.cpp index f1176d617..624f11c57 100644 --- a/xs/src/libslic3r/GCodeWriter.cpp +++ b/xs/src/libslic3r/GCodeWriter.cpp @@ -511,6 +511,15 @@ GCodeWriter::get_position() const return this->_pos; } +std::string +GCodeWriter::end_program() +{ + std::ostringstream gcode; + if (FLAVOR_IS(gcfMachinekit)) + gcode << "M2 ; end of program\n"; + return gcode.str(); +} + #ifdef SLIC3RXS REGISTER_CLASS(GCodeWriter, "GCode::Writer"); #endif diff --git a/xs/src/libslic3r/GCodeWriter.hpp b/xs/src/libslic3r/GCodeWriter.hpp index 03de197d1..6854f02e0 100644 --- a/xs/src/libslic3r/GCodeWriter.hpp +++ b/xs/src/libslic3r/GCodeWriter.hpp @@ -46,6 +46,7 @@ class GCodeWriter { std::string lift(); std::string unlift(); Pointf3 get_position() const; + std::string end_program(); private: std::string _extrusion_axis; diff --git a/xs/xsp/GCodeWriter.xsp b/xs/xsp/GCodeWriter.xsp index a76c0e55f..d2f1e00d4 100644 --- a/xs/xsp/GCodeWriter.xsp +++ b/xs/xsp/GCodeWriter.xsp @@ -45,6 +45,7 @@ std::string lift(); std::string unlift(); Clone get_position() const; + std::string end_program(); %{ SV* From cc83e9f06d3d236e5c5599783f5ad3cfd4d149e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20R=C3=B6ssler?= Date: Sat, 7 Feb 2015 12:37:00 +0100 Subject: [PATCH 5/6] using end_program() function in GCode output --- lib/Slic3r/Print/GCode.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Slic3r/Print/GCode.pm b/lib/Slic3r/Print/GCode.pm index b2c96d122..47f56ef45 100644 --- a/lib/Slic3r/Print/GCode.pm +++ b/lib/Slic3r/Print/GCode.pm @@ -249,6 +249,7 @@ sub export { print $fh $gcodegen->writer->set_fan(0); printf $fh "%s\n", $gcodegen->placeholder_parser->process($self->config->end_gcode); print $fh $gcodegen->writer->update_progress($gcodegen->layer_count, $gcodegen->layer_count, 1); # 100% + print $fh $gcodegen->writer->end_program(); $self->print->total_used_filament(0); $self->print->total_extruded_volume(0); From cef149485284ceefee77c3ece3db0728f693bfb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20R=C3=B6ssler?= Date: Tue, 10 Feb 2015 14:22:23 +0100 Subject: [PATCH 6/6] Switched to P parameter instead of S for Machinekit flavour MCode commands --- xs/src/libslic3r/GCodeWriter.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xs/src/libslic3r/GCodeWriter.cpp b/xs/src/libslic3r/GCodeWriter.cpp index 624f11c57..cacedd427 100644 --- a/xs/src/libslic3r/GCodeWriter.cpp +++ b/xs/src/libslic3r/GCodeWriter.cpp @@ -83,7 +83,7 @@ GCodeWriter::set_temperature(unsigned int temperature, bool wait, int tool) std::ostringstream gcode; gcode << code << " "; - if (FLAVOR_IS(gcfMach3)) { + if (FLAVOR_IS(gcfMach3) || FLAVOR_IS(gcfMachinekit)) { gcode << "P"; } else { gcode << "S"; @@ -118,7 +118,7 @@ GCodeWriter::set_bed_temperature(unsigned int temperature, bool wait) std::ostringstream gcode; gcode << code << " "; - if (FLAVOR_IS(gcfMach3)) { + if (FLAVOR_IS(gcfMach3) || FLAVOR_IS(gcfMachinekit)) { gcode << "P"; } else { gcode << "S"; @@ -153,7 +153,7 @@ GCodeWriter::set_fan(unsigned int speed, bool dont_save) gcode << "M126"; } else { gcode << "M106 "; - if (FLAVOR_IS(gcfMach3)) { + if (FLAVOR_IS(gcfMach3) || FLAVOR_IS(gcfMachinekit)) { gcode << "P"; } else { gcode << "S";