Refactoring: moved most of the low-level G-code to the Slic3r::GCode::Base class. Cleanup of the retraction and wipe logic.

This commit is contained in:
Alessandro Ranellucci 2014-10-21 20:16:45 +02:00
parent 33edda0a69
commit 167df0ab87
11 changed files with 403 additions and 177 deletions

View file

@ -21,13 +21,49 @@ Extruder::reset()
double
Extruder::extrude(double dE)
{
if (this->config->use_relative_e_distances) {
// in case of relative E distances we always reset to 0 before any output
if (this->config->use_relative_e_distances)
this->E = 0;
}
this->E += dE;
this->absolute_E += dE;
return this->E;
return dE;
}
/* This method makes sure the extruder is retracted by the specified amount
of filament and returns the amount of filament retracted.
If the extruder is already retracted by the same or a greater amount,
this method is a no-op.
The restart_extra argument sets the extra length to be used for
unretraction. If we're actually performing a retraction, any restart_extra
value supplied will overwrite the previous one if any. */
double
Extruder::retract(double length, double restart_extra)
{
// in case of relative E distances we always reset to 0 before any output
if (this->config->use_relative_e_distances)
this->E = 0;
double to_retract = length - this->retracted;
if (to_retract > 0) {
this->E -= to_retract;
this->absolute_E -= to_retract;
this->retracted += to_retract;
this->restart_extra = restart_extra;
return to_retract;
} else {
return 0;
}
}
double
Extruder::unretract()
{
double dE = this->retracted + this->restart_extra;
this->extrude(dE);
this->retracted = 0;
this->restart_extra = 0;
return dE;
}
Pointf

View file

@ -14,7 +14,8 @@ class Extruder
virtual ~Extruder() {}
void reset();
double extrude(double dE);
double retract(double length, double restart_extra);
double unretract();
Pointf extruder_offset() const;
double nozzle_diameter() const;

View file

