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.
This commit is contained in:
Phil Hord 2016-07-01 13:43:54 -04:00 committed by Markus Hitter
parent 95787f3a34
commit 6679dd6562
4 changed files with 14 additions and 14 deletions

14
dda.c
View File

@ -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

2
dda.h
View File

@ -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);

View File

@ -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]) +

View File

@ -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