2014-04-07 23:42:29 +00:00
|
|
|
#include "Extruder.hpp"
|
|
|
|
|
|
|
|
namespace Slic3r {
|
|
|
|
|
2017-06-22 13:18:37 +00:00
|
|
|
Extruder::Extruder(unsigned int id, GCodeConfig *config) :
|
|
|
|
m_id(id),
|
2017-05-03 16:28:22 +00:00
|
|
|
m_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
|
2017-06-22 13:18:37 +00:00
|
|
|
m_e_per_mm3 = this->extrusion_multiplier();
|
|
|
|
if (! m_config->use_volumetric_e)
|
|
|
|
m_e_per_mm3 /= this->filament_crossection();
|
2014-04-07 23:42:29 +00:00
|
|
|
}
|
|
|
|
|
2017-05-19 17:24:21 +00:00
|
|
|
double Extruder::extrude(double dE)
|
2014-04-07 23:42:29 +00:00
|
|
|
{
|
2014-10-21 18:16:45 +00:00
|
|
|
// in case of relative E distances we always reset to 0 before any output
|
2017-05-03 16:28:22 +00:00
|
|
|
if (m_config->use_relative_e_distances)
|
2017-06-22 13:18:37 +00:00
|
|
|
m_E = 0.;
|
|
|
|
m_E += dE;
|
|
|
|
m_absolute_E += dE;
|
|
|
|
if (dE < 0.)
|
|
|
|
m_retracted -= 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. */
|
2017-05-19 17:24:21 +00:00
|
|
|
double Extruder::retract(double length, double restart_extra)
|
2014-10-21 18:16:45 +00:00
|
|
|
{
|
|
|
|
// in case of relative E distances we always reset to 0 before any output
|
2017-05-03 16:28:22 +00:00
|
|
|
if (m_config->use_relative_e_distances)
|
2017-06-22 13:18:37 +00:00
|
|
|
m_E = 0.;
|
|
|
|
double to_retract = std::max(0., length - m_retracted);
|
|
|
|
if (to_retract > 0.) {
|
|
|
|
m_E -= to_retract;
|
|
|
|
m_absolute_E -= to_retract;
|
|
|
|
m_retracted += to_retract;
|
|
|
|
m_restart_extra = restart_extra;
|
2014-10-21 18:16:45 +00:00
|
|
|
}
|
2017-06-22 13:18:37 +00:00
|
|
|
return to_retract;
|
2014-10-21 18:16:45 +00:00
|
|
|
}
|
|
|
|
|
2017-05-19 17:24:21 +00:00
|
|
|
double Extruder::unretract()
|
2014-10-21 18:16:45 +00:00
|
|
|
{
|
2017-06-22 13:18:37 +00:00
|
|
|
double dE = m_retracted + m_restart_extra;
|
2014-10-21 18:16:45 +00:00
|
|
|
this->extrude(dE);
|
2017-06-22 13:18:37 +00:00
|
|
|
m_retracted = 0.;
|
|
|
|
m_restart_extra = 0.;
|
2014-10-21 18:16:45 +00:00
|
|
|
return dE;
|
2014-04-07 23:42:29 +00:00
|
|
|
}
|
|
|
|
|
2017-06-22 13:18:37 +00:00
|
|
|
// Used filament volume in mm^3.
|
2017-05-19 17:24:21 +00:00
|
|
|
double Extruder::extruded_volume() const
|
2014-10-21 18:36:52 +00:00
|
|
|
{
|
2017-06-22 13:18:37 +00:00
|
|
|
return m_config->use_volumetric_e ?
|
|
|
|
m_absolute_E + m_retracted :
|
|
|
|
this->used_filament() * this->filament_crossection();
|
2014-10-21 18:36:52 +00:00
|
|
|
}
|
|
|
|
|
2017-06-22 13:18:37 +00:00
|
|
|
// Used filament length in mm.
|
2017-05-19 17:24:21 +00:00
|
|
|
double Extruder::used_filament() const
|
2014-10-21 18:36:52 +00:00
|
|
|
{
|
2017-06-22 13:18:37 +00:00
|
|
|
return m_config->use_volumetric_e ?
|
|
|
|
this->extruded_volume() / this->filament_crossection() :
|
|
|
|
m_absolute_E + m_retracted;
|
2014-10-21 18:36:52 +00:00
|
|
|
}
|
|
|
|
|
2017-05-19 17:24:21 +00:00
|
|
|
double Extruder::filament_diameter() const
|
2014-04-27 21:49:05 +00:00
|
|
|
{
|
2017-06-22 10:59:23 +00:00
|
|
|
return m_config->filament_diameter.get_at(m_id);
|
2014-04-27 21:49:05 +00:00
|
|
|
}
|
|
|
|
|
2017-05-19 17:24:21 +00:00
|
|
|
double Extruder::filament_density() const
|
2017-01-16 05:56:01 +00:00
|
|
|
{
|
2017-06-22 10:59:23 +00:00
|
|
|
return m_config->filament_density.get_at(m_id);
|
2017-01-16 05:56:01 +00:00
|
|
|
}
|
|
|
|
|
2017-05-19 17:24:21 +00:00
|
|
|
double Extruder::filament_cost() const
|
2017-01-16 05:56:01 +00:00
|
|
|
{
|
2017-06-22 10:59:23 +00:00
|
|
|
return m_config->filament_cost.get_at(m_id);
|
2017-01-16 05:56:01 +00:00
|
|
|
}
|
|
|
|
|
2017-05-19 17:24:21 +00:00
|
|
|
double Extruder::extrusion_multiplier() const
|
2014-04-27 21:49:05 +00:00
|
|
|
{
|
2017-06-22 10:59:23 +00:00
|
|
|
return m_config->extrusion_multiplier.get_at(m_id);
|
2014-04-27 21:49:05 +00:00
|
|
|
}
|
|
|
|
|
2017-05-19 17:24:21 +00:00
|
|
|
// Return a "retract_before_wipe" percentage as a factor clamped to <0, 1>
|
|
|
|
double Extruder::retract_before_wipe() const
|
|
|
|
{
|
2017-06-22 10:59:23 +00:00
|
|
|
return std::min(1., std::max(0., m_config->retract_before_wipe.get_at(m_id) * 0.01));
|
2017-05-19 17:24:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double Extruder::retract_length() const
|
2014-04-27 21:49:05 +00:00
|
|
|
{
|
2017-06-22 10:59:23 +00:00
|
|
|
return m_config->retract_length.get_at(m_id);
|
2014-04-27 21:49:05 +00:00
|
|
|
}
|
|
|
|
|
2017-05-19 17:24:21 +00:00
|
|
|
double Extruder::retract_lift() const
|
2014-04-27 21:49:05 +00:00
|
|
|
{
|
2017-06-22 10:59:23 +00:00
|
|
|
return m_config->retract_lift.get_at(m_id);
|
2014-04-27 21:49:05 +00:00
|
|
|
}
|
|
|
|
|
2017-05-19 17:24:21 +00:00
|
|
|
int Extruder::retract_speed() const
|
2014-04-27 21:49:05 +00:00
|
|
|
{
|
2017-06-22 13:18:37 +00:00
|
|
|
return int(floor(m_config->retract_speed.get_at(m_id)+0.5));
|
2014-04-27 21:49:05 +00:00
|
|
|
}
|
|
|
|
|
2017-05-19 17:24:21 +00:00
|
|
|
int Extruder::deretract_speed() const
|
|
|
|
{
|
2017-06-22 13:18:37 +00:00
|
|
|
int speed = int(floor(m_config->deretract_speed.get_at(m_id)+0.5));
|
2017-05-19 17:24:21 +00:00
|
|
|
return (speed > 0) ? speed : this->retract_speed();
|
|
|
|
}
|
|
|
|
|
|
|
|
double Extruder::retract_restart_extra() const
|
2014-04-27 21:49:05 +00:00
|
|
|
{
|
2017-06-22 10:59:23 +00:00
|
|
|
return m_config->retract_restart_extra.get_at(m_id);
|
2014-04-27 21:49:05 +00:00
|
|
|
}
|
|
|
|
|
2017-05-19 17:24:21 +00:00
|
|
|
double Extruder::retract_length_toolchange() const
|
2014-04-27 21:49:05 +00:00
|
|
|
{
|
2017-06-22 10:59:23 +00:00
|
|
|
return m_config->retract_length_toolchange.get_at(m_id);
|
2014-04-27 21:49:05 +00:00
|
|
|
}
|
|
|
|
|
2017-05-19 17:24:21 +00:00
|
|
|
double Extruder::retract_restart_extra_toolchange() const
|
2014-04-27 21:49:05 +00:00
|
|
|
{
|
2017-06-22 10:59:23 +00:00
|
|
|
return m_config->retract_restart_extra_toolchange.get_at(m_id);
|
2014-04-27 21:49:05 +00:00
|
|
|
}
|
|
|
|
|
2014-04-07 23:42:29 +00:00
|
|
|
}
|