@ -123,7 +123,11 @@ ExtrusionPath::gcode(Extruder* extruder, double e, double F,
const double line_length = line_it->length() * SCALING_FACTOR;
// calculate extrusion length for this line
double E = (e == 0) ? 0 : extruder->extrude(e * line_length);
double E = 0;
if (e > 0) {
extruder->extrude(e * line_length);
E = extruder->E;
}
// compose G-code line

View file

@ -312,6 +312,13 @@ class GCodeConfig : public virtual StaticPrintConfig
ConfigOptionString extrusion_axis;
ConfigOptionBool gcode_comments;
ConfigOptionEnum<GCodeFlavor> gcode_flavor;
ConfigOptionFloats retract_length;
ConfigOptionFloats retract_length_toolchange;
ConfigOptionFloats retract_lift;
ConfigOptionFloats retract_restart_extra;
ConfigOptionFloats retract_restart_extra_toolchange;
ConfigOptionInts retract_speed;
ConfigOptionFloat travel_speed;
ConfigOptionBool use_firmware_retraction;
ConfigOptionBool use_relative_e_distances;
@ -319,6 +326,19 @@ class GCodeConfig : public virtual StaticPrintConfig
this->extrusion_axis.value = "E";
this->gcode_comments.value = false;
this->gcode_flavor.value = gcfRepRap;
this->retract_length.values.resize(1);
this->retract_length.values[0] = 1;
this->retract_length_toolchange.values.resize(1);
this->retract_length_toolchange.values[0] = 10;
this->retract_lift.values.resize(1);
this->retract_lift.values[0] = 0;
this->retract_restart_extra.values.resize(1);
this->retract_restart_extra.values[0] = 0;
this->retract_restart_extra_toolchange.values.resize(1);
this->retract_restart_extra_toolchange.values[0] = 0;
this->retract_speed.values.resize(1);
this->retract_speed.values[0] = 30;
this->travel_speed.value = 130;
this->use_firmware_retraction.value = false;
this->use_relative_e_distances.value = false;
};
@ -327,6 +347,13 @@ class GCodeConfig : public virtual StaticPrintConfig
if (opt_key == "extrusion_axis") return &this->extrusion_axis;
if (opt_key == "gcode_comments") return &this->gcode_comments;
if (opt_key == "gcode_flavor") return &this->gcode_flavor;
if (opt_key == "retract_length") return &this->retract_length;
if (opt_key == "retract_length_toolchange") return &this->retract_length_toolchange;
if (opt_key == "retract_lift") return &this->retract_lift;
if (opt_key == "retract_restart_extra") return &this->retract_restart_extra;
if (opt_key == "retract_restart_extra_toolchange") return &this->retract_restart_extra_toolchange;
if (opt_key == "retract_speed") return &this->retract_speed;
if (opt_key == "travel_speed") return &this->travel_speed;
if (opt_key == "use_firmware_retraction") return &this->use_firmware_retraction;
if (opt_key == "use_relative_e_distances") return &this->use_relative_e_distances;
@ -380,12 +407,6 @@ class PrintConfig : public GCodeConfig
ConfigOptionFloat resolution;
ConfigOptionFloats retract_before_travel;
ConfigOptionBools retract_layer_change;
ConfigOptionFloats retract_length;
ConfigOptionFloats retract_length_toolchange;
ConfigOptionFloats retract_lift;
ConfigOptionFloats retract_restart_extra;
ConfigOptionFloats retract_restart_extra_toolchange;
ConfigOptionInts retract_speed;
ConfigOptionFloat skirt_distance;
ConfigOptionInt skirt_height;
ConfigOptionInt skirts;
@ -396,7 +417,6 @@ class PrintConfig : public GCodeConfig
ConfigOptionInts temperature;
ConfigOptionInt threads;
ConfigOptionString toolchange_gcode;
ConfigOptionFloat travel_speed;
ConfigOptionFloat vibration_limit;
ConfigOptionBools wipe;
ConfigOptionFloat z_offset;
@ -456,18 +476,6 @@ class PrintConfig : public GCodeConfig
this->retract_before_travel.values[0] = 2;
this->retract_layer_change.values.resize(1);
this->retract_layer_change.values[0] = true;
this->retract_length.values.resize(1);
this->retract_length.values[0] = 1;
this->retract_length_toolchange.values.resize(1);
this->retract_length_toolchange.values[0] = 10;
this->retract_lift.values.resize(1);
this->retract_lift.values[0] = 0;
this->retract_restart_extra.values.resize(1);
this->retract_restart_extra.values[0] = 0;
this->retract_restart_extra_toolchange.values.resize(1);
this->retract_restart_extra_toolchange.values[0] = 0;
this->retract_speed.values.resize(1);
this->retract_speed.values[0] = 30;
this->skirt_distance.value = 6;
this->skirt_height.value = 1;
this->skirts.value = 1;
@ -479,7 +487,6 @@ class PrintConfig : public GCodeConfig
this->temperature.values[0] = 200;
this->threads.value = 2;
this->toolchange_gcode.value = "";
this->travel_speed.value = 130;
this->vibration_limit.value = 0;
this->wipe.values.resize(1);
this->wipe.values[0] = false;
@ -530,12 +537,6 @@ class PrintConfig : public GCodeConfig
if (opt_key == "resolution") return &this->resolution;
if (opt_key == "retract_before_travel") return &this->retract_before_travel;
if (opt_key == "retract_layer_change") return &this->retract_layer_change;
if (opt_key == "retract_length") return &this->retract_length;
if (opt_key == "retract_length_toolchange") return &this->retract_length_toolchange;
if (opt_key == "retract_lift") return &this->retract_lift;
if (opt_key == "retract_restart_extra") return &this->retract_restart_extra;
if (opt_key == "retract_restart_extra_toolchange") return &this->retract_restart_extra_toolchange;
if (opt_key == "retract_speed") return &this->retract_speed;
if (opt_key == "skirt_distance") return &this->skirt_distance;
if (opt_key == "skirt_height") return &this->skirt_height;
if (opt_key == "skirts") return &this->skirts;
@ -546,7 +547,6 @@ class PrintConfig : public GCodeConfig
if (opt_key == "temperature") return &this->temperature;
if (opt_key == "threads") return &this->threads;
if (opt_key == "toolchange_gcode") return &this->toolchange_gcode;
if (opt_key == "travel_speed") return &this->travel_speed;
if (opt_key == "vibration_limit") return &this->vibration_limit;
if (opt_key == "wipe") return &this->wipe;
if (opt_key == "z_offset") return &this->z_offset;