Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FormerLurker/ArcWelderLib.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'ArcWelder/arc_welder.cpp')
-rw-r--r--ArcWelder/arc_welder.cpp49
1 files changed, 39 insertions, 10 deletions
diff --git a/ArcWelder/arc_welder.cpp b/ArcWelder/arc_welder.cpp
index a1f4ca7..95fbcda 100644
--- a/ArcWelder/arc_welder.cpp
+++ b/ArcWelder/arc_welder.cpp
@@ -34,6 +34,7 @@
#include <fstream>
#include <iomanip>
#include <sstream>
+#include <version.h>
arc_welder::arc_welder(
std::string source_path,
@@ -53,7 +54,7 @@ arc_welder::arc_welder(
int buffer_size,
progress_callback callback) : current_arc_(
DEFAULT_MIN_SEGMENTS,
- buffer_size - 5,
+ buffer_size,
resolution_mm,
path_tolerance_percent,
max_radius,
@@ -92,6 +93,7 @@ arc_welder::arc_welder(
last_gcode_line_written_ = 0;
points_compressed_ = 0;
arcs_created_ = 0;
+ arcs_aborted_by_flow_rate_ = 0;
waiting_for_arc_ = false;
previous_feedrate_ = -1;
gcode_position_args_.set_num_extruders(8);
@@ -114,6 +116,10 @@ gcode_position_args arc_welder::get_args_(bool g90_g91_influences_extruder, int
gcode_position_args args;
// Configure gcode_position_args
args.g90_influences_extruder = g90_g91_influences_extruder;
+ if (buffer_size < 2)
+ {
+ buffer_size = 2;
+ }
args.position_buffer_size = buffer_size;
args.autodetect_position = true;
args.home_x = 0;
@@ -258,7 +264,8 @@ arc_welder_results results;
p_logger_->log(logger_type_, DEBUG, "Sending initial progress update.");
continue_processing = on_progress_(get_progress_(static_cast<long>(gcodeFile.tellg()), static_cast<double>(start_clock)));
p_logger_->log(logger_type_, DEBUG, "Processing source file.");
-
+
+ bool arc_Welder_comment_added = false;
while (std::getline(gcodeFile, line) && continue_processing)
{
lines_processed_++;
@@ -267,17 +274,20 @@ arc_welder_results results;
if (lines_processed_ == 1)
{
bool isUltiGCode = line == ";FLAVOR:UltiGCode";
- if (isUltiGCode)
+ bool isPrusaSlicer = line.rfind("; generated by PrusaSlicer", 0) == 0;
+ if (isUltiGCode || isPrusaSlicer)
{
write_gcode_to_file(line);
}
add_arcwelder_comment_to_target();
- if (isUltiGCode)
+ if (isUltiGCode || isPrusaSlicer)
{
lines_with_no_commands++;
continue;
}
}
+
+
cmd.clear();
if (verbose_logging_enabled_)
{
@@ -368,6 +378,7 @@ arc_welder_progress arc_welder::get_progress_(long source_file_position, double
progress.lines_processed = lines_processed_;
progress.points_compressed = points_compressed_;
progress.arcs_created = arcs_created_;
+ progress.arcs_aborted_by_flow_rate = arcs_aborted_by_flow_rate_;
progress.source_file_position = source_file_position;
progress.target_file_size = static_cast<long>(output_file_.tellp());
progress.source_file_size = file_size_;
@@ -432,6 +443,7 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end, bool is_reprocess
// calculate the extrusion rate (mm/mm) and see how much it changes
double mm_extruded_per_mm_travel = 0;
double extrusion_rate_change_percent = 0;
+ bool aborted_by_flow_rate = false;
if (movement_length_mm > 0)
{
mm_extruded_per_mm_travel = extruder_current.e_relative / movement_length_mm;
@@ -440,9 +452,10 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end, bool is_reprocess
extrusion_rate_change_percent = std::fabs(utilities::get_percent_change(previous_extrusion_rate_, mm_extruded_per_mm_travel));
}
}
- if (extrusion_rate_change_percent > extrusion_rate_variance_percent_)
+ if (previous_extrusion_rate_ != 0 && utilities::greater_than(extrusion_rate_change_percent, extrusion_rate_variance_percent_))
{
- std::cout << "Extrusion Rate Change Percent: " << extrusion_rate_change_percent << "\n";
+ arcs_aborted_by_flow_rate_++;
+ aborted_by_flow_rate = true;
}
// We need to make sure the printer is using absolute xyz, is extruding, and the extruder axis mode is the same as that of the previous position
@@ -483,6 +496,8 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end, bool is_reprocess
(
!waiting_for_arc_ ||
extruder_current.is_extruding ||
+ // Test for travel conversion
+
//(previous_extruder.is_extruding && extruder_current.is_extruding) || // Test to see if
// we can get more arcs.
(previous_extruder.is_retracting && extruder_current.is_retracting)
@@ -493,6 +508,8 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end, bool is_reprocess
)
) {
+ // Record the extrusion rate
+ previous_extrusion_rate_ = mm_extruded_per_mm_travel;
printer_point p(p_cur_pos->get_gcode_x(), p_cur_pos->get_gcode_y(), p_cur_pos->get_gcode_z(), extruder_current.e_relative, movement_length_mm);
if (!waiting_for_arc_)
{
@@ -514,6 +531,11 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end, bool is_reprocess
arc_added = current_arc_.try_add_point(p);
if (arc_added)
{
+ // Make sure our position list is large enough to handle all the segments
+ if (current_arc_.get_num_segments()+2 > p_source_position_->get_max_positions())
+ {
+ p_source_position_->grow_max_positions(p_source_position_->get_max_positions()*2);
+ }
if (!waiting_for_arc_)
{
waiting_for_arc_ = true;
@@ -533,7 +555,7 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end, bool is_reprocess
}
}
else {
- previous_extrusion_rate_ = 0;
+
if (debug_logging_enabled_) {
if (is_end)
{
@@ -606,9 +628,12 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end, bool is_reprocess
{
p_logger_->log(logger_type_, DEBUG, "Feature type changed, cannot add point to current arc: " + cmd.gcode);
}
- else if (previous_extrusion_rate_ != 0 && !utilities::is_equal(previous_extrusion_rate_, mm_extruded_per_mm_travel))
+ else if (aborted_by_flow_rate)
{
- p_logger_->log(logger_type_, DEBUG, "Previus extrusion rate changed: " + cmd.gcode);
+ std::stringstream stream;
+ stream << std::fixed << std::setprecision(5);
+ stream << "Arc Canceled - The extrusion rate variance of " << extrusion_rate_variance_percent_ << "% exceeded by " << extrusion_rate_change_percent - extrusion_rate_variance_percent_ <<"% on line " << lines_processed_ << ". Extruded " << extruder_current.e_relative << "mm over " << movement_length_mm << "mm of travel (" << mm_extruded_per_mm_travel << "mm/mm). Previous rate: " << previous_extrusion_rate_ << "mm/mm.";
+ p_logger_->log(logger_type_, DEBUG, stream.str());
}
else
{
@@ -617,9 +642,12 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end, bool is_reprocess
}
}
}
+
+ // Reset the previous extrusion rate
+ previous_extrusion_rate_ = 0;
}
- previous_extrusion_rate_ = mm_extruded_per_mm_travel;
+
if (!arc_added && !(cmd.is_empty && cmd.comment.length() == 0))
{
@@ -844,6 +872,7 @@ void arc_welder::add_arcwelder_comment_to_target()
stream << std::fixed;
stream << "; Postprocessed by [ArcWelder](https://github.com/FormerLurker/ArcWelderLib)\n";
stream << "; Copyright(C) 2020 - Brad Hochgesang\n";
+ stream << "; Version: " << GIT_TAGGED_VERSION << ", Branch: " << GIT_BRANCH << ", BuildDate: " << BUILD_DATE << "\n";
stream << "; resolution=" << std::setprecision(2) << resolution_mm_ << "mm\n";
stream << "; path_tolerance=" << std::setprecision(0) << (current_arc_.get_path_tolerance_percent() * 100.0) << "%\n";
stream << "; max_radius=" << std::setprecision(2) << (current_arc_.get_max_radius()) << "mm\n";