From 6a70a4fbb36911fcc53116261b915a3c12286f67 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 15 Feb 2018 22:11:26 -0600 Subject: [PATCH] Fix G26 circles (#9627) Easier to configure. Catch an odd divisor. --- Marlin/src/gcode/bedlevel/G26.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Marlin/src/gcode/bedlevel/G26.cpp b/Marlin/src/gcode/bedlevel/G26.cpp index d52deccd2..dd84e4e39 100644 --- a/Marlin/src/gcode/bedlevel/G26.cpp +++ b/Marlin/src/gcode/bedlevel/G26.cpp @@ -738,14 +738,18 @@ void GcodeSuite::G26() { /** * Pre-generate radius offset values at 30 degree intervals to reduce CPU load. */ - - #define A_CNT ((360 / 30) / 2) // must be a multiple of 2 for _COS() and _SIN() macro to work correctly! - #define NEGATION_of_COS_TABLE(A) (((A + A_CNT * 16) % (A_CNT * 2)) >= A_CNT ? -1 : 1) - #define _COS(A) (trig_table[(A + A_CNT * 16) % A_CNT] * NEGATION_of_COS_TABLE(A)) - #define _SIN(A) (-_COS((A + A_CNT / 2) % (A_CNT * 2))) + #define A_INT 30 + #define _ANGS (360 / A_INT) + #define A_CNT (_ANGS / 2) + #define _IND(A) ((A + _ANGS * 8) % _ANGS) + #define _COS(A) (trig_table[_IND(A) % A_CNT] * (_IND(A) >= A_CNT ? -1 : 1)) + #define _SIN(A) (-_COS((A + A_CNT / 2) % _ANGS)) + #if A_CNT & 1 + #error "A_CNT must be a positive value. Please change A_INT." + #endif float trig_table[A_CNT]; for (uint8_t i = 0; i < A_CNT; i++) - trig_table[i] = INTERSECTION_CIRCLE_RADIUS * cos(RADIANS(i * 30)); + trig_table[i] = INTERSECTION_CIRCLE_RADIUS * cos(RADIANS(i * A_INT)); mesh_index_pair location; do {