Add weight/cost output to gcode. On the way to #647

This commit is contained in:
Joseph Lenox 2017-01-15 23:56:01 -06:00 committed by bubnikv
parent bbd63616b1
commit 3846d9e734
7 changed files with 63 additions and 1 deletions

View File

@ -962,7 +962,7 @@ sub build {
my $self = shift;
$self->init_config_options(qw(
filament_colour filament_diameter filament_notes filament_max_volumetric_speed extrusion_multiplier
filament_colour filament_diameter filament_notes filament_max_volumetric_speed extrusion_multiplier filament_density filament_cost
temperature first_layer_temperature bed_temperature first_layer_bed_temperature
fan_always_on cooling
min_fan_speed max_fan_speed bridge_fan_speed disable_fan_first_layers
@ -977,6 +977,8 @@ sub build {
$optgroup->append_single_option_line('filament_colour', 0);
$optgroup->append_single_option_line('filament_diameter', 0);
$optgroup->append_single_option_line('extrusion_multiplier', 0);
$optgroup->append_single_option_line('filament_density', 0);
$optgroup->append_single_option_line('filament_cost', 0);
}
{

View File

@ -321,17 +321,33 @@ sub export {
$self->print->clear_filament_stats;
$self->print->total_used_filament(0);
$self->print->total_extruded_volume(0);
my $total_filament_weight = 0.0;
my $total_filament_cost = 0.0;
foreach my $extruder (@{$gcodegen->writer->extruders}) {
my $used_filament = $extruder->used_filament;
my $extruded_volume = $extruder->extruded_volume;
my $filament_weight = $extruded_volume * $extruder->filament_density;
my $filament_cost = $filament_weight * ($extruder->filament_cost / 1000);
$self->print->set_filament_stats($extruder->id, $used_filament);
printf $fh "; filament used = %.1fmm (%.1fcm3)\n",
$used_filament, $extruded_volume/1000;
if ($filament_weight > 0) {
$total_filament_weight += $filament_weight;
printf $fh "; filament used = %.1fg\n",
$filament_weight;
if ($filament_cost > 0) {
$total_filament_cost += $filament_cost;
printf $fh "; filament cost = %.1f\n",
$filament_cost;
}
}
$self->print->total_used_filament($self->print->total_used_filament + $used_filament);
$self->print->total_extruded_volume($self->print->total_extruded_volume + $extruded_volume);
}
printf $fh "; total filament cost = %.1f\n",
$total_filament_cost;
# append full config
print $fh "\n";

View File

@ -111,6 +111,18 @@ Extruder::filament_diameter() const
return this->config->filament_diameter.get_at(this->id);
}
double
Extruder::filament_density() const
{
return this->config->filament_density.get_at(this->id);
}
double
Extruder::filament_cost() const
{
return this->config->filament_cost.get_at(this->id);
}
double
Extruder::extrusion_multiplier() const
{

View File

@ -29,6 +29,8 @@ class Extruder
double used_filament() const;
double filament_diameter() const;
double filament_density() const;
double filament_cost() const;
double extrusion_multiplier() const;
double retract_length() const;
double retract_lift() const;

View File

@ -335,6 +335,30 @@ PrintConfigDef::PrintConfigDef()
opt->values.push_back(3);
def->default_value = opt;
}
def = this->add("filament_density", coFloats);
def->label = "Density";
def->tooltip = "Enter your filament density here. This is only for statistical information. A decent way is to weigh a known length of filament and compute the ratio of the length to volume.";
def->sidetext = "g/mm^3";
def->cli = "filament-density=f@";
def->min = 0;
{
ConfigOptionFloats* opt = new ConfigOptionFloats();
opt->values.push_back(0);
def->default_value = opt;
}
def = this->add("filament_cost", coFloats);
def->label = "Cost";
def->tooltip = "Enter your filament cost per kg here. This is only for statistical information.";
def->sidetext = "money/kg";
def->cli = "filament-cost=f@";
def->min = 0;
{
ConfigOptionFloats* opt = new ConfigOptionFloats();
opt->values.push_back(0);
def->default_value = opt;
}
def = this->add("filament_settings_id", coString);
def->default_value = new ConfigOptionString("");

View File

@ -299,6 +299,8 @@ class GCodeConfig : public virtual StaticPrintConfig
ConfigOptionString extrusion_axis;
ConfigOptionFloats extrusion_multiplier;
ConfigOptionFloats filament_diameter;
ConfigOptionFloats filament_density;
ConfigOptionFloats filament_cost;
ConfigOptionFloats filament_max_volumetric_speed;
ConfigOptionBool gcode_comments;
ConfigOptionEnum<GCodeFlavor> gcode_flavor;
@ -334,6 +336,8 @@ class GCodeConfig : public virtual StaticPrintConfig
OPT_PTR(extrusion_axis);
OPT_PTR(extrusion_multiplier);
OPT_PTR(filament_diameter);
OPT_PTR(filament_density);
OPT_PTR(filament_cost);
OPT_PTR(filament_max_volumetric_speed);
OPT_PTR(gcode_comments);
OPT_PTR(gcode_flavor);

View File

@ -42,6 +42,8 @@
%code%{ RETVAL = THIS->retract_speed_mm_min; %};
double filament_diameter();
double filament_density();
double filament_cost();
double extrusion_multiplier();
double retract_length();
double retract_lift();