From 48ab4ee45d36d89faed1b029fd017ff4f8704390 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 23 Mar 2010 14:13:31 -0500 Subject: [PATCH] Add a relative tolerance for arcs Previously, IJK arcs were rejected based on the absolute radius error alone. This is problematic when the numbers come from calculations where at least one input is a non-exact constant given as a decimal number. Adding a relative error check (arbitrarily .1%) and rejecting an arc only when it fails both the absolute and relative error checks, or when it fails a much larger absolute error check allows large arcs with relatively small errors to be accepted. --- src/emc/rs274ngc/interp_arc.cc | 18 ++++++++++++------ 1 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/emc/rs274ngc/interp_arc.cc b/src/emc/rs274ngc/interp_arc.cc index 1106ae8..22d8af6 100644 --- a/src/emc/rs274ngc/interp_arc.cc +++ b/src/emc/rs274ngc/interp_arc.cc @@ -105,12 +105,15 @@ int Interp::arc_data_comp_ijk(int move, //! tolerance), + double abs_err = fabs(arc_radius - radius2); + double rel_err = abs_err / std::max(arc_radius, radius2); + CHKS(abs_err > 100*tolerance || (abs_err > tolerance && (rel_err > .001)), _("Radius to end of arc differs from radius to start: " - "start=(%c%.4f,%c%.4f) center=(%c%.4f,%c%.4f) end=(%c%.4f,%c%.4f) r1=%.4f r2=%.4f"), + "start=(%c%.4f,%c%.4f) center=(%c%.4f,%c%.4f) end=(%c%.4f,%c%.4f) r1=%.4f r2=%.4f abs_err=%.4g rel_err=%.4f%%"), a, current_x, b, current_y, a, *center_x, b, *center_y, - a, end_x, b, end_y, arc_radius, radius2); + a, end_x, b, end_y, arc_radius, radius2, + abs_err, rel_err*100); CHKS(((arc_radius <= tool_radius) && (((side == LEFT) && (move == G_3)) || ((side == RIGHT) && (move == G_2)))), @@ -267,12 +270,15 @@ int Interp::arc_data_ijk(int move, //!< either G_2 (cw arc) or G_3 (ccw ar radius = hypot((*center_x - current_x), (*center_y - current_y)); radius2 = hypot((*center_x - end_x), (*center_y - end_y)); CHKS(((radius < min_radius) || (radius2 < min_radius)), NCE_ZERO_RADIUS_ARC); - CHKS((fabs(radius - radius2) > tolerance), + double abs_err = fabs(radius - radius2); + double rel_err = abs_err / std::max(radius, radius2); + CHKS(abs_err > 100*tolerance || (abs_err > tolerance && (rel_err > .001)), _("Radius to end of arc differs from radius to start: " - "start=(%c%.4f,%c%.4f) center=(%c%.4f,%c%.4f) end=(%c%.4f,%c%.4f) r1=%.4f r2=%.4f"), + "start=(%c%.4f,%c%.4f) center=(%c%.4f,%c%.4f) end=(%c%.4f,%c%.4f) r1=%.4f r2=%.4f abs_err=%.4g rel_err=%.4f%%"), a, current_x, b, current_y, a, *center_x, b, *center_y, - a, end_x, b, end_y, radius, radius2); + a, end_x, b, end_y, radius, radius2, + abs_err, rel_err*100); if (move == G_2) *turn = -1; else if (move == G_3) -- 1.6.6.62.g584f3