Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented simplistic extrusion for constant rate extruders #3734

Closed
14 changes: 12 additions & 2 deletions lib/Slic3r/GUI/Tab.pm
Expand Up @@ -769,7 +769,6 @@ sub _update {
$self->load_config($new_conf);
}
}

if ($config->support_material) {
# Ask only once.
if (! $self->{support_material_overhangs_queried}) {
Expand Down Expand Up @@ -1065,6 +1064,7 @@ sub build {
nozzle_diameter extruder_offset
retract_length retract_lift retract_speed retract_restart_extra retract_before_travel retract_layer_change wipe
retract_length_toolchange retract_restart_extra_toolchange
start_e_gcode stop_e_gcode constant_extruder
));
$self->{config}->set('printer_settings_id', '');

Expand Down Expand Up @@ -1339,7 +1339,7 @@ sub _extruders_count_changed {
}

sub _extruder_options { qw(nozzle_diameter extruder_offset retract_length retract_lift retract_lift_above retract_lift_below retract_speed retract_restart_extra retract_before_travel wipe
retract_layer_change retract_length_toolchange retract_restart_extra_toolchange) }
retract_layer_change retract_length_toolchange retract_restart_extra_toolchange constant_extruder start_e_gcode stop_e_gcode) }

sub _build_extruder_pages {
my $self = shift;
Expand Down Expand Up @@ -1393,6 +1393,12 @@ sub _build_extruder_pages {
$optgroup->append_single_option_line($_, $extruder_idx)
for qw(retract_length_toolchange retract_restart_extra_toolchange);
}
{
my $optgroup = $page->new_optgroup('Custom Extruder');
$optgroup->append_single_option_line('constant_extruder', $extruder_idx);
$optgroup->append_single_option_line('start_e_gcode', $extruder_idx);
$optgroup->append_single_option_line('stop_e_gcode', $extruder_idx);
}
}

# remove extra pages
Expand Down Expand Up @@ -1463,6 +1469,10 @@ sub _update {
# some options only apply when not using firmware retraction
$self->get_field($_, $i)->toggle($retraction && !$config->use_firmware_retraction)
for qw(retract_restart_extra wipe);

# start/stop extrusion gcode only applies if using a constant extruder
$self->get_field($_, $i)->toggle($config->get_at('constant_extruder', $i))
for qw(start_e_gcode stop_e_gcode);

# retraction speed is also used by auto-speed pressure regulator, even when
# user enabled firmware retraction
Expand Down
19 changes: 18 additions & 1 deletion xs/src/libslic3r/Extruder.cpp
Expand Up @@ -78,7 +78,8 @@ Extruder::unretract()
double
Extruder::e_per_mm(double mm3_per_mm) const
{
return mm3_per_mm * this->e_per_mm3;
// return 0 if constant rate extruder in use
return (this->is_constant_rate() ? 0.0 : mm3_per_mm * this->e_per_mm3);
}

double
Expand Down Expand Up @@ -152,5 +153,21 @@ Extruder::retract_restart_extra_toolchange() const
{
return this->config->retract_restart_extra_toolchange.get_at(this->id);
}
std::string
Extruder::start_extrusion_gcode() const
{
return this->config->start_e_gcode.get_at(this->id);
}
std::string
Extruder::stop_extrusion_gcode() const
{
return this->config->stop_e_gcode.get_at(this->id);
}

bool
Extruder::is_constant_rate() const
{
return this->config->constant_extruder.get_at(this->id);
}

}
3 changes: 3 additions & 0 deletions xs/src/libslic3r/Extruder.hpp
Expand Up @@ -36,6 +36,9 @@ class Extruder
double retract_restart_extra() const;
double retract_length_toolchange() const;
double retract_restart_extra_toolchange() const;
std::string start_extrusion_gcode() const;
std::string stop_extrusion_gcode() const;
bool is_constant_rate() const;

private:
GCodeConfig *config;
Expand Down
11 changes: 9 additions & 2 deletions xs/src/libslic3r/GCode.cpp
Expand Up @@ -508,9 +508,12 @@ GCode::_extrude(ExtrusionPath path, std::string description, double speed)
}

