Time estimate uses G1 lines containing E parameter for remaining time calculations

This commit is contained in:
Enrico Turri 2018-06-28 08:52:07 +02:00
parent 7ff22b9413
commit 9725966f38
2 changed files with 9 additions and 55 deletions

View file

@ -106,14 +106,6 @@ namespace Slic3r {
return ::sqrt(value); return ::sqrt(value);
} }
//#################################################################################################################
GCodeTimeEstimator::Block::Time::Time()
: elapsed(-1.0f)
, remaining(-1.0f)
{
}
//#################################################################################################################
GCodeTimeEstimator::Block::Block() GCodeTimeEstimator::Block::Block()
: st_synchronized(false) : st_synchronized(false)
//################################################################################################################# //#################################################################################################################
@ -183,13 +175,6 @@ namespace Slic3r {
trapezoid.decelerate_after = accelerate_distance + cruise_distance; trapezoid.decelerate_after = accelerate_distance + cruise_distance;
} }
//#################################################################################################################
void GCodeTimeEstimator::Block::calculate_remaining_time(float final_time)
{
time.remaining = (time.elapsed >= 0.0f) ? final_time - time.elapsed : -1.0f;
}
//#################################################################################################################
float GCodeTimeEstimator::Block::max_allowable_speed(float acceleration, float target_velocity, float distance) float GCodeTimeEstimator::Block::max_allowable_speed(float acceleration, float target_velocity, float distance)
{ {
// to avoid invalid negative numbers due to numerical imprecision // to avoid invalid negative numbers due to numerical imprecision
@ -248,10 +233,6 @@ namespace Slic3r {
_reset_time(); _reset_time();
_set_blocks_st_synchronize(false); _set_blocks_st_synchronize(false);
_calculate_time(); _calculate_time();
//#################################################################################################################
if (are_remaining_times_enabled())
_calculate_remaining_times();
//#################################################################################################################
#if ENABLE_MOVE_STATS #if ENABLE_MOVE_STATS
_log_moves_stats(); _log_moves_stats();
@ -446,17 +427,18 @@ namespace Slic3r {
_parser.parse_line(gcode_line, _parser.parse_line(gcode_line,
[this, &g1_lines_count, &last_recorded_time, &in, &out, &path_tmp, time_mask, interval](GCodeReader& reader, const GCodeReader::GCodeLine& line) [this, &g1_lines_count, &last_recorded_time, &in, &out, &path_tmp, time_mask, interval](GCodeReader& reader, const GCodeReader::GCodeLine& line)
{ {
if (line.cmd_is("G1")) if (line.cmd_is("G1") && line.has_e())
{ {
++g1_lines_count; ++g1_lines_count;
for (const Block& block : _blocks) for (const Block& block : _blocks)
{ {
if (block.g1_line_id == g1_lines_count) if ((block.g1_line_id == g1_lines_count) && (block.elapsed_time != -1.0f))
{ {
if ((last_recorded_time == _time) || (last_recorded_time - block.time.remaining > interval)) float block_remaining_time = _time - block.elapsed_time;
if ((last_recorded_time == _time) || (last_recorded_time - block_remaining_time > interval))
{ {
char buffer[1024]; char buffer[1024];
sprintf(buffer, time_mask.c_str(), std::to_string((int)(100.0f * block.time.elapsed / _time)).c_str(), _get_time_minutes(block.time.remaining).c_str()); sprintf(buffer, time_mask.c_str(), std::to_string((int)(100.0f * block.elapsed_time / _time)).c_str(), _get_time_minutes(block_remaining_time).c_str());
fwrite((const void*)buffer, 1, ::strlen(buffer), out); fwrite((const void*)buffer, 1, ::strlen(buffer), out);
if (ferror(out)) if (ferror(out))
@ -467,7 +449,7 @@ namespace Slic3r {
throw std::runtime_error(std::string("Remaining times export failed.\nIs the disk full?\n")); throw std::runtime_error(std::string("Remaining times export failed.\nIs the disk full?\n"));
} }
last_recorded_time = block.time.remaining; last_recorded_time = block_remaining_time;
break; break;
} }
} }
@ -878,7 +860,7 @@ namespace Slic3r {
block_time += block.deceleration_time(); block_time += block.deceleration_time();
_time += block_time; _time += block_time;
//########################################################################################################################## //##########################################################################################################################
block.time.elapsed = _time; block.elapsed_time = are_remaining_times_enabled() ? _time : -1.0f;
//########################################################################################################################## //##########################################################################################################################
MovesStatsMap::iterator it = _moves_stats.find(block.move_type); MovesStatsMap::iterator it = _moves_stats.find(block.move_type);
@ -892,22 +874,12 @@ namespace Slic3r {
_time += block.cruise_time(); _time += block.cruise_time();
_time += block.deceleration_time(); _time += block.deceleration_time();
//########################################################################################################################## //##########################################################################################################################
block.time.elapsed = _time; block.elapsed_time = are_remaining_times_enabled() ? _time : -1.0f;
//########################################################################################################################## //##########################################################################################################################
#endif // ENABLE_MOVE_STATS #endif // ENABLE_MOVE_STATS
} }
} }
//#################################################################################################################
void GCodeTimeEstimator::_calculate_remaining_times()
{
for (Block& block : _blocks)
{
block.calculate_remaining_time(_time);
}
}
//#################################################################################################################
void GCodeTimeEstimator::_process_gcode_line(GCodeReader&, const GCodeReader::GCodeLine& line) void GCodeTimeEstimator::_process_gcode_line(GCodeReader&, const GCodeReader::GCodeLine& line)
{ {
PROFILE_FUNC(); PROFILE_FUNC();

View file

@ -134,16 +134,6 @@ namespace Slic3r {
bool nominal_length; bool nominal_length;
}; };
//#################################################################################################################
struct Time
{
float elapsed;
float remaining;
Time();
};
//#################################################################################################################
#if ENABLE_MOVE_STATS #if ENABLE_MOVE_STATS
EMoveType move_type; EMoveType move_type;
#endif // ENABLE_MOVE_STATS #endif // ENABLE_MOVE_STATS
@ -157,7 +147,7 @@ namespace Slic3r {
FeedrateProfile feedrate; FeedrateProfile feedrate;
Trapezoid trapezoid; Trapezoid trapezoid;
//################################################################################################################# //#################################################################################################################
Time time; float elapsed_time;
unsigned int g1_line_id; unsigned int g1_line_id;
//################################################################################################################# //#################################################################################################################
@ -189,10 +179,6 @@ namespace Slic3r {
// Calculates this block's trapezoid // Calculates this block's trapezoid
void calculate_trapezoid(); void calculate_trapezoid();
//#################################################################################################################
void calculate_remaining_time(float final_time);
//#################################################################################################################
// Calculates the maximum allowable speed at this point when you must be able to reach target_velocity using the // Calculates the maximum allowable speed at this point when you must be able to reach target_velocity using the
// acceleration within the allotted distance. // acceleration within the allotted distance.
static float max_allowable_speed(float acceleration, float target_velocity, float distance); static float max_allowable_speed(float acceleration, float target_velocity, float distance);
@ -362,10 +348,6 @@ namespace Slic3r {
// Calculates the time estimate // Calculates the time estimate
void _calculate_time(); void _calculate_time();
//#################################################################################################################
void _calculate_remaining_times();
//#################################################################################################################
// Processes the given gcode line // Processes the given gcode line
void _process_gcode_line(GCodeReader&, const GCodeReader::GCodeLine& line); void _process_gcode_line(GCodeReader&, const GCodeReader::GCodeLine& line);