SPE-2437: Separate update of positions inside the pressure equalizer into functions.

This commit is contained in:
Lukáš Hejl 2024-08-28 09:51:35 +02:00 committed by Lukas Matena
parent 913e49c235
commit e8b1d0ad75
2 changed files with 35 additions and 23 deletions

View File

@ -329,8 +329,6 @@ bool PressureEqualizer::process_line(const char *line, const char *line_end, GCo
{ {
// G0, G1: A FFF 3D printer does not make a difference between the two. // G0, G1: A FFF 3D printer does not make a difference between the two.
buf.adjustable_flow = this->opened_extrude_set_speed_block; buf.adjustable_flow = this->opened_extrude_set_speed_block;
buf.extrude_set_speed_tag = found_extrude_set_speed_tag;
buf.extrude_end_tag = found_extrude_end_tag;
float new_pos[5]; float new_pos[5];
memcpy(new_pos, m_current_pos, sizeof(float)*5); memcpy(new_pos, m_current_pos, sizeof(float)*5);
bool changed[5] = { false, false, false, false, false }; bool changed[5] = { false, false, false, false, false };
@ -482,6 +480,30 @@ bool PressureEqualizer::process_line(const char *line, const char *line_end, GCo
return true; return true;
} }
void PressureEqualizer::GCodeLine::update_end_position(const float *position_end)
{
assert(position_end != nullptr);
if (position_end == nullptr)
return;
for (int i = 0; i < 4; ++i) {
this->pos_end[i] = position_end[i];
this->pos_provided[i] = true;
}
}
void PressureEqualizer::GCodeLine::update_end_position(const float *position_start, const float *position_end, const float t)
{
assert(position_start != nullptr && position_end != nullptr);
if (position_start == nullptr || position_end == nullptr)
return;
for (size_t i = 0; i < 4; ++i) {
this->pos_end[i] = position_start[i] + (position_end[i] - position_start[i]) * t;
this->pos_provided[i] = true;
}
}
void PressureEqualizer::output_gcode_line(const size_t line_idx) void PressureEqualizer::output_gcode_line(const size_t line_idx)
{ {
GCodeLine &line = m_gcode_lines[line_idx]; GCodeLine &line = m_gcode_lines[line_idx];
@ -548,15 +570,11 @@ void PressureEqualizer::output_gcode_line(const size_t line_idx)
float t = l_acc / l; float t = l_acc / l;
for (int i = 0; i < 4; ++ i) { for (int i = 0; i < 4; ++ i) {
pos_end[i] = pos_start[i] + (pos_end[i] - pos_start[i]) * t; pos_end[i] = pos_start[i] + (pos_end[i] - pos_start[i]) * t;
line.pos_provided[i] = true;
} }
} else { } else {
// Emit the steady feed rate segment. // Emit the steady feed rate segment.
float t = l_steady / l; const float t = l_steady / l;
for (int i = 0; i < 4; ++ i) { line.update_end_position(pos_start, pos_end, t);
line.pos_end[i] = pos_start[i] + (pos_end[i] - pos_start[i]) * t;
line.pos_provided[i] = true;
}
push_line_to_output(line_idx, pos_start[4], comment); push_line_to_output(line_idx, pos_start[4], comment);
comment = nullptr; comment = nullptr;
@ -569,29 +587,23 @@ void PressureEqualizer::output_gcode_line(const size_t line_idx)
pos_start[4] = new_pos_start_feedrate; pos_start[4] = new_pos_start_feedrate;
} }
} }
// Split the segment into pieces. // Split the segment into pieces.
for (size_t i = 1; i < nSegments; ++ i) { for (size_t i = 1; i < nSegments; ++ i) {
float t = float(i) / float(nSegments); const float t = float(i) / float(nSegments);
for (size_t j = 0; j < 4; ++ j) { line.update_end_position(pos_start, pos_end, t);
line.pos_end[j] = pos_start[j] + (pos_end[j] - pos_start[j]) * t;
line.pos_provided[j] = true;
}
// Interpolate the feed rate at the center of the segment. // Interpolate the feed rate at the center of the segment.
push_line_to_output(line_idx, pos_start[4] + (pos_end[4] - pos_start[4]) * (float(i) - 0.5f) / float(nSegments), comment); push_line_to_output(line_idx, pos_start[4] + (pos_end[4] - pos_start[4]) * (float(i) - 0.5f) / float(nSegments), comment);
comment = nullptr; comment = nullptr;
memcpy(line.pos_start, line.pos_end, sizeof(float)*5); memcpy(line.pos_start, line.pos_end, sizeof(float)*5);
} }
if (l_steady > 0.f && accelerating) { if (l_steady > 0.f && accelerating) {
for (int i = 0; i < 4; ++ i) { line.update_end_position(pos_end2);
line.pos_end[i] = pos_end2[i];
line.pos_provided[i] = true;
}
push_line_to_output(line_idx, pos_end[4], comment); push_line_to_output(line_idx, pos_end[4], comment);
} else { } else {
for (int i = 0; i < 4; ++ i) { line.update_end_position(pos_end);
line.pos_end[i] = pos_end[i];
line.pos_provided[i] = true;
}
push_line_to_output(line_idx, pos_end[4], comment); push_line_to_output(line_idx, pos_end[4], comment);
} }
} }

View File

@ -178,8 +178,8 @@ private:
bool adjustable_flow = false; bool adjustable_flow = false;
bool extrude_set_speed_tag = false; void update_end_position(const float *position_end);
bool extrude_end_tag = false; void update_end_position(const float *position_start, const float *position_end, float t);
}; };
using GCodeLines = std::vector<GCodeLine>; using GCodeLines = std::vector<GCodeLine>;