// compensate retraction
gcode += this->unretract();
if (!this->writer.extruder()->is_constant_rate())
gcode += this->unretract();

// adjust acceleration
// Don't adjust if using a constant extruder
if (!this->writer.extruder()->is_constant_rate())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this actually needed? User can just leave acceleration settings to 0 and Slic3r will not emit any acceleration command.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted it to be more broadly compatible with print settings.

{
double acceleration;
if (this->config.first_layer_acceleration.value > 0 && this->first_layer) {
Expand Down Expand Up @@ -583,16 +586,20 @@ GCode::_extrude(ExtrusionPath path, std::string description, double speed)
{
std::string comment = this->config.gcode_comments ? description : "";
Lines lines = path.polyline.lines();

if (this->writer.extruder()->is_constant_rate())
gcode += this->writer.extruder()->start_extrusion_gcode() + ";\n";
for (Lines::const_iterator line = lines.begin(); line != lines.end(); ++line) {
const double line_length = line->length() * SCALING_FACTOR;
path_length += line_length;

gcode += this->writer.extrude_to_xy(
this->point_to_gcode(line->b),
e_per_mm * line_length,
comment
);
}
if (this->writer.extruder()->is_constant_rate())
gcode += this->writer.extruder()->stop_extrusion_gcode() + ";\n";
}
if (this->wipe.enable) {
this->wipe.path = path.polyline;
Expand Down
10 changes: 7 additions & 3 deletions xs/src/libslic3r/GCodeWriter.cpp
Expand Up @@ -375,8 +375,10 @@ GCodeWriter::extrude_to_xy(const Pointf &point, double dE, const std::string &co

std::ostringstream gcode;
gcode << "G1 X" << XYZF_NUM(point.x)
<< " Y" << XYZF_NUM(point.y)
<< " " << this->_extrusion_axis << E_NUM(this->_extruder->E);
<< " Y" << XYZF_NUM(point.y);
if (!this->extruder()->is_constant_rate()) // leave off E if constant
gcode << " " << this->_extrusion_axis << E_NUM(this->_extruder->E);

COMMENT(comment);
gcode << "\n";
return gcode.str();
Expand All @@ -393,9 +395,11 @@ GCodeWriter::extrude_to_xyz(const Pointf3 &point, double dE, const std::string &
gcode << "G1 X" << XYZF_NUM(point.x)
<< " Y" << XYZF_NUM(point.y)
<< " Z" << XYZF_NUM(point.z)
<< " " << this->_extrusion_axis << E_NUM(this->_extruder->E);
<< " " << this->_extrusion_axis << E_NUM(this->_extruder->E);

COMMENT(comment);
gcode << "\n";

return gcode.str();
}

Expand Down
38 changes: 37 additions & 1 deletion xs/src/libslic3r/PrintConfig.cpp
Expand Up @@ -116,6 +116,16 @@ PrintConfigDef::PrintConfigDef()
def->cli = "complete-objects!";
def->default_value = new ConfigOptionBool(false);

def = this->add("constant_extruder", coBools);
def->label = "Custom Constant rate extruder";
def->tooltip = "This flag indicates that this extruder is constant rate (pump or solenoid based, not stepper motor). Acceleration control is disabled for print moves with this extruder.";
def->cli = "constant-extruder!";
{
ConfigOptionBools* opt = new ConfigOptionBools();
opt->values.push_back(false);
def->default_value = opt;
}

def = this->add("cooling", coBool);
def->label = "Enable auto cooling";
def->tooltip = "This flag enables the automatic cooling logic that adjusts print speed and fan speed according to layer printing time.";
Expand Down Expand Up @@ -533,7 +543,7 @@ PrintConfigDef::PrintConfigDef()
def = this->add("gcode_flavor", coEnum);
def->label = "G-code flavor";
def->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.";
def->cli = "gcode-flavor=s";
def->cli = "gcode-flavor=s";
def->enum_keys_map = ConfigOptionEnum<GCodeFlavor>::get_enum_values();
def->enum_values.push_back("reprap");
def->enum_values.push_back("repetier");
Expand Down Expand Up @@ -1142,6 +1152,32 @@ PrintConfigDef::PrintConfigDef()
def->height = 120;
def->default_value = new ConfigOptionString("G28 ; home all axes\nG1 Z5 F5000 ; lift nozzle\n");

def = this->add("start_e_gcode", coStrings);
def->label = "Extrusion Start G-code";
def->tooltip = "This gcode snippet is used at the start of printing moves. User is expected to use the appropriate rate (if applicable) for print speed used.";
def->cli = "start-e-gcode=s@";
def->multiline = true;
def->full_width = true;
def->height = 30;
{
ConfigOptionStrings* opt = new ConfigOptionStrings();
opt->values.push_back("M126");
def->default_value = opt;
}

def = this->add("stop_e_gcode", coStrings);
def->label = "Extrusion Stop G-code";
def->tooltip = "This gcode snippet is used at the stop of printing moves. User is expected to use the appropriate rate (if applicable) for print speed used.";
def->cli = "stop-e-gcode=s@";
def->multiline = true;
def->full_width = true;
def->height = 30;
{
ConfigOptionStrings* opt = new ConfigOptionStrings();
opt->values.push_back("M127");
def->default_value = opt;
}

def = this->add("support_material", coBool);
def->label = "Generate support material";
def->category = "Support material";
Expand Down
9 changes: 8 additions & 1 deletion xs/src/libslic3r/PrintConfig.hpp
Expand Up @@ -26,7 +26,7 @@
namespace Slic3r {

enum GCodeFlavor {
gcfRepRap, gcfTeacup, gcfMakerWare, gcfSailfish, gcfMach3, gcfMachinekit, gcfNoExtrusion, gcfSmoothie, gcfRepetier,
gcfRepRap, gcfTeacup, gcfMakerWare, gcfSailfish, gcfMach3, gcfMachinekit, gcfCustomExtrusion, gcfNoExtrusion, gcfSmoothie, gcfRepetier,
};

enum InfillPattern {
Expand All @@ -53,6 +53,7 @@ template<> inline t_config_enum_values ConfigOptionEnum<GCodeFlavor>::get_enum_v
keys_map["sailfish"] = gcfSailfish;
keys_map["mach3"] = gcfMach3;
keys_map["machinekit"] = gcfMachinekit;
keys_map["custom-extrusion"] = gcfCustomExtrusion;
keys_map["no-extrusion"] = gcfNoExtrusion;
keys_map["smoothie"] = gcfSmoothie;
return keys_map;
Expand Down Expand Up @@ -284,6 +285,7 @@ class PrintRegionConfig : public virtual StaticPrintConfig
class GCodeConfig : public virtual StaticPrintConfig
{
public:
ConfigOptionBools constant_extruder;
ConfigOptionString before_layer_gcode;
ConfigOptionString end_gcode;
ConfigOptionString extrusion_axis;
Expand All @@ -305,6 +307,8 @@ class GCodeConfig : public virtual StaticPrintConfig
ConfigOptionFloats retract_restart_extra_toolchange;
ConfigOptionFloats retract_speed;
ConfigOptionString start_gcode;
ConfigOptionStrings start_e_gcode;
ConfigOptionStrings stop_e_gcode;
ConfigOptionString toolchange_gcode;
ConfigOptionFloat travel_speed;
ConfigOptionBool use_firmware_retraction;
Expand All @@ -317,6 +321,7 @@ class GCodeConfig : public virtual StaticPrintConfig
}

virtual ConfigOption* optptr(const t_config_option_key &opt_key, bool create = false) {
OPT_PTR(constant_extruder);
OPT_PTR(before_layer_gcode);
OPT_PTR(end_gcode);
OPT_PTR(extrusion_axis);
Expand All @@ -338,6 +343,8 @@ class GCodeConfig : public virtual StaticPrintConfig
OPT_PTR(retract_restart_extra_toolchange);
OPT_PTR(retract_speed);
OPT_PTR(start_gcode);
OPT_PTR(start_e_gcode);
OPT_PTR(stop_e_gcode);
OPT_PTR(toolchange_gcode);
OPT_PTR(travel_speed);
OPT_PTR(use_firmware_retraction);
Expand Down