From 110faae986eef6c4398c166a81c91cbd1d5a3bf4 Mon Sep 17 00:00:00 2001 From: Sonny J Date: Thu, 15 Sep 2011 20:32:15 -0600 Subject: [PATCH] More '%' modulo opertor removals and some housecleaning. - Serial functions contained quite a few modulo operations that would be executed with high frequency when streaming. AVR processors are very slow when operating these. In one test on the Arduino forums, it showed about a 15x slow down compared to a simple if-then statement. - Clarified some variable names and types and comments. --- gcode.c | 2 +- motion_control.c | 16 ++++++++-------- motion_control.h | 4 ++-- serial.c | 11 +++++++---- settings.c | 2 +- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/gcode.c b/gcode.c index 29afe14..7127932 100644 --- a/gcode.c +++ b/gcode.c @@ -328,7 +328,7 @@ uint8_t gc_execute_line(char *line) { } // Set clockwise/counter-clockwise sign for mc_arc computations - int8_t isclockwise = false; + uint8_t isclockwise = false; if (gc.motion_mode == MOTION_MODE_CW_ARC) { isclockwise = true; } // Trace the arc diff --git a/motion_control.c b/motion_control.c index 8b55779..aec1c1c 100644 --- a/motion_control.c +++ b/motion_control.c @@ -48,7 +48,7 @@ void mc_dwell(uint32_t milliseconds) // The arc is approximated by generating a huge number of tiny, linear segments. The length of each // segment is configured in settings.mm_per_arc_segment. void mc_arc(double *position, double *target, double *offset, uint8_t axis_0, uint8_t axis_1, - uint8_t axis_linear, double feed_rate, uint8_t invert_feed_rate, double radius, int8_t isclockwise) + uint8_t axis_linear, double feed_rate, uint8_t invert_feed_rate, double radius, uint8_t isclockwise) { // int acceleration_manager_was_enabled = plan_is_acceleration_manager_enabled(); // plan_set_acceleration_manager_enabled(false); // disable acceleration management for the duration of the arc @@ -106,7 +106,7 @@ void mc_arc(double *position, double *target, double *offset, uint8_t axis_0, ui double cos_T = 1-0.5*theta_per_segment*theta_per_segment; // Small angle approximation double sin_T = theta_per_segment; - double trajectory[3]; + double arc_target[3]; double sin_Ti; double cos_Ti; double r_axisi; @@ -114,7 +114,7 @@ void mc_arc(double *position, double *target, double *offset, uint8_t axis_0, ui int8_t count = 0; // Initialize the linear axis - trajectory[axis_linear] = position[axis_linear]; + arc_target[axis_linear] = position[axis_linear]; for (i = 1; i