2014-04-07 23:42:29 +00:00
|
|
|
#include "Extruder.hpp"
|
|
|
|
|
|
|
|
namespace Slic3r {
|
|
|
|
|
2014-10-25 08:42:07 +00:00
|
|
|
Extruder::Extruder(int id, GCodeConfig *config)
|
2014-04-07 23:42:29 +00:00
|
|
|
: id(id),
|
2014-04-27 21:03:22 +00:00
|
|
|
config(config)
|
2014-04-07 23:42:29 +00:00
|
|
|
{
|
|
|
|
reset();
|
2014-10-21 18:36:52 +00:00
|
|
|
|
|
|
|
// cache values that are going to be called often
|
2015-01-05 18:39:10 +00:00
|
|
|
if (config->use_volumetric_e) {
|
|
|
|
this->e_per_mm3 = this->extrusion_multiplier();
|
|
|
|
} else {
|
|
|
|
this->e_per_mm3 = this->extrusion_multiplier()
|
|
|
|
* (4 / ((this->filament_diameter() * this->filament_diameter()) * PI));
|
|
|
|
}
|
2014-10-21 18:36:52 +00:00
|
|
|
this->retract_speed_mm_min = this->retract_speed() * 60;
|
2014-04-07 23:42:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Extruder::reset()
|
|
|
|
{
|
|
|
|
this->E = 0;
|
|
|
|
this->absolute_E = 0;
|
|
|
|
this->retracted = 0;
|
|
|
|
this->restart_extra = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
Extruder::extrude(double dE)
|
|
|
|
{
|
2014-10-21 18:16:45 +00:00
|
|
|
// in case of relative E distances we always reset to 0 before any output
|
|
|
|
if (this->config->use_relative_e_distances)
|
2014-04-07 23:42:29 +00:00
|
|
|
this->E = 0;
|
|
|
|
|
|
|
|
this->E += dE;
|
|
|
|
this->absolute_E += dE;
|
2014-10-21 18:16:45 +00:00
|
|
|
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;
|
2014-04-07 23:42:29 +00:00
|
|
|
}
|
|
|
|
|
2014-10-21 18:36:52 +00:00
|
|
|
double
|
|
|
|
Extruder::e_per_mm(double mm3_per_mm) const
|
|
|
|
{
|
|
|
|
return mm3_per_mm * this->e_per_mm3;
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
Extruder::extruded_volume() const
|
|
|
|
{
|
2015-01-05 18:39:10 +00:00
|
|
|
if (this->config->use_volumetric_e) {
|
|
|
|
// Any current amount of retraction should not affect used filament, since
|
|
|
|
// it represents empty volume in the nozzle. We add it back to E.
|
|
|
|
return this->absolute_E + this->retracted;
|
|
|
|
}
|
|
|
|
|
2014-10-21 18:36:52 +00:00
|
|
|
return this->used_filament() * (this->filament_diameter() * this->filament_diameter()) * PI/4;
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
Extruder::used_filament() const
|
|
|
|
{
|
2015-01-05 18:39:10 +00:00
|
|
|
if (this->config->use_volumetric_e) {
|
|
|
|
return this->extruded_volume() / (this->filament_diameter() * this->filament_diameter() * PI/4);
|
|
|
|
}
|
|
|
|
|
2014-10-21 18:36:52 +00:00
|
|
|
// Any current amount of retraction should not affect used filament, since
|
|
|
|
// it represents empty volume in the nozzle. We add it back to E.
|
|
|
|
return this->absolute_E + this->retracted;
|
|
|
|
}
|
|
|
|
|
2014-04-27 21:49:05 +00:00
|
|
|
double
|
|
|
|
Extruder::filament_diameter() const
|
|
|
|
{
|
2014-04-28 20:02:34 +00:00
|
|
|
return this->config->filament_diameter.get_at(this->id);
|
2014-04-27 21:49:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
Extruder::extrusion_multiplier() const
|
|
|
|
{
|
2014-04-28 20:02:34 +00:00
|
|
|
return this->config->extrusion_multiplier.get_at(this->id);
|
2014-04-27 21:49:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
Extruder::retract_length() const
|
|
|
|
{
|
2014-04-28 20:02:34 +00:00
|
|
|
return this->config->retract_length.get_at(this->id);
|
2014-04-27 21:49:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
Extruder::retract_lift() const
|
|
|
|
{
|
2014-04-28 20:02:34 +00:00
|
|
|
return this->config->retract_lift.get_at(this->id);
|
2014-04-27 21:49:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
Extruder::retract_speed() const
|
|
|
|
{
|
2014-04-28 20:02:34 +00:00
|
|
|
return this->config->retract_speed.get_at(this->id);
|
2014-04-27 21:49:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
Extruder::retract_restart_extra() const
|
|
|
|
{
|
2014-04-28 20:02:34 +00:00
|
|
|
return this->config->retract_restart_extra.get_at(this->id);
|
2014-04-27 21:49:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
Extruder::retract_length_toolchange() const
|
|
|
|
{
|
2014-04-28 20:02:34 +00:00
|
|
|
return this->config->retract_length_toolchange.get_at(this->id);
|
2014-04-27 21:49:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
Extruder::retract_restart_extra_toolchange() const
|
|
|
|
{
|
2014-04-28 20:02:34 +00:00
|
|
|
return this->config->retract_restart_extra_toolchange.get_at(this->id);
|
2014-04-27 21:49:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-27 20:44:10 +00:00
|
|
|
#ifdef SLIC3RXS
|
|
|
|
REGISTER_CLASS(Extruder, "Extruder");
|
|
|
|
#endif
|
|
|
|
|
2014-04-07 23:42:29 +00:00
|
|
|
}
|