#4986 - Fixed remaining print time and SD-percentage calculation not correct (replaces e14c122d1233a7af9bfe63425d3bfb4e5906ede3)

This commit is contained in:
enricoturri1966 2020-10-27 15:50:04 +01:00
parent 00ec9cc4ed
commit 90c69e6bda
2 changed files with 27 additions and 11 deletions

View File

@ -170,7 +170,7 @@ void GCodeProcessor::TimeMachine::reset()
prev.reset(); prev.reset();
gcode_time.reset(); gcode_time.reset();
blocks = std::vector<TimeBlock>(); blocks = std::vector<TimeBlock>();
g1_times_cache = std::vector<float>(); g1_times_cache = std::vector<G1LinesCacheItem>();
std::fill(moves_time.begin(), moves_time.end(), 0.0f); std::fill(moves_time.begin(), moves_time.end(), 0.0f);
std::fill(roles_time.begin(), roles_time.end(), 0.0f); std::fill(roles_time.begin(), roles_time.end(), 0.0f);
layers_time = std::vector<float>(); layers_time = std::vector<float>();
@ -292,7 +292,7 @@ void GCodeProcessor::TimeMachine::calculate_time(size_t keep_last_n_blocks)
} }
layers_time[block.layer_id - 1] += block_time; layers_time[block.layer_id - 1] += block_time;
} }
g1_times_cache.push_back(time); g1_times_cache.push_back({ block.g1_line_id, time });
} }
if (keep_last_n_blocks) if (keep_last_n_blocks)
@ -398,14 +398,18 @@ void GCodeProcessor::TimeProcessor::post_process(const std::string& filename)
auto process_line_G1 = [&]() { auto process_line_G1 = [&]() {
for (size_t i = 0; i < static_cast<size_t>(PrintEstimatedTimeStatistics::ETimeMode::Count); ++i) { for (size_t i = 0; i < static_cast<size_t>(PrintEstimatedTimeStatistics::ETimeMode::Count); ++i) {
const TimeMachine& machine = machines[i]; const TimeMachine& machine = machines[i];
if (machine.enabled && g1_lines_counter < machine.g1_times_cache.size()) { if (machine.enabled) {
float elapsed_time = machine.g1_times_cache[g1_lines_counter]; auto it = std::find_if(machine.g1_times_cache.begin(), machine.g1_times_cache.end(),
std::pair<int, int> to_export = { int(100.0f * elapsed_time / machine.time), [g1_lines_counter](const TimeMachine::G1LinesCacheItem& item) { return item.id == g1_lines_counter; });
time_in_minutes(machine.time - elapsed_time) }; if (it != machine.g1_times_cache.end()) {
if (last_exported[i] != to_export) { float elapsed_time = it->elapsed_time;
export_line += format_line_M73(machine.line_m73_mask.c_str(), std::pair<int, int> to_export = { int(100.0f * elapsed_time / machine.time),
to_export.first, to_export.second); time_in_minutes(machine.time - elapsed_time) };
last_exported[i] = to_export; if (last_exported[i] != to_export) {
export_line += format_line_M73(machine.line_m73_mask.c_str(),
to_export.first, to_export.second);
last_exported[i] = to_export;
}
} }
} }
} }
@ -711,6 +715,7 @@ void GCodeProcessor::reset()
m_filament_diameters = std::vector<float>(Min_Extruder_Count, 1.75f); m_filament_diameters = std::vector<float>(Min_Extruder_Count, 1.75f);
m_extruded_last_z = 0.0f; m_extruded_last_z = 0.0f;
m_g1_line_id = 0;
m_layer_id = 0; m_layer_id = 0;
m_cp_color.reset(); m_cp_color.reset();
@ -1393,6 +1398,8 @@ void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line)
return type; return type;
}; };
++m_g1_line_id;
// enable processing of lines M201/M203/M204/M205 // enable processing of lines M201/M203/M204/M205
m_time_processor.machine_envelope_processing_enabled = true; m_time_processor.machine_envelope_processing_enabled = true;
@ -1498,6 +1505,7 @@ void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line)
block.move_type = type; block.move_type = type;
block.role = m_extrusion_role; block.role = m_extrusion_role;
block.distance = distance; block.distance = distance;
block.g1_line_id = m_g1_line_id;
block.layer_id = m_layer_id; block.layer_id = m_layer_id;
// calculates block cruise feedrate // calculates block cruise feedrate

View File

@ -145,6 +145,7 @@ namespace Slic3r {
EMoveType move_type{ EMoveType::Noop }; EMoveType move_type{ EMoveType::Noop };
ExtrusionRole role{ erNone }; ExtrusionRole role{ erNone };
unsigned int g1_line_id{ 0 };
unsigned int layer_id{ 0 }; unsigned int layer_id{ 0 };
float distance{ 0.0f }; // mm float distance{ 0.0f }; // mm
float acceleration{ 0.0f }; // mm/s^2 float acceleration{ 0.0f }; // mm/s^2
@ -182,6 +183,12 @@ namespace Slic3r {
void reset(); void reset();
}; };
struct G1LinesCacheItem
{
unsigned int id;
float elapsed_time;
};
bool enabled; bool enabled;
float acceleration; // mm/s^2 float acceleration; // mm/s^2
// hard limit for the acceleration, to which the firmware will clamp. // hard limit for the acceleration, to which the firmware will clamp.
@ -193,7 +200,7 @@ namespace Slic3r {
State prev; State prev;
CustomGCodeTime gcode_time; CustomGCodeTime gcode_time;
std::vector<TimeBlock> blocks; std::vector<TimeBlock> blocks;
std::vector<float> g1_times_cache; std::vector<G1LinesCacheItem> g1_times_cache;
std::array<float, static_cast<size_t>(EMoveType::Count)> moves_time; std::array<float, static_cast<size_t>(EMoveType::Count)> moves_time;
std::array<float, static_cast<size_t>(ExtrusionRole::erCount)> roles_time; std::array<float, static_cast<size_t>(ExtrusionRole::erCount)> roles_time;
std::vector<float> layers_time; std::vector<float> layers_time;
@ -376,6 +383,7 @@ namespace Slic3r {
ExtruderColors m_extruder_colors; ExtruderColors m_extruder_colors;
std::vector<float> m_filament_diameters; std::vector<float> m_filament_diameters;
float m_extruded_last_z; float m_extruded_last_z;
unsigned int m_g1_line_id;
unsigned int m_layer_id; unsigned int m_layer_id;
CpColor m_cp_color; CpColor m_cp_color;