diff options
author | FormerLurker <hochgebe@gmail.com> | 2020-11-20 23:40:10 +0300 |
---|---|---|
committer | FormerLurker <hochgebe@gmail.com> | 2020-11-20 23:40:10 +0300 |
commit | 4f2fef2779e4cac3d31eb2ba4181416efb6a6bab (patch) | |
tree | 7f4adcdc7e46d5cb8812b9235a20a73cfdc27050 /ArcWelder | |
parent | 995ec6d5b35cf8ae23dabb74065fdafdcc843740 (diff) |
Add -z parameter to console app to support arcs, take z into account when calculating spiral length.
Diffstat (limited to 'ArcWelder')
-rw-r--r-- | ArcWelder/arc_welder.cpp | 28 | ||||
-rw-r--r-- | ArcWelder/arc_welder.h | 2 | ||||
-rw-r--r-- | ArcWelder/segmented_arc.cpp | 9 | ||||
-rw-r--r-- | ArcWelder/segmented_arc.h | 2 | ||||
-rw-r--r-- | ArcWelder/segmented_shape.cpp | 19 | ||||
-rw-r--r-- | ArcWelder/segmented_shape.h | 4 |
6 files changed, 47 insertions, 17 deletions
diff --git a/ArcWelder/arc_welder.cpp b/ArcWelder/arc_welder.cpp index 7f78c3c..c9cd465 100644 --- a/ArcWelder/arc_welder.cpp +++ b/ArcWelder/arc_welder.cpp @@ -188,7 +188,8 @@ arc_welder_results results; source_path_ << "', target_file_path:'" << target_path_ << "', resolution_mm:" << resolution_mm_ << "mm (+-" << current_arc_.get_resolution_mm() << "mm), path_tolerance_percent: " << current_arc_.get_path_tolerance_percent() << ", max_radius_mm:" << current_arc_.get_max_radius() - << ", g90_91_influences_extruder: " << (p_source_position_->get_g90_91_influences_extruder() ? "True" : "False"); + << ", g90_91_influences_extruder: " << (p_source_position_->get_g90_91_influences_extruder() ? "True" : "False") + << ", allow_z_axis_changes: " << (allow_z_axis_changes_ ? "True" : "False"); p_logger_->log(logger_type_, INFO, stream.str()); @@ -416,13 +417,12 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end, bool is_reprocess } } + bool z_axis_ok = allow_z_axis_changes_ || + utilities::is_equal(p_cur_pos->z, p_pre_pos->z); + if ( !is_end && cmd.is_known_command && !cmd.is_empty && ( - is_g1_g2 && - ( - allow_z_axis_changes_ || - utilities::is_equal(p_cur_pos->z, p_pre_pos->z) - ) && + is_g1_g2 && z_axis_ok && utilities::is_equal(p_cur_pos->x_offset, p_pre_pos->x_offset) && utilities::is_equal(p_cur_pos->y_offset, p_pre_pos->y_offset) && utilities::is_equal(p_cur_pos->z_offset, p_pre_pos->z_offset) && @@ -474,9 +474,7 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end, bool is_reprocess { p_logger_->log(logger_type_, DEBUG, "Adding point to arc from Gcode:" + cmd.gcode); } - { - p_logger_->log(logger_type_, DEBUG, "Removed start point from arc and added a new point from Gcode:" + cmd.gcode); - } + } } } @@ -561,7 +559,7 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end, bool is_reprocess } } - if (!arc_added) + if (!arc_added && !(cmd.is_empty && cmd.comment.length() == 0)) { if (current_arc_.get_num_segments() < current_arc_.get_min_segments()) { if (debug_logging_enabled_ && !cmd.is_empty) @@ -690,7 +688,15 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end, bool is_reprocess if (p_cur_pos->has_xy_position_changed && (cur_extruder.is_extruding || cur_extruder.is_retracting)) { position* prev_pos = p_source_position_->get_previous_position_ptr(); - length = utilities::get_cartesian_distance(cur_pos->x, cur_pos->y, prev_pos->x, prev_pos->y); + length = 0; + if (allow_z_axis_changes_) + { + length = utilities::get_cartesian_distance(cur_pos->x, cur_pos->y, cur_pos->z, prev_pos->x, prev_pos->y, prev_pos->z); + } + else { + length = utilities::get_cartesian_distance(cur_pos->x, cur_pos->y, prev_pos->x, prev_pos->y); + } + } unwritten_commands_.push_back(unwritten_command(cur_pos, length)); diff --git a/ArcWelder/arc_welder.h b/ArcWelder/arc_welder.h index 0c2b3ea..5577267 100644 --- a/ArcWelder/arc_welder.h +++ b/ArcWelder/arc_welder.h @@ -407,7 +407,7 @@ struct arc_welder_results { std::string message; arc_welder_progress progress; }; -#define DEFAULT_GCODE_BUFFER_SIZE 100 +#define DEFAULT_GCODE_BUFFER_SIZE 1000 #define DEFAULT_G90_G91_INFLUENCES_EXTRUDER false class arc_welder { diff --git a/ArcWelder/segmented_arc.cpp b/ArcWelder/segmented_arc.cpp index f1cc66d..5f8701f 100644 --- a/ArcWelder/segmented_arc.cpp +++ b/ArcWelder/segmented_arc.cpp @@ -155,11 +155,18 @@ bool segmented_arc::try_add_point(point p, double e_relative) { // If we haven't added a point, and we have exactly min_segments_, // pull off the initial arc point and try again + point old_initial_point = points_.pop_front(); // We have to remove the distance and e relative value // accumulated between the old arc start point and the new point new_initial_point = points_[0]; - original_shape_length_ -= utilities::get_cartesian_distance(old_initial_point.x, old_initial_point.y, new_initial_point.x, new_initial_point.y); + if (allow_z_axis_changes_) { + original_shape_length_ -= utilities::get_cartesian_distance(old_initial_point.x, old_initial_point.y, old_initial_point.z, new_initial_point.x, new_initial_point.y, new_initial_point.z); + } + else { + original_shape_length_ -= utilities::get_cartesian_distance(old_initial_point.x, old_initial_point.y, new_initial_point.x, new_initial_point.y); + } + e_relative_ -= new_initial_point.e_relative; //std::cout << " failed - removing start point and retrying current point.\n"; return try_add_point(p, e_relative); diff --git a/ArcWelder/segmented_arc.h b/ArcWelder/segmented_arc.h index 5bbdf34..9af5f25 100644 --- a/ArcWelder/segmented_arc.h +++ b/ArcWelder/segmented_arc.h @@ -28,7 +28,7 @@ #include <iomanip> #include <sstream> -#define GCODE_CHAR_BUFFER_SIZE 100 +#define GCODE_CHAR_BUFFER_SIZE 1000 class segmented_arc : public segmented_shape diff --git a/ArcWelder/segmented_shape.cpp b/ArcWelder/segmented_shape.cpp index 170b1df..77448c0 100644 --- a/ArcWelder/segmented_shape.cpp +++ b/ArcWelder/segmented_shape.cpp @@ -381,6 +381,15 @@ bool arc::try_create_arc( // but also could indicate that our vector calculation above // got the direction wrong double arc_length = c.radius * angle_radians; + + if (allow_z_axis_changes) + { + // We may be traveling in 3 space, calculate the arc_length of the spiral + if (start_point.z != end_point.z) + { + arc_length = std::hypot(arc_length, end_point.z - start_point.z); + } + } // Calculate the percent difference of the original path double difference = (arc_length - approximate_length) / approximate_length; if (!utilities::is_zero(difference, path_tolerance_percent)) @@ -395,6 +404,14 @@ bool arc::try_create_arc( double test_radians = std::abs(angle_radians - 2 * PI_DOUBLE); // Calculate the length of that arc double test_arc_length = c.radius * test_radians; + if (allow_z_axis_changes) + { + // We may be traveling in 3 space, calculate the arc_length of the spiral + if (start_point.z != end_point.z) + { + test_arc_length = std::hypot(arc_length, end_point.z - start_point.z); + } + } difference = (test_arc_length - approximate_length) / approximate_length; if (!utilities::is_zero(difference, path_tolerance_percent)) { @@ -408,7 +425,7 @@ bool arc::try_create_arc( if (allow_z_axis_changes) { // Ensure the perimeter of the arc is less than that of a full circle - double perimeter = c.radius * 2.0 * PI_DOUBLE; + double perimeter = std::hypot(c.radius * 2.0 * PI_DOUBLE, end_point.z - start_point.z); if (perimeter <= approximate_length) { return false; } diff --git a/ArcWelder/segmented_shape.h b/ArcWelder/segmented_shape.h index ac9b1db..3c8da0f 100644 --- a/ArcWelder/segmented_shape.h +++ b/ArcWelder/segmented_shape.h @@ -25,7 +25,7 @@ #pragma once #include <string> #include <limits> -#define PI_DOUBLE 3.14159265358979323846 +#define PI_DOUBLE 3.14159265358979323846264338327950288 #include <list> #include "utilities.h" @@ -121,7 +121,7 @@ struct circle { }; #define DEFAULT_RESOLUTION_MM 0.05 -#define DEFAULT_ALLOW_Z_AXIS_CHANGES true +#define DEFAULT_ALLOW_Z_AXIS_CHANGES false struct arc : circle { arc() { |