From cd0155b5f457aff21cfcf040457ca47809ed00f4 Mon Sep 17 00:00:00 2001 From: Phil Hord Date: Mon, 25 Nov 2013 18:06:43 -0500 Subject: [PATCH] DDA: Move axis calculations into loops, part 3. Clean up code to reduce duplication by consolidating code into loops for per-axis actions. Part 3 is moving fast axis detection into a loop. Binary size 84 bytes smaller. --- dda.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/dda.c b/dda.c index b7f07c9..c580a97 100644 --- a/dda.c +++ b/dda.c @@ -52,6 +52,15 @@ TARGET BSS current_position; /// \brief numbers for tracking the current state of movement MOVE_STATE BSS move_state; +/// \var steps_per_m +/// \brief motor steps required to advance one meter on each axis +static const axes_uint32_t PROGMEM steps_per_m = { + STEPS_PER_M_X, + STEPS_PER_M_Y, + STEPS_PER_M_Z, + STEPS_PER_M_E +}; + /// \var maximum_feedrate /// \brief maximum allowed feedrate on each axis static const axes_uint32_t PROGMEM maximum_feedrate = { @@ -184,23 +193,17 @@ void dda_create(DDA *dda, TARGET *target) { target->axis[X] - startpoint.axis[X], target->axis[Y] - startpoint.axis[Y], target->axis[Z] - startpoint.axis[Z], target->axis[E] - startpoint.axis[E]); - dda->total_steps = dda->delta[X]; - dda->fast_um = delta_um[X]; - dda->fast_spm = STEPS_PER_M_X; - if (dda->delta[Y] > dda->total_steps) { - dda->total_steps = dda->delta[Y]; - dda->fast_um = delta_um[Y]; - dda->fast_spm = STEPS_PER_M_Y; - } - if (dda->delta[Z] > dda->total_steps) { - dda->total_steps = dda->delta[Z]; - dda->fast_um = delta_um[Z]; - dda->fast_spm = STEPS_PER_M_Z; - } - if (dda->delta[E] > dda->total_steps) { - dda->total_steps = dda->delta[E]; - dda->fast_um = delta_um[E]; - dda->fast_spm = STEPS_PER_M_E; + // Admittedly, this looks like it's overcomplicated. Why store three 32-bit + // values if storing an axis number would be fully sufficient? Well, I'm not + // sure, but my feeling says that when we achieve true circles and Beziers, + // we'll have total_steps which matches neither of X, Y, Z or E. Accordingly, + // keep it for now. --Traumflug + for (i = X; i < AXIS_COUNT; i++) { + if (i == X || dda->delta[i] > dda->total_steps) { + dda->total_steps = dda->delta[i]; + dda->fast_um = delta_um[i]; + dda->fast_spm = pgm_read_dword(&steps_per_m[i]); + } } if (DEBUG_DDA && (debug_flags & DEBUG_DDA))