diff options
author | FormerLurker <hochgebe@gmail.com> | 2020-05-02 18:49:25 +0300 |
---|---|---|
committer | FormerLurker <hochgebe@gmail.com> | 2020-05-02 18:49:25 +0300 |
commit | 39f4cd7fe66d7b9ec331d0e498c5caf3b8c916ec (patch) | |
tree | 2bb9b1e29b5f6261a7437581b2c96c26edb9cd5a | |
parent | 8d7b572cc7fa7faf795db88a29340b6380090f8f (diff) |
Remove absolute and relative extrusion adjustments since they are insignificant, and most firmware doesn't adjust E when interpolating segments.
-rw-r--r-- | ArcWelder/arc_welder.cpp | 144 | ||||
-rw-r--r-- | ArcWelder/arc_welder.h | 5 | ||||
-rw-r--r-- | ArcWelder/segmented_arc.cpp | 89 | ||||
-rw-r--r-- | ArcWelderTest/ArcWelderTest.cpp | 2 |
4 files changed, 17 insertions, 223 deletions
diff --git a/ArcWelder/arc_welder.cpp b/ArcWelder/arc_welder.cpp index 458b8e5..de89646 100644 --- a/ArcWelder/arc_welder.cpp +++ b/ArcWelder/arc_welder.cpp @@ -43,7 +43,6 @@ arc_welder::arc_welder(std::string source_path, std::string target_path, logger logger_type_ = 0; progress_callback_ = NULL; verbose_output_ = false; - absolute_e_offset_total_ = 0; source_path_ = source_path; target_path_ = target_path; resolution_mm_ = resolution_mm; @@ -57,7 +56,6 @@ arc_welder::arc_welder(std::string source_path, std::string target_path, logger arcs_created_ = 0; waiting_for_line_ = false; waiting_for_arc_ = false; - absolute_e_offset_ = 0; gcode_position_args_.set_num_extruders(8); for (int index = 0; index < 8; index++) { @@ -69,19 +67,6 @@ arc_welder::arc_welder(std::string source_path, std::string target_path, logger // We don't care about the printer settings, except for g91 influences extruder. p_source_position_ = new gcode_position(gcode_position_args_); - - // Create a list of commands that will need rewritten absolute e values - std::vector<std::string> absolute_e_rewrite_command_names; - absolute_e_rewrite_command_names.push_back("G0"); - absolute_e_rewrite_command_names.push_back("G1"); - absolute_e_rewrite_command_names.push_back("G2"); - absolute_e_rewrite_command_names.push_back("G3"); - //absolute_e_rewrite_command_names.push_back("G92"); - - for (unsigned int index = 0; index < absolute_e_rewrite_command_names.size(); index++) - { - absolute_e_rewrite_commands_.insert(absolute_e_rewrite_command_names[index]); - } } arc_welder::arc_welder(std::string source_path, std::string target_path, logger* log, double resolution_mm, bool g90_g91_influences_extruder, int buffer_size) @@ -149,7 +134,6 @@ void arc_welder::reset() arcs_created_ = 0; waiting_for_line_ = false; waiting_for_arc_ = false; - absolute_e_offset_ = 0; } long arc_welder::get_file_size(const std::string& file_path) @@ -332,8 +316,6 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end) bool arc_added = false; bool clear_shapes = false; - - // 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 // TODO: Handle relative XYZ axis. This is possible, but maybe not so important. if ( @@ -354,6 +336,7 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end) if (!waiting_for_arc_) { + previous_feedrate_ = p_pre_pos->f; if (debug_logging_enabled_) { p_logger_->log(logger_type_, DEBUG, "Starting new arc from Gcode:" + cmd.gcode); @@ -501,22 +484,17 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end) { unwritten_commands_.pop_back(); } - // get the feedrate for the previous position + // get the feedrate for the previous position (the last command that was turned into an arc) double current_f = p_pre_pos->f; + // Undo the current command, since it isn't included in the arc + p_source_position_->undo_update(); // IMPORTANT NOTE: p_cur_pos and p_pre_pos will NOT be usable beyond this point. p_pre_pos = NULL; p_cur_pos = NULL; - // Undo the previous updates that will be turned into the arc, including the current position - // (so not num_segments - 1, but num_segments) - for (int index = 0; index < current_arc_.get_num_segments(); index++) - { - undo_commands_.push_back(p_source_position_->get_current_position_ptr()->command); - p_source_position_->undo_update(); - } - + // Set the current feedrate if it is different, else set to 0 to indicate that no feedrate should be included - if(p_source_position_->get_current_position_ptr()->f == current_f) + if(previous_feedrate_ > 0 && previous_feedrate_ == current_f) { current_f = 0; } @@ -529,60 +507,16 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end) p_logger_->log(logger_type_, DEBUG, "Arc created with " + std::to_string(current_arc_.get_num_segments()) + " segments: " + gcode); } - // parse the arc gcode - parsed_command new_command; - bool parsed = parser_.try_parse_gcode(gcode.c_str(), new_command); - if (!parsed) - { - if (error_logging_enabled_) - { - p_logger_->log_exception(logger_type_, "Unable to parse arc command! Fatal Error."); - } - throw std::exception(); - } - // update the position processor and add the command to the unwritten commands list - p_source_position_->update(new_command, lines_processed_, gcodes_processed_, -1); - unwritten_commands_.push_back(unwritten_command(p_source_position_->get_current_position_ptr())); + // Get and alter the current position so we can add it to the unwritten commands list + parsed_command arc_command = parser_.parse_gcode(gcode.c_str()); + unwritten_commands_.push_back( + unwritten_command(arc_command, p_source_position_->get_current_position_ptr()->is_extruder_relative) + ); // write all unwritten commands (if we don't do this we'll mess up absolute e by adding an offset to the arc) // including the most recent arc command BEFORE updating the absolute e offset write_unwritten_gcodes_to_file(); - - // If the e values are not equal, use G91 to adjust the current absolute e position - double difference = 0; - double new_e_rel_relative = p_source_position_->get_current_position().get_current_extruder().e_relative; - double old_e_relative = current_arc_.get_shape_e_relative(); - - // See if any offset needs to be applied for absolute E coordinates - if ( - !utilities::is_equal(new_e_rel_relative, old_e_relative)) - { - // Calculate the difference between the original absolute e and - // change made by G2/G3 - difference = new_e_rel_relative - old_e_relative; - // Adjust the absolute E offset based on the difference - // We need to do this AFTER writing the modified gcode(arc), since the - // difference is based on that. - absolute_e_offset_ += difference; - if (debug_logging_enabled_) - { - p_logger_->log(logger_type_, DEBUG, "Adjusting absolute extrusion by " + utilities::to_string(difference) + "mm. New Offset: " + utilities::to_string(difference)); - } - } - - // Undo the arc update and re-apply the original commands to the position processor so that subsequent - // gcodes in the file are interpreted properly. Do NOT add the most recent command - // since it will be reprocessed - p_source_position_->undo_update(); - - for (int index = current_arc_.get_num_segments() - 1; index > 0; index--) - { - parsed_command cmd = undo_commands_.pop_back(); - p_source_position_->update(undo_commands_[index], lines_processed_, gcodes_processed_, -1); - } - // Clear the undo commands (there should be one left) - undo_commands_.clear(); // Now clear the arc and flag the processor as not waiting for an arc waiting_for_arc_ = false; current_arc_.clear(); @@ -636,23 +570,6 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end) { write_unwritten_gcodes_to_file(); } - if (cmd.command == "G92") - { - // See if there is an E parameter - for (unsigned int parameter_index = 0; parameter_index < cmd.parameters.size(); parameter_index++) - { - parsed_command_parameter param = cmd.parameters[parameter_index]; - if (param.name == "E") - { - absolute_e_offset_ = 0; - if (debug_logging_enabled_) - { - p_logger_->log(logger_type_, DEBUG, "G92 found that set E axis, resetting absolute offset."); - } - } - } - } - return lines_written; } @@ -702,44 +619,7 @@ int arc_welder::write_unwritten_gcodes_to_file() { // The the current unwritten position and remove it from the list unwritten_command p = unwritten_commands_.pop_front(); - bool has_e_coordinate = false; - std::string additional_comment = ""; - double old_e = p.offset_e; - double new_e = old_e; - if (!p.is_extruder_relative && utilities::greater_than(abs(absolute_e_offset_), 0.0) && - absolute_e_rewrite_commands_.find(p.command.command) != absolute_e_rewrite_commands_.end() - ){ - // handle any absolute extrusion shift - // There is an offset, and we are in absolute E. Rewrite the gcode - parsed_command new_command = p.command; - new_command.parameters.clear(); - has_e_coordinate = false; - for (unsigned int index = 0; index < p.command.parameters.size(); index++) - { - parsed_command_parameter p_cur_param = p.command.parameters[index]; - if (p_cur_param.name == "E") - { - has_e_coordinate = true; - if (p_cur_param.value_type == 'U') - { - p_cur_param.value_type = 'F'; - } - new_e = p.offset_e + absolute_e_offset_; - p_cur_param.double_value = new_e; - - } - new_command.parameters.push_back(p_cur_param); - } - - - if (has_e_coordinate) - { - p.command = new_command; - } - } - - write_gcode_to_file(p.to_string(has_e_coordinate, additional_comment)); - + write_gcode_to_file(p.command.to_string()); } return size; diff --git a/ArcWelder/arc_welder.h b/ArcWelder/arc_welder.h index c64c7bd..7e75038 100644 --- a/ArcWelder/arc_welder.h +++ b/ArcWelder/arc_welder.h @@ -130,16 +130,13 @@ private: bool waiting_for_line_; bool waiting_for_arc_; array_list<unwritten_command> unwritten_commands_; - array_list<parsed_command> undo_commands_; segmented_arc current_arc_; std::ofstream output_file_; // We don't care about the printer settings, except for g91 influences extruder. gcode_position * p_source_position_; - double absolute_e_offset_; - std::set<std::string> absolute_e_rewrite_commands_; + double previous_feedrate_ = -1; gcode_parser parser_; - double absolute_e_offset_total_; bool verbose_output_; int logger_type_; logger* p_logger_; diff --git a/ArcWelder/segmented_arc.cpp b/ArcWelder/segmented_arc.cpp index 94c89fb..f51bf6a 100644 --- a/ArcWelder/segmented_arc.cpp +++ b/ArcWelder/segmented_arc.cpp @@ -213,23 +213,6 @@ bool segmented_arc::does_circle_fit_points(circle c, point p, double pd) } } - /* - // Check the midpoints of the segments in the points_ to make sure they fit our circle. - for (int index = 0; index < points_.count() - 1; index++) - { - // Make sure the length from the center of our circle to the test point is - // at or below our max distance. - point midpoint = point::get_midpoint(points_[index], points_[index + 1]); - distance_from_center = utilities::get_cartesian_distance(midpoint.x, midpoint.y, c.center.x, c.center.y); - difference_from_radius = abs(distance_from_center - c.radius); - // Test allowing more play for the midpoints. - if (utilities::greater_than(difference_from_radius, resolution_mm_)) - { - //std::cout << " failed - midpoints do not lie on circle.\n"; - return false; - } - } - */ // Check the point perpendicular from the segment to the circle's center, if any such point exists for (int index = 0; index < points_.count() - 1; index++) { @@ -263,14 +246,7 @@ bool segmented_arc::does_circle_fit_points(circle c, point p, double pd) // get the current arc and compare the total length to the original length arc a; return try_get_arc(c, p, pd, a ); - /* - if (!a.is_arc || utilities::greater_than(abs(a.length - (original_shape_length_ + pd)), resolution_mm_*2)) - { - //std::cout << " failed - final lengths do not match.\n"; - return false; - } - return true; - */ + } bool segmented_arc::try_get_arc(arc & target_arc) @@ -284,71 +260,12 @@ bool segmented_arc::try_get_arc(circle& c, point endpoint, double additional_dis int mid_point_index = ((points_.count() - 1) / 2) + 1; return arc::try_create_arc(c, points_[0], points_[mid_point_index], endpoint, original_shape_length_ + additional_distance, resolution_mm_, target_arc); } -/* - -std::string segmented_arc::get_shape_gcode_absolute(double f, double e_abs_start) -{ - - s_stream_.clear(); - s_stream_.str(""); - arc c; - try_get_arc(c); - - double new_extrusion; - // get the original ratio of filament extruded to length, but not for retractions - if (utilities::greater_than(e_relative_, 0)) - { - double extrusion_per_mm = e_relative_ / original_shape_length_; - new_extrusion = c.length * extrusion_per_mm; - } - else - { - new_extrusion = e_relative_; - } - - - double i = c.center.x - c.start_point.x; - double j = c.center.y - c.start_point.y; - if (utilities::less_than(c.angle_radians, 0)) - { - s_stream_ << "G2"; - } - else - { - s_stream_ << "G3"; - } - s_stream_ << std::setprecision(3); - s_stream_ << " X" << c.end_point.x << " Y" << c.end_point.y << " I" << i << " J" << j; - // Do not output for travel movements - if (e_relative_ != 0) - { - s_stream_ << std::setprecision(5); - s_stream_ << " E" << e_abs_start + new_extrusion; - } - - if (utilities::greater_than(f, 0)) - { - s_stream_ << std::setprecision(0) << " F" << f; - } - return s_stream_.str(); -}*/ std::string segmented_arc::get_shape_gcode_absolute(double f, double e_abs_start) { arc c; try_get_arc(c); - double new_extrusion; - // get the original ratio of filament extruded to length, but not for retractions - if (utilities::greater_than(e_relative_, 0)) - { - double extrusion_per_mm = e_relative_ / original_shape_length_; - new_extrusion = c.length * extrusion_per_mm; - } - else - { - new_extrusion = e_relative_; - } double i = c.center.x - c.start_point.x; double j = c.center.y - c.start_point.y; // Here is where the performance part kicks in (these are expensive calls) that makes things a bit ugly. @@ -358,7 +275,7 @@ std::string segmented_arc::get_shape_gcode_absolute(double f, double e_abs_start // G2 if (e_relative_ != 0) { - double e = e_abs_start + new_extrusion; + double e = e_abs_start + e_relative_; // Add E param if (utilities::greater_than_or_equal(f, 1)) { @@ -392,7 +309,7 @@ std::string segmented_arc::get_shape_gcode_absolute(double f, double e_abs_start // G3 if (e_relative_ != 0) { - double e = e_abs_start + new_extrusion; + double e = e_abs_start + e_relative_; // Add E param if (utilities::greater_than_or_equal(f, 1)) { diff --git a/ArcWelderTest/ArcWelderTest.cpp b/ArcWelderTest/ArcWelderTest.cpp index 4988988..bc6d380 100644 --- a/ArcWelderTest/ArcWelderTest.cpp +++ b/ArcWelderTest/ArcWelderTest.cpp @@ -239,7 +239,7 @@ static void TestAntiStutter(std::string filePath) logger* p_logger = new logger(logger_names, logger_levels); p_logger->set_log_level(INFO); //arc_welder arc_welder_obj(BENCHY_0_5_MM_NO_WIPE, "C:\\Users\\Brad\\Documents\\3DPrinter\\AntiStutter\\test_output.gcode", p_logger, max_resolution, false, 50, static_cast<progress_callback>(on_progress)); - arc_welder arc_welder_obj(SIX_SPEED_TEST, "C:\\Users\\Brad\\Documents\\3DPrinter\\AntiStutter\\test_output.gcode", p_logger, max_resolution, false, 50, on_progress); + //arc_welder arc_welder_obj(SIX_SPEED_TEST, "C:\\Users\\Brad\\Documents\\3DPrinter\\AntiStutter\\test_output.gcode", p_logger, max_resolution, false, 50, on_progress); arc_welder arc_welder_obj(SIX_SPEED_TEST, "C:\\Users\\Brad\\Documents\\3DPrinter\\AntiStutter\\SixSpeedTest_AS.gcode", p_logger, max_resolution, false, 50, on_progress); //BENCHY_LAYER_1GCODE //SMALL_TEST |