GCodeProcessor -> Calculate mm3 per mm on the fly

This commit is contained in:
enricoturri1966 2020-07-29 10:04:10 +02:00
parent d9228ee82c
commit 11cf9a87f1
5 changed files with 35 additions and 36 deletions

View file

@ -1178,7 +1178,6 @@ void GCode::_do_export(Print& print, FILE* file, ThumbnailsGeneratorCallback thu
// resets analyzer's tracking data
#if ENABLE_GCODE_VIEWER
m_last_mm3_per_mm = 0.0f;
m_last_width = 0.0f;
m_last_height = 0.0f;
#else
@ -3237,16 +3236,13 @@ std::string GCode::_extrude(const ExtrusionPath &path, std::string description,
}
#endif // ENABLE_GCODE_VIEWER
#if !ENABLE_GCODE_VIEWER
if (last_was_wipe_tower || (m_last_mm3_per_mm != path.mm3_per_mm)) {
m_last_mm3_per_mm = path.mm3_per_mm;
#if ENABLE_GCODE_VIEWER
sprintf(buf, ";%s%f\n", GCodeProcessor::Mm3_Per_Mm_Tag.c_str(), m_last_mm3_per_mm);
gcode += buf;
#else
sprintf(buf, ";%s%f\n", GCodeAnalyzer::Mm3_Per_Mm_Tag.c_str(), m_last_mm3_per_mm);
gcode += buf;
#endif // ENABLE_GCODE_VIEWER
}
#endif // !ENABLE_GCODE_VIEWER
if (last_was_wipe_tower || (m_last_width != path.width)) {
m_last_width = path.width;

View file

@ -173,7 +173,6 @@ public:
m_last_pos_defined(false),
m_last_extrusion_role(erNone),
#if ENABLE_GCODE_VIEWER
m_last_mm3_per_mm(0.0f),
m_last_width(0.0f),
m_last_height(0.0f),
#else
@ -378,10 +377,16 @@ private:
double m_volumetric_speed;
// Support for the extrusion role markers. Which marker is active?
ExtrusionRole m_last_extrusion_role;
#if ENABLE_GCODE_VIEWER
// Support for G-Code Processor
float m_last_width;
float m_last_height;
#else
// Support for G-Code Analyzer
double m_last_mm3_per_mm;
float m_last_width;
float m_last_height;
#endif // ENABLE_GCODE_VIEWER
Point m_last_pos;
bool m_last_pos_defined;

View file

@ -24,7 +24,6 @@ namespace Slic3r {
const std::string GCodeProcessor::Extrusion_Role_Tag = "ExtrType:";
const std::string GCodeProcessor::Width_Tag = "PrusaSlicer__WIDTH:";
const std::string GCodeProcessor::Height_Tag = "PrusaSlicer__HEIGHT:";
const std::string GCodeProcessor::Mm3_Per_Mm_Tag = "PrusaSlicer__MM3_PER_MM:";
const std::string GCodeProcessor::Color_Change_Tag = "COLOR_CHANGE";
const std::string GCodeProcessor::Pause_Print_Tag = "PAUSE_PRINT";
const std::string GCodeProcessor::Custom_Code_Tag = "CUSTOM_CODE";
@ -325,6 +324,10 @@ void GCodeProcessor::apply_config(const PrintConfig& config)
m_extruders_color[id] = static_cast<unsigned int>(id);
}
for (double diam : config.filament_diameter.values) {
m_filament_diameters.push_back(static_cast<float>(diam));
}
m_time_processor.machine_limits = reinterpret_cast<const MachineEnvelopeConfig&>(config);
// Filament load / unload times are not specific to a firmware flavor. Let anybody use it if they find it useful.
// As of now the fields are shown at the UI dialog in the same combo box as the ramming values, so they
@ -370,6 +373,7 @@ void GCodeProcessor::reset()
m_extrusion_role = erNone;
m_extruder_id = 0;
m_extruders_color = ExtrudersColor();
m_filament_diameters = std::vector<float>();
m_cp_color.reset();
m_producer = EProducer::Unknown;
@ -592,20 +596,6 @@ void GCodeProcessor::process_tags(const std::string& comment)
return;
}
// mm3 per mm tag
pos = comment.find(Mm3_Per_Mm_Tag);
if (pos != comment.npos) {
try
{
m_mm3_per_mm = std::stof(comment.substr(pos + Mm3_Per_Mm_Tag.length()));
}
catch (...)
{
BOOST_LOG_TRIVIAL(error) << "GCodeProcessor encountered an invalid value for Mm3_Per_Mm (" << comment << ").";
}
return;
}
// color change tag
pos = comment.find(Color_Change_Tag);
if (pos != comment.npos) {
@ -1019,6 +1009,14 @@ void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line)
EMoveType type = move_type(delta_pos);
if (type == EMoveType::Extrude) {
if (delta_pos[E] > 0.0f) {
float ds = std::sqrt(sqr(delta_pos[X]) + sqr(delta_pos[Y]) + sqr(delta_pos[Z]));
if (ds > 0.0f && static_cast<size_t>(m_extruder_id) < m_filament_diameters.size())
m_mm3_per_mm = round_nearest(delta_pos[E] * static_cast<float>(M_PI) * sqr(static_cast<float>(m_filament_diameters[m_extruder_id])) / (4.0f * ds), 3);
}
}
// time estimate section
auto move_length = [](const AxisCoords& delta_pos) {
float sq_xyz_length = sqr(delta_pos[X]) + sqr(delta_pos[Y]) + sqr(delta_pos[Z]);

View file

@ -21,7 +21,6 @@ namespace Slic3r {
static const std::string Extrusion_Role_Tag;
static const std::string Width_Tag;
static const std::string Height_Tag;
static const std::string Mm3_Per_Mm_Tag;
static const std::string Color_Change_Tag;
static const std::string Pause_Print_Tag;
static const std::string Custom_Code_Tag;
@ -241,6 +240,7 @@ namespace Slic3r {
ExtrusionRole m_extrusion_role;
unsigned char m_extruder_id;
ExtrudersColor m_extruders_color;
std::vector<float> m_filament_diameters;
CpColor m_cp_color;
enum class EProducer

View file

@ -84,19 +84,17 @@ public:
return *this;
}
WipeTowerWriter& change_analyzer_mm3_per_mm(float len, float e) {
static const float area = float(M_PI) * 1.75f * 1.75f / 4.f;
float mm3_per_mm = (len == 0.f ? 0.f : area * e / len);
// adds tag for analyzer:
char buf[64];
#if ENABLE_GCODE_VIEWER
sprintf(buf, ";%s%f\n", GCodeProcessor::Mm3_Per_Mm_Tag.c_str(), mm3_per_mm);
#else
sprintf(buf, ";%s%f\n", GCodeAnalyzer::Mm3_Per_Mm_Tag.c_str(), mm3_per_mm);
#endif // ENABLE_GCODE_VIEWER
m_gcode += buf;
return *this;
#if !ENABLE_GCODE_VIEWER
WipeTowerWriter& change_analyzer_mm3_per_mm(float len, float e) {
static const float area = float(M_PI) * 1.75f * 1.75f / 4.f;
float mm3_per_mm = (len == 0.f ? 0.f : area * e / len);
// adds tag for analyzer:
char buf[64];
sprintf(buf, ";%s%f\n", GCodeAnalyzer::Mm3_Per_Mm_Tag.c_str(), mm3_per_mm);
m_gcode += buf;
return *this;
}
#endif // !ENABLE_GCODE_VIEWER
WipeTowerWriter& set_initial_position(const Vec2f &pos, float width = 0.f, float depth = 0.f, float internal_angle = 0.f) {
m_wipe_tower_width = width;
@ -169,8 +167,10 @@ public:
Vec2f rot(this->rotate(Vec2f(x,y))); // this is where we want to go
if (! m_preview_suppressed && e > 0.f && len > 0.f) {
#if !ENABLE_GCODE_VIEWER
change_analyzer_mm3_per_mm(len, e);
// Width of a squished extrusion, corrected for the roundings of the squished extrusions.
#endif // !ENABLE_GCODE_VIEWER
// Width of a squished extrusion, corrected for the roundings of the squished extrusions.
// This is left zero if it is a travel move.
float width = e * m_filpar[0].filament_area / (len * m_layer_height);
// Correct for the roundings of a squished extrusion.