From 6679dd6562cfa1ef5f3f05b7a0ee100088170a0c Mon Sep 17 00:00:00 2001 From: Phil Hord Date: Fri, 1 Jul 2016 13:43:54 -0400 Subject: [PATCH] dda_create(): treat 'target' as const and input only. `target` is an input to dda_create, but we don't modify it. We copy it into dda->endpoint and modify that instead, if needed. Make `target` const so this treatment is explicit. Rely on dda->endpoint to hold our "target" data so any decisions we make leading up to using it will be correctly reflected in our math. --- dda.c | 14 +++++++------- dda.h | 2 +- dda_kinematics.c | 4 ++-- dda_kinematics.h | 8 ++++---- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/dda.c b/dda.c index 0fa3cf2..435fcdb 100644 --- a/dda.c +++ b/dda.c @@ -152,7 +152,7 @@ void dda_new_startpoint(void) { * 6. Lookahead calculation too slow. This is handled in dda_join_moves() * already. */ -void dda_create(DDA *dda, TARGET *target) { +void dda_create(DDA *dda, const TARGET *target) { axes_uint32_t delta_um; axes_int32_t steps; uint32_t distance, c_limit, c_limit_calc; @@ -311,7 +311,7 @@ void dda_create(DDA *dda, TARGET *target) { // 60 * 16 MHz * 5 mm is > 32 bits uint32_t move_duration, md_candidate; - move_duration = distance * ((60 * F_CPU) / (target->F * 1000UL)); + move_duration = distance * ((60 * F_CPU) / (dda->endpoint.F * 1000UL)); for (i = X; i < AXIS_COUNT; i++) { md_candidate = dda->delta[i] * ((60 * F_CPU) / (pgm_read_dword(&maximum_feedrate_P[i]) * 1000UL)); @@ -357,7 +357,7 @@ void dda_create(DDA *dda, TARGET *target) { dda->c = move_duration / startpoint.F; if (dda->c < c_limit) dda->c = c_limit; - dda->end_c = move_duration / target->F; + dda->end_c = move_duration / dda->endpoint.F; if (dda->end_c < c_limit) dda->end_c = c_limit; @@ -366,7 +366,7 @@ void dda_create(DDA *dda, TARGET *target) { if (dda->c != dda->end_c) { uint32_t stF = startpoint.F / 4; - uint32_t enF = target->F / 4; + uint32_t enF = dda->endpoint.F / 4; // now some constant acceleration stuff, courtesy of http://www.embedded.com/design/mcus-processors-and-socs/4006438/Generate-stepper-motor-speed-profiles-in-real-time uint32_t ssq = (stF * stF); uint32_t esq = (enF * enF); @@ -406,7 +406,7 @@ void dda_create(DDA *dda, TARGET *target) { else dda->accel = 0; #elif defined ACCELERATION_RAMPING - dda->c_min = move_duration / target->F; + dda->c_min = move_duration / dda->endpoint.F; if (dda->c_min < c_limit) { dda->c_min = c_limit; dda->endpoint.F = move_duration / dda->c_min; @@ -463,7 +463,7 @@ void dda_create(DDA *dda, TARGET *target) { } #else - dda->c = move_duration / target->F; + dda->c = move_duration / dda->endpoint.F; if (dda->c < c_limit) dda->c = c_limit; #endif @@ -473,7 +473,7 @@ void dda_create(DDA *dda, TARGET *target) { serial_writestr_P(PSTR("] }\n")); // next dda starts where we finish - memcpy(&startpoint, target, sizeof(TARGET)); + memcpy(&startpoint, &dda->endpoint, sizeof(TARGET)); #ifdef LOOKAHEAD prev_dda = dda; #endif diff --git a/dda.h b/dda.h index e580709..b4b2cdc 100644 --- a/dda.h +++ b/dda.h @@ -190,7 +190,7 @@ void dda_init(void); void dda_new_startpoint(void); // create a DDA -void dda_create(DDA *dda, TARGET *target); +void dda_create(DDA *dda, const TARGET *target); // start a created DDA (called from timer interrupt) void dda_start(DDA *dda); diff --git a/dda_kinematics.c b/dda_kinematics.c index 6634df5..6b0ee9c 100644 --- a/dda_kinematics.c +++ b/dda_kinematics.c @@ -9,7 +9,7 @@ void -carthesian_to_carthesian(TARGET *startpoint, TARGET *target, +carthesian_to_carthesian(const TARGET *startpoint, const TARGET *target, axes_uint32_t delta_um, axes_int32_t steps) { enum axis_e i; @@ -31,7 +31,7 @@ carthesian_to_carthesian(TARGET *startpoint, TARGET *target, } void -carthesian_to_corexy(TARGET *startpoint, TARGET *target, +carthesian_to_corexy(const TARGET *startpoint, const TARGET *target, axes_uint32_t delta_um, axes_int32_t steps) { delta_um[X] = (uint32_t)labs((target->axis[X] - startpoint->axis[X]) + diff --git a/dda_kinematics.h b/dda_kinematics.h index fef2f4c..155ada6 100644 --- a/dda_kinematics.h +++ b/dda_kinematics.h @@ -8,19 +8,19 @@ #include "dda.h" -void carthesian_to_carthesian(TARGET *startpoint, TARGET *target, +void carthesian_to_carthesian(const TARGET *startpoint, const TARGET *target, axes_uint32_t delta_um, axes_int32_t steps); -void carthesian_to_corexy(TARGET *startpoint, TARGET *target, +void carthesian_to_corexy(const TARGET *startpoint, const TARGET *target, axes_uint32_t delta_um, axes_int32_t steps); //void carthesian_to_scara(TARGET *startpoint, TARGET *target, // axes_uint32_t delta_um, axes_int32_t steps); -static void code_axes_to_stepper_axes(TARGET *, TARGET *, axes_uint32_t, +static void code_axes_to_stepper_axes(const TARGET *, const TARGET *, axes_uint32_t, axes_int32_t) __attribute__ ((always_inline)); -inline void code_axes_to_stepper_axes(TARGET *startpoint, TARGET *target, +inline void code_axes_to_stepper_axes(const TARGET *startpoint, const TARGET *target, axes_uint32_t delta_um, axes_int32_t steps) { #if defined KINEMATICS_STRAIGHT