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:
authorFormerLurker <hochgebe@gmail.com>2021-01-11 05:00:15 +0300
committerFormerLurker <hochgebe@gmail.com>2021-01-11 05:00:15 +0300
commitb6a676692ae9137f8613b13f6734440d4d7ff328 (patch)
tree71e7d8be960e005423af53e43d1428136328c968
parent794e853bfd5c21c97457c4070cfc1633e233b003 (diff)
Debug Late Arc Checking
-rw-r--r--ArcWelder/arc_welder.cpp26
-rw-r--r--ArcWelder/arc_welder.h1
-rw-r--r--ArcWelder/segmented_arc.cpp6
-rw-r--r--ArcWelder/segmented_arc.h2
-rw-r--r--ArcWelder/segmented_shape.cpp56
-rw-r--r--ArcWelderTest/ArcWelderTest.cpp6
-rw-r--r--ArcWelderTest/ArcWelderTest.h1
-rw-r--r--GcodeProcessorLib/utilities.h4
8 files changed, 64 insertions, 38 deletions
diff --git a/ArcWelder/arc_welder.cpp b/ArcWelder/arc_welder.cpp
index c96eb2d..d4b4e67 100644
--- a/ArcWelder/arc_welder.cpp
+++ b/ArcWelder/arc_welder.cpp
@@ -92,7 +92,6 @@ arc_welder::arc_welder(
arcs_created_ = 0;
waiting_for_arc_ = false;
previous_feedrate_ = -1;
- previous_is_extruder_relative_ = false;
gcode_position_args_.set_num_extruders(8);
for (int index = 0; index < 8; index++)
{
@@ -456,7 +455,6 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end, bool is_reprocess
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, extruder_current.get_offset_e(), movement_length_mm);
if (!waiting_for_arc_)
{
- previous_is_extruder_relative_ = p_pre_pos->is_extruder_relative;
if (debug_logging_enabled_)
{
p_logger_->log(logger_type_, DEBUG, "Starting new arc from Gcode:" + cmd.gcode);
@@ -589,19 +587,15 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end, bool is_reprocess
}
else if (waiting_for_arc_)
{
-
if (current_arc_.is_shape())
{
write_arc_gcodes(p_pre_pos->is_extruder_relative, p_pre_pos->f);
// IMPORTANT NOTE: p_cur_pos and p_pre_pos will NOT be usable beyond this point.
p_pre_pos = NULL;
p_cur_pos = NULL;
-
- // Now clear the arc and flag the processor as not waiting for an arc
- waiting_for_arc_ = false;
- current_arc_.clear();
-
+ // Now clear the arc and flag the processor as not waiting for an arc
+ waiting_for_arc_ = current_arc_.get_num_segments() > 0;
// Reprocess this line
if (!is_end)
{
@@ -615,6 +609,8 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end, bool is_reprocess
}
return 0;
}
+
+
}
else
@@ -624,7 +620,6 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end, bool is_reprocess
p_logger_->log(logger_type_, DEBUG, "The current arc is not a valid arc, resetting.");
}
current_arc_.clear();
- waiting_for_arc_ = false;
}
}
else if (debug_logging_enabled_)
@@ -649,7 +644,7 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end, bool is_reprocess
void arc_welder::write_arc_gcodes(bool is_extruder_relative, double previous_feedrate)
{
-
+ bool test_current_arc = true;
// Loop through each generated arc
int num_points;
arc current_arc;
@@ -673,7 +668,8 @@ void arc_welder::write_arc_gcodes(bool is_extruder_relative, double previous_fee
while (current_arc_.get_num_segments() > 2)
{
// try to create an arc from the current points
- bool arc_created = current_arc_.get_next_arc(current_arc, num_points);
+ bool arc_created = current_arc_.get_next_arc(current_arc, num_points, test_current_arc);
+ test_current_arc = false;
if (!arc_created)
{
@@ -719,7 +715,7 @@ void arc_welder::write_arc_gcodes(bool is_extruder_relative, double previous_fee
{
char buffer[20];
std::string message = "Arc created with ";
- sprintf(buffer, "%d", current_arc_.get_num_segments());
+ sprintf(buffer, "%d", num_points);
message += buffer;
message += " segments: ";
message += gcode;
@@ -739,7 +735,11 @@ void arc_welder::write_arc_gcodes(bool is_extruder_relative, double previous_fee
// 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();
+ //write_unwritten_gcodes_to_file();
+
+
+ //current_arc_.clear();
+
}
std::string arc_welder::get_comment_for_arc(int num_points)
diff --git a/ArcWelder/arc_welder.h b/ArcWelder/arc_welder.h
index 05776c4..2429bdb 100644
--- a/ArcWelder/arc_welder.h
+++ b/ArcWelder/arc_welder.h
@@ -477,7 +477,6 @@ private:
// We don't care about the printer settings, except for g91 influences extruder.
gcode_position* p_source_position_;
double previous_feedrate_;
- bool previous_is_extruder_relative_;
gcode_parser parser_;
bool verbose_output_;
int logger_type_;
diff --git a/ArcWelder/segmented_arc.cpp b/ArcWelder/segmented_arc.cpp
index 2b487b9..b0fafc3 100644
--- a/ArcWelder/segmented_arc.cpp
+++ b/ArcWelder/segmented_arc.cpp
@@ -256,7 +256,7 @@ bool segmented_arc::try_add_point_internal_(printer_point p)
}
-bool segmented_arc::get_next_arc(arc& arc, int& num_points)
+bool segmented_arc::get_next_arc(arc& arc, int& num_points, bool test_current_arc)
{
num_points = 0;
if (points_.count() < 3)
@@ -268,7 +268,7 @@ bool segmented_arc::get_next_arc(arc& arc, int& num_points)
// update it as we return arcs and pop points.
// Test for the most common case, which is a valid arc. This will speed things up a ton for very large circles.
- if (arc::are_points_within_slice(current_arc_, points_, points_.count()))
+ if (test_current_arc && arc::are_points_within_slice(current_arc_, points_, points_.count()))
{
arc = current_arc_;
arc.e_relative = e_relative_;
@@ -291,7 +291,7 @@ bool segmented_arc::get_next_arc(arc& arc, int& num_points)
original_shape_length_ -= arc.original_shape_length;
// Remove the points we've added to the arc
- for (int index = 0; index < num_points; index++)
+ for (int index = 0; index < num_points-1; index++)
{
points_.pop_front();
}
diff --git a/ArcWelder/segmented_arc.h b/ArcWelder/segmented_arc.h
index 31b97d0..1126e96 100644
--- a/ArcWelder/segmented_arc.h
+++ b/ArcWelder/segmented_arc.h
@@ -48,7 +48,7 @@ public:
virtual bool try_add_point(printer_point p);
virtual double get_shape_length();
- bool get_next_arc(arc &arc, int& num_points);
+ bool get_next_arc(arc &arc, int& num_points, bool test_current_arc);
static std::string get_shape_gcode(const arc& arc, bool is_relative, double f, unsigned char xyz_precision, unsigned char e_precision, double xyz_tolerance);
//std::string get_shape_gcode_absolute(double e, double f);
diff --git a/ArcWelder/segmented_shape.cpp b/ArcWelder/segmented_shape.cpp
index 68bab79..e048f22 100644
--- a/ArcWelder/segmented_shape.cpp
+++ b/ArcWelder/segmented_shape.cpp
@@ -656,7 +656,7 @@ bool arc::try_create_first_arc(
// we have to loop through each point, starting with the first 3 (3 points are required for an arc)
// and see how many points we can add before running into an error
int max_index_found = -1;
- arc test_arc;
+
circle test_circle;
if (points.count() < 3)
@@ -679,7 +679,7 @@ bool arc::try_create_first_arc(
approximate_length += points[index].distance;
e_relative += points[index].e_relative;
int mid_point_index = ((index - 1) / 2) + 1;
-
+ arc test_arc;
if (!arc::try_create_arc(test_circle, points[0], points[mid_point_index], points[index], test_arc, approximate_length, resolution_mm, path_tolerance_percent, allow_3d_arcs))
{
break;
@@ -687,6 +687,7 @@ bool arc::try_create_first_arc(
if (arc::are_points_within_slice(test_arc, points, index + 1))
{
max_index_found = index;
+ target_arc = test_arc;
}
else
{
@@ -695,7 +696,6 @@ bool arc::try_create_first_arc(
}
if (max_index_found > -1)
{
- target_arc = test_arc;
target_arc.offset_e = points[max_index_found].offset_e;
target_arc.e_relative = e_relative;
num_points = max_index_found + 1;
@@ -709,11 +709,22 @@ bool arc::are_points_within_slice(const arc& test_arc, const array_list<printer_
// Loop through the points and see if they fit inside of the angles
double previous_polar = test_arc.polar_start_theta;
+ bool will_cross_zero = false;
bool crossed_zero = false;
point start_norm((test_arc.start_point.x - test_arc.center.x) / test_arc.radius, (test_arc.start_point.y - test_arc.center.y) / test_arc.radius, 0.0);
point end_norm((test_arc.end_point.x - test_arc.center.x) / test_arc.radius, (test_arc.end_point.y - test_arc.center.y) / test_arc.radius, 0.0);
-
+
+ if (test_arc.direction == DirectionEnum::COUNTERCLOCKWISE)
+ {
+ will_cross_zero = test_arc.polar_start_theta > test_arc.polar_end_theta;
+ }
+ else
+ {
+ will_cross_zero = test_arc.polar_start_theta < test_arc.polar_end_theta;
+ }
+
+ // Need to see if point 1 to point 2 cross zero
for (int index = 1; index < point_count; index++)
{
double polar_test;
@@ -732,12 +743,14 @@ bool arc::are_points_within_slice(const arc& test_arc, const array_list<printer_
// Only check to see if we are within the arc if this isn't the endpoint
if (index < point_count - 1)
{
- // First test to see if this point lies within the arc
- if (test_arc.polar_start_theta < test_arc.polar_end_theta && !(test_arc.polar_start_theta < polar_test && polar_test < test_arc.polar_end_theta))
+ if (will_cross_zero)
{
- return false;
+ if (!(polar_test > test_arc.polar_start_theta || polar_test < test_arc.polar_end_theta))
+ {
+ return false;
+ }
}
- else if (test_arc.polar_start_theta > test_arc.polar_end_theta && !(polar_test > test_arc.polar_start_theta || polar_test < test_arc.polar_end_theta))
+ else if (!(test_arc.polar_start_theta < polar_test && polar_test < test_arc.polar_end_theta))
{
return false;
}
@@ -745,31 +758,42 @@ bool arc::are_points_within_slice(const arc& test_arc, const array_list<printer_
// Now make sure the angles are increasing
if (previous_polar > polar_test)
{
+ if (!will_cross_zero)
+ {
+ return false;
+ }
+
// Allow the angle to cross zero once
if (crossed_zero)
{
return false;
}
- crossed_zero = true;
+ will_cross_zero = false;
}
}
else
{
if (index < point_count - 1)
{
- if (test_arc.polar_start_theta > test_arc.polar_end_theta && !(test_arc.polar_start_theta > polar_test && polar_test > test_arc.polar_end_theta))
+ if (will_cross_zero)
{
- return false;
+ if (!(polar_test < test_arc.polar_start_theta || polar_test > test_arc.polar_end_theta))
+ {
+ return false;
+ }
}
- else if (test_arc.polar_start_theta < test_arc.polar_end_theta && !(polar_test < test_arc.polar_start_theta || polar_test > test_arc.polar_end_theta))
+ else if (!(test_arc.polar_start_theta > polar_test && polar_test > test_arc.polar_end_theta))
{
return false;
}
}
-
// Now make sure the angles are decreasing
if (previous_polar < polar_test)
{
+ if (!will_cross_zero)
+ {
+ return false;
+ }
// Allow the angle to cross zero once
if (crossed_zero)
{
@@ -784,6 +808,12 @@ bool arc::are_points_within_slice(const arc& test_arc, const array_list<printer_
return false;
previous_polar = polar_test;
}
+
+ if (will_cross_zero != crossed_zero)
+ {
+ return false;
+ }
+
return true;
}
diff --git a/ArcWelderTest/ArcWelderTest.cpp b/ArcWelderTest/ArcWelderTest.cpp
index 0630f11..323b7d1 100644
--- a/ArcWelderTest/ArcWelderTest.cpp
+++ b/ArcWelderTest/ArcWelderTest.cpp
@@ -293,7 +293,7 @@ static void TestAntiStutter(std::string filePath)
//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(
- BAD_ARC_DIRECTIONS_2,
+ BARBARIAN,
"C:\\Users\\Brad\\Documents\\3DPrinter\\AntiStutter\\test_output.gcode",
p_logger,
max_resolution,
@@ -416,7 +416,7 @@ bool TestProblemDoubles()
return result;
}
-
+/*
bool TestIsInCaselessTrim()
{
std::string test("This is a test");
@@ -428,4 +428,4 @@ bool TestIsInCaselessTrim()
const char* test_3[] = { "t1", "", "this is a test", NULL };
result = utilities::is_in_caseless_trim(test, test_3);
return result;
-} \ No newline at end of file
+} */ \ No newline at end of file
diff --git a/ArcWelderTest/ArcWelderTest.h b/ArcWelderTest/ArcWelderTest.h
index dff8139..e31f4ff 100644
--- a/ArcWelderTest/ArcWelderTest.h
+++ b/ArcWelderTest/ArcWelderTest.h
@@ -106,3 +106,4 @@ static std::string UNICODE_TEST = "C:\\Users\\Brad\\Documents\\3DPrinter\\AntiSt
+
diff --git a/GcodeProcessorLib/utilities.h b/GcodeProcessorLib/utilities.h
index 8765fa6..401bed4 100644
--- a/GcodeProcessorLib/utilities.h
+++ b/GcodeProcessorLib/utilities.h
@@ -39,10 +39,6 @@ public:
static bool less_than(double x, double y, double tolerance = ZERO_TOLERANCE);
static bool less_than_or_equal(double x, double y, double tolerance = ZERO_TOLERANCE);
- static bool is_equal_caseless(const std::string& lhs, const std::string& rhs);
- static bool is_equal_caseless_trim(const std::string& lhs, const std::string& rhs);
- static bool is_in_caseless_trim(const std::string& lhs, const char** rhs);
-
static double get_cartesian_distance(double x1, double y1, double x2, double y2);
static double get_cartesian_distance(double x1, double y1, double z1, double x2, double y2, double z2);
static std::string to_string(double value);