Skip to content

Commit 5e7920d

Browse files
committed
Fix for issue #34.
1 parent 11d11e4 commit 5e7920d

File tree

10 files changed

+57
-48
lines changed

10 files changed

+57
-48
lines changed

ArcWelder/arc_welder.cpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ arc_welder::arc_welder(
9292
arcs_created_ = 0;
9393
waiting_for_arc_ = false;
9494
previous_feedrate_ = -1;
95-
previous_is_extruder_relative_ = false;
9695
gcode_position_args_.set_num_extruders(8);
9796
for (int index = 0; index < 8; index++)
9897
{
@@ -386,6 +385,7 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end, bool is_reprocess
386385
p_source_position_->update(cmd, lines_processed_, gcodes_processed_, -1);
387386
position* p_cur_pos = p_source_position_->get_current_position_ptr();
388387
position* p_pre_pos = p_source_position_->get_previous_position_ptr();
388+
bool is_previous_extruder_relative = p_pre_pos->is_extruder_relative;
389389
extruder extruder_current = p_cur_pos->get_current_extruder();
390390
extruder previous_extruder = p_pre_pos->get_current_extruder();
391391
//std::cout << lines_processed_ << " - " << cmd.gcode << ", CurrentEAbsolute: " << cur_extruder.e <<", ExtrusionLength: " << cur_extruder.extrusion_length << ", Retraction Length: " << cur_extruder.retraction_length << ", IsExtruding: " << cur_extruder.is_extruding << ", IsRetracting: " << cur_extruder.is_retracting << ".\n";
@@ -455,7 +455,7 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end, bool is_reprocess
455455
// we can get more arcs.
456456
(previous_extruder.is_retracting && extruder_current.is_retracting)
457457
) &&
458-
p_cur_pos->is_extruder_relative == p_pre_pos->is_extruder_relative &&
458+
p_cur_pos->is_extruder_relative == is_previous_extruder_relative &&
459459
(!waiting_for_arc_ || p_pre_pos->f == p_cur_pos->f) && // might need to skip the waiting for arc check...
460460
(!waiting_for_arc_ || p_pre_pos->feature_type_tag == p_cur_pos->feature_type_tag)
461461
)
@@ -464,7 +464,6 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end, bool is_reprocess
464464
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);
465465
if (!waiting_for_arc_)
466466
{
467-
previous_is_extruder_relative_ = p_pre_pos->is_extruder_relative;
468467
if (debug_logging_enabled_)
469468
{
470469
p_logger_->log(logger_type_, DEBUG, "Starting new arc from Gcode:" + cmd.gcode);
@@ -581,6 +580,7 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end, bool is_reprocess
581580
}
582581
}
583582

