Merge branch 'gcode-refactoring'

This commit is contained in:
Alessandro Ranellucci 2014-10-21 20:20:28 +02:00
commit f82e92f498
20 changed files with 747 additions and 363 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

@ -960,6 +960,7 @@ t_optiondef_map PrintConfigDef::def = PrintConfigDef::build_def();
REGISTER_CLASS(DynamicPrintConfig, "Config");
REGISTER_CLASS(PrintObjectConfig, "Config::PrintObject");
REGISTER_CLASS(PrintRegionConfig, "Config::PrintRegion");
REGISTER_CLASS(GCodeConfig, "Config::GCode");
REGISTER_CLASS(PrintConfig, "Config::Print");
REGISTER_CLASS(FullPrintConfig, "Config::Full");
#endif

View file

@ -306,7 +306,62 @@ class PrintRegionConfig : public virtual StaticPrintConfig
};
};
class PrintConfig : public virtual StaticPrintConfig
class GCodeConfig : public virtual StaticPrintConfig
{
public:
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;
GCodeConfig() : 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;
};
ConfigOption* option(const t_config_option_key opt_key, bool create = false) {
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;
return NULL;
};
};
class PrintConfig : public GCodeConfig
{
public:
ConfigOptionBool avoid_crossing_perimeters;
@ -324,7 +379,6 @@ class PrintConfig : public virtual StaticPrintConfig
ConfigOptionFloat extruder_clearance_height;
ConfigOptionFloat extruder_clearance_radius;
ConfigOptionPoints extruder_offset;
ConfigOptionString extrusion_axis;
ConfigOptionFloats extrusion_multiplier;
ConfigOptionBool fan_always_on;
ConfigOptionInt fan_below_layer_time;
@ -336,8 +390,6 @@ class PrintConfig : public virtual StaticPrintConfig
ConfigOptionInts first_layer_temperature;
ConfigOptionBool g0;
ConfigOptionBool gcode_arcs;
ConfigOptionBool gcode_comments;
ConfigOptionEnum<GCodeFlavor> gcode_flavor;
ConfigOptionFloat infill_acceleration;
ConfigOptionBool infill_first;
ConfigOptionString layer_gcode;
@ -355,12 +407,6 @@ class PrintConfig : public virtual StaticPrintConfig
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;
@ -371,14 +417,11 @@ class PrintConfig : public virtual StaticPrintConfig
ConfigOptionInts temperature;
ConfigOptionInt threads;
ConfigOptionString toolchange_gcode;
ConfigOptionFloat travel_speed;
ConfigOptionBool use_firmware_retraction;
ConfigOptionBool use_relative_e_distances;
ConfigOptionFloat vibration_limit;
ConfigOptionBools wipe;
ConfigOptionFloat z_offset;
PrintConfig() : StaticPrintConfig() {
PrintConfig() : GCodeConfig() {
this->avoid_crossing_perimeters.value = false;
this->bed_shape.values.push_back(Pointf(0,0));
this->bed_shape.values.push_back(Pointf(200,0));
@ -398,7 +441,6 @@ class PrintConfig : public virtual StaticPrintConfig
this->extruder_clearance_radius.value = 20;
this->extruder_offset.values.resize(1);
this->extruder_offset.values[0] = Pointf(0,0);
this->extrusion_axis.value = "E";
this->extrusion_multiplier.values.resize(1);
this->extrusion_multiplier.values[0] = 1;
this->fan_always_on.value = false;
@ -415,8 +457,6 @@ class PrintConfig : public virtual StaticPrintConfig
this->first_layer_temperature.values[0] = 200;
this->g0.value = false;
this->gcode_arcs.value = false;
this->gcode_comments.value = false;
this->gcode_flavor.value = gcfRepRap;
this->infill_acceleration.value = 0;
this->infill_first.value = false;
this->layer_gcode.value = "";
@ -436,18 +476,6 @@ class PrintConfig : public virtual StaticPrintConfig
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;
@ -459,9 +487,6 @@ class PrintConfig : public virtual StaticPrintConfig
this->temperature.values[0] = 200;
this->threads.value = 2;
this->toolchange_gcode.value = "";
this->travel_speed.value = 130;
this->use_firmware_retraction.value = false;
this->use_relative_e_distances.value = false;
this->vibration_limit.value = 0;
this->wipe.values.resize(1);
this->wipe.values[0] = false;
@ -484,7 +509,6 @@ class PrintConfig : public virtual StaticPrintConfig
if (opt_key == "extruder_clearance_height") return &this->extruder_clearance_height;
if (opt_key == "extruder_clearance_radius") return &this->extruder_clearance_radius;
if (opt_key == "extruder_offset") return &this->extruder_offset;
if (opt_key == "extrusion_axis") return &this->extrusion_axis;
if (opt_key == "extrusion_multiplier") return &this->extrusion_multiplier;
if (opt_key == "fan_always_on") return &this->fan_always_on;
if (opt_key == "fan_below_layer_time") return &this->fan_below_layer_time;
@ -496,8 +520,6 @@ class PrintConfig : public virtual StaticPrintConfig
if (opt_key == "first_layer_temperature") return &this->first_layer_temperature;
if (opt_key == "g0") return &this->g0;
if (opt_key == "gcode_arcs") return &this->gcode_arcs;
if (opt_key == "gcode_comments") return &this->gcode_comments;
if (opt_key == "gcode_flavor") return &this->gcode_flavor;
if (opt_key == "infill_acceleration") return &this->infill_acceleration;
if (opt_key == "infill_first") return &this->infill_first;
if (opt_key == "layer_gcode") return &this->layer_gcode;
@ -515,12 +537,6 @@ class PrintConfig : public virtual StaticPrintConfig
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;
@ -531,18 +547,20 @@ class PrintConfig : public virtual StaticPrintConfig
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 == "use_firmware_retraction") return &this->use_firmware_retraction;
if (opt_key == "use_relative_e_distances") return &this->use_relative_e_distances;
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;
// look in parent class
ConfigOption* opt;
if ((opt = GCodeConfig::option(opt_key, create)) != NULL) return opt;
return NULL;
};
};
class FullPrintConfig : public PrintObjectConfig, public PrintRegionConfig, public PrintConfig {
class FullPrintConfig : public PrintObjectConfig, public PrintRegionConfig, public PrintConfig
{
public:
ConfigOption* option(const t_config_option_key opt_key, bool create = false) {
ConfigOption* opt;
@ -551,15 +569,6 @@ class FullPrintConfig : public PrintObjectConfig, public PrintRegionConfig, publ
if ((opt = PrintConfig::option(opt_key, create)) != NULL) return opt;
return NULL;
};
std::string get_extrusion_axis() {
if (this->gcode_flavor == gcfMach3) {
return std::string("A");
} else if (this->gcode_flavor == gcfNoExtrusion) {
return std::string("");
}
return this->extrusion_axis;
}
};
}