583+
bool arc_generated = false;
584584
if (!arc_added && !(cmd.is_empty && cmd.comment.length() == 0))
585585
{
586586
if (current_arc_.get_num_segments() < current_arc_.get_min_segments()) {
@@ -604,10 +604,13 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end, bool is_reprocess
604604
points_compressed_ += current_arc_.get_num_segments()-1;
605605
arcs_created_++; // increment the number of generated arcs
606606
write_arc_gcodes(p_pre_pos->is_extruder_relative, p_pre_pos->f);
607+
// Now clear the arc and flag the processor as not waiting for an arc
608+
waiting_for_arc_ = false;
609+
arc_generated = true;
610+
current_arc_.clear();
607611
p_cur_pos = NULL;
608612
p_pre_pos = NULL;
609613

610-
611614
// Reprocess this line
612615
if (!is_end)
613616
{
@@ -642,13 +645,16 @@ int arc_welder::process_gcode(parsed_command cmd, bool is_end, bool is_reprocess
642645

643646
if (waiting_for_arc_ || !arc_added)
644647
{
645-
position* cur_pos = p_source_position_->get_current_position_ptr();
646-
unwritten_commands_.push_back(unwritten_command(cur_pos, movement_length_mm));
648+
// This might not work....
649+
//position* cur_pos = p_source_position_->get_current_position_ptr();
650+
651+
unwritten_commands_.push_back(unwritten_command(cmd, is_previous_extruder_relative, movement_length_mm));
647652

648653
}
649-
if (!waiting_for_arc_)
654+
else if (!waiting_for_arc_)
650655
{
651656
write_unwritten_gcodes_to_file();
657+
current_arc_.clear();
652658
}
653659
return lines_written;
654660
}
@@ -660,9 +666,10 @@ void arc_welder::write_arc_gcodes(bool is_extruder_relative, double current_feed
660666
// remove the same number of unwritten gcodes as there are arc segments, minus 1 for the start point
661667
// Which isn't a movement
662668
// note, skip the first point, it is the starting point
663-
for (int index = 0; index < current_arc_.get_num_segments() - 1; index++)
669+
int num_segments = current_arc_.get_num_segments() - 1;
670+
for (int index = 0; index < num_segments; index++)
664671
{
665-
unwritten_commands_.pop_back();
672+
while (!unwritten_commands_.pop_back().is_g1_g2);
666673
}
667674

668675
// Undo the current command, since it isn't included in the arc
@@ -675,7 +682,7 @@ void arc_welder::write_arc_gcodes(bool is_extruder_relative, double current_feed
675682

676683
// Craete the arc gcode
677684
std::string gcode;
678-
if (previous_is_extruder_relative_) {
685+
if (is_extruder_relative) {
679686
gcode = get_arc_gcode_relative(current_feedrate, comment);
680687
}
681688

@@ -703,9 +710,7 @@ void arc_welder::write_arc_gcodes(bool is_extruder_relative, double current_feed
703710
// now write the current arc to the file
704711
write_gcode_to_file(gcode);
705712

706-
// Now clear the arc and flag the processor as not waiting for an arc
707-
waiting_for_arc_ = false;
708-
current_arc_.clear();
713+
709714
}
710715

711716
std::string arc_welder::get_comment_for_arc()

ArcWelder/arc_welder.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,6 @@ class arc_welder
478478
// We don't care about the printer settings, except for g91 influences extruder.
479479
gcode_position* p_source_position_;
480480
double previous_feedrate_;
481-
bool previous_is_extruder_relative_;
482481
gcode_parser parser_;
483482
bool verbose_output_;
484483
int logger_type_;

ArcWelder/segmented_arc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class segmented_arc :
6262
bool try_add_point_internal_(printer_point p);
6363
std::string get_shape_gcode_(bool has_e, double e, double f) const;
6464
arc current_arc_;
65+
int num_gcode;
6566
double max_radius_mm_;
6667
int min_arc_segments_;
6768
double mm_per_arc_segment_;

ArcWelder/segmented_shape.cpp

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ point point::get_midpoint(point p1, point p2)
8080

8181
return point(x, y, z);
8282
}
83+
84+
bool point::is_near_collinear(const point& p1, const point& p2, const point& p3, double tolerance)
85+
{
86+
return fabs((p1.y - p2.y) * (p1.x - p3.x) - (p1.y - p3.y) * (p1.x - p2.x)) <= 1e-9;
87+
}
88+
8389
#pragma endregion Point Functions
8490

8591
#pragma region Segment Functions
@@ -133,34 +139,24 @@ double vector::cross_product_magnitude(vector v1, vector v2)
133139
// Users of this code must verify correctness for their application.
134140
// dot product (3D) which allows vector operations in arguments
135141
#define dot(u,v) ((u).x * (v).x + (u).y * (v).y + (u).z * (v).z)
142+
#define dotxy(u,v) ((u).x * (v).x + (u).y * (v).y)
136143
#define norm(v) sqrt(dot(v,v)) // norm = length of vector
137144
#define d(u,v) norm(u-v) // distance = norm of difference
138145

139-
double distance_from_segment(segment s, point p)
140-
{
141-
vector v = s.p2 - s.p1;
142-
vector w = p - s.p1;
143-
144-
double c1 = dot(w, v);
145-
if (c1 <= 0)
146-
return d(p, s.p1);
147-
148-
double c2 = dot(v, v);
149-
if (c2 <= c1)
150-
return d(p, s.p2);
151-
152-
double b = c1 / c2;
153-
point pb = s.p1 + (v * b);
154-
return d(p, pb);
155-
}
156-
157146
#pragma endregion Distance Calculation Source
158147

159148

160149
#pragma region Circle Functions
161150

151+
162152
bool circle::try_create_circle(const point& p1, const point& p2, const point& p3, const double max_radius, circle& new_circle)
163153
{
154+
if (point::is_near_collinear(p1,p2,p3, 0.001))
155+
{
156+
return false;
157+
}
158+
159+
164160
double x1 = p1.x;
165161
double y1 = p1.y;
166162
double x2 = p2.x;

ArcWelder/segmented_shape.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ struct point
4646
double y;
4747
double z;
4848
static point get_midpoint(point p1, point p2);
49+
static bool is_near_collinear(const point& p1, const point& p2, const point& p3, double percent_tolerance);
4950
};
5051

5152
struct printer_point : point
@@ -192,7 +193,6 @@ struct arc : circle
192193
double path_tolerance_percent = ARC_LENGTH_PERCENT_TOLERANCE_DEFAULT,
193194
bool allow_3d_arcs = DEFAULT_ALLOW_3D_ARCS);
194195
};
195-
double distance_from_segment(segment s, point p);
196196

197197
#define DEFAULT_MIN_SEGMENTS 3
198198
#define DEFAULT_MAX_SEGMENTS 50

ArcWelder/unwritten_command.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,27 @@ struct unwritten_command
3232
e_relative = 0;
3333
offset_e = 0;
3434
extrusion_length = 0;
35+
is_g1_g2 = false;
3536
}
3637
unwritten_command(parsed_command &cmd, bool is_relative, double command_length) {
3738
is_extruder_relative = is_relative;
39+
is_g1_g2 = cmd.command == "G0" || cmd.command == "G1";
3840
gcode = cmd.gcode;
3941
comment = cmd.comment;
4042
extrusion_length = command_length;
4143
}
44+
/*
4245
unwritten_command(position* p, double command_length) {
4346
4447
e_relative = p->get_current_extruder().e_relative;
4548
offset_e = p->get_current_extruder().get_offset_e();
4649
is_extruder_relative = p->is_extruder_relative;
50+
is_g1_g2 = p->command.command == "G0" || p->command.command == "G1";
4751
gcode = p->command.gcode;
4852
comment = p->command.comment;
4953
extrusion_length = command_length;
50-
}
54+
} */
55+
bool is_g1_g2;
5156
bool is_extruder_relative;
5257
double e_relative;
5358
double offset_e;

ArcWelderTest/ArcWelderTest.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ static std::string FIRMWARE_COMPENSATION_TEST_1 = "C:\\Users\\Brad\\Documents\\3
9393
static std::string BENCHY_MIN_RADIUS_TEST = "C:\\Users\\Brad\\Documents\\3DPrinter\\AntiStutter\\BenchyMinRadiusTest.gcode";
9494
static std::string ISSUE_93 = "C:\\Users\\Brad\\Documents\\3DPrinter\\AntiStutter\\Issues\\93\\FailingGCode.gcode";
9595
static std::string ISSUE_99 = "C:\\Users\\Brad\\Documents\\3DPrinter\\AntiStutter\\Issues\\99\\FailingGCode.gcode";
96+
static std::string ISSUE_134 = "C:\\Users\\Brad\\Documents\\AntiStutter\\Issues\\134\\BirdHouse [PETG] [brim]+Infill [20%,cubic]+Noz [0.6]+LH [0.2]+LW-[0.6]+Temps [240+70]+50.0mms+Support [normal (56)]+Coast-[False].gcode" ;
9697

9798
static std::string CONE_TEST = "C:\\Users\\Brad\\Documents\\3DPrinter\\AntiStutter\\ConeTest.gcode";
9899
static std::string CONE_TEST_VASE = "C:\\Users\\Brad\\Documents\\3DPrinter\\AntiStutter\\ConeTestVase.gcode";
@@ -102,6 +103,8 @@ static std::string BAD_ARC_DIRECTIONS = "C:\\Users\\Brad\\Documents\\3DPrinter\\
102103
static std::string BAD_ARC_DIRECTIONS_2 = "C:\\Users\\Brad\\Documents\\3DPrinter\\AntiStutter\\BadArcDirections2.gcode";
103104
static std::string WIPER_TEST = "C:\\Users\\Brad\\Documents\\3DPrinter\\AntiStutter\\wiper_test.gcode";
104105
static std::string SLOW_COUPLER = "C:\\Users\\Brad\\Documents\\3DPrinter\\AntiStutter\\Rob_Coupler.gcode";
106+
static std::string ISSUE_34 = "C:\\Users\\Brad\\Documents\\3DPrinter\\AntiStutter\\spacer.gcode";
107+
static std::string DIFFICULT_ARCS_ISSUE_34 = "C:\\Users\\Brad\\Documents\\3DPrinter\\AntiStutter\\DifficultArcs\\issue_34.gcode";
105108

106109

107110

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required (VERSION "3.15")
1+
cmake_minimum_required (VERSION "3.13")
22
set(CMAKE_VERBOSE_MAKEFILE ON)
33

44
if(NOT CMAKE_BUILD_TYPE)

GcodeProcessorLib/array_list.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class array_list
6464

6565
inline int get_index_position(int index) const
6666
{
67-
int index_position = index + front_index_ + max_size_;
67+
int index_position = index + front_index_;// + max_size_;
6868
while (index_position >= max_size_)
6969
{
7070
index_position = index_position - max_size_;
@@ -135,7 +135,7 @@ class array_list
135135
{
136136
throw std::exception();
137137
}
138-
int pos = get_index_position(count_);
138+
int pos = get_index_position(count_-1);
139139
count_--;
140140
return items_[pos];
141141
}

GcodeProcessorLib/version.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#ifndef VERSION_H
2-
#define VERSION_H
3-
#ifndef HAS_GENERATED_VERSION
4-
#define GIT_BRANCH "Unknown"
5-
#define GIT_COMMIT_HASH "Unknown"
6-
#define GIT_TAGGED_VERSION "Unknown"
7-
#define GIT_TAG "Unknown"
8-
#define BUILD_DATE "Unknown"
9-
#define COPYRIGHT_DATE "2020"
10-
#define AUTHOR "Brad Hochgesang"
2+
#define VERSION_H
3+
#ifndef HAS_GENERATED_VERSION
4+
#define VERSION_GENERATED_H
5+
#define GIT_BRANCH "master"
6+
#define GIT_COMMIT_HASH "11d11e4"
7+
#define GIT_TAGGED_VERSION "1.1.0"
8+
#define GIT_TAG "1.1.0"
9+
#define BUILD_DATE "2021-01-24T20:44:10Z"
10+
#define COPYRIGHT_DATE "2021"
11+
#define AUTHOR "Brad Hochgesang"
1112
#else
12-
#include "version.generated.h"
13-
13+
#include "version.generated.h"
1414
#endif
1515
#endif

0 commit comments

Comments
 (0)