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:
parent
95787f3a34
commit
6679dd6562
14
dda.c
14
dda.c
|
|
@ -152,7 +152,7 @@ void dda_new_startpoint(void) {
|
||||||
* 6. Lookahead calculation too slow. This is handled in dda_join_moves()
|
* 6. Lookahead calculation too slow. This is handled in dda_join_moves()
|
||||||
* already.
|
* already.
|
||||||
*/
|
*/
|
||||||
void dda_create(DDA *dda, TARGET *target) {
|
void dda_create(DDA *dda, const TARGET *target) {
|
||||||
axes_uint32_t delta_um;
|
axes_uint32_t delta_um;
|
||||||
axes_int32_t steps;
|
axes_int32_t steps;
|
||||||
uint32_t distance, c_limit, c_limit_calc;
|
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
|
// 60 * 16 MHz * 5 mm is > 32 bits
|
||||||
uint32_t move_duration, md_candidate;
|
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++) {
|
for (i = X; i < AXIS_COUNT; i++) {
|
||||||
md_candidate = dda->delta[i] * ((60 * F_CPU) /
|
md_candidate = dda->delta[i] * ((60 * F_CPU) /
|
||||||
(pgm_read_dword(&maximum_feedrate_P[i]) * 1000UL));
|
(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;
|
dda->c = move_duration / startpoint.F;
|
||||||
if (dda->c < c_limit)
|
if (dda->c < c_limit)
|
||||||
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)
|
if (dda->end_c < c_limit)
|
||||||
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) {
|
if (dda->c != dda->end_c) {
|
||||||
uint32_t stF = startpoint.F / 4;
|
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
|
// 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 ssq = (stF * stF);
|
||||||
uint32_t esq = (enF * enF);
|
uint32_t esq = (enF * enF);
|
||||||
|
|
@ -406,7 +406,7 @@ void dda_create(DDA *dda, TARGET *target) {
|
||||||
else
|
else
|
||||||
dda->accel = 0;
|
dda->accel = 0;
|
||||||
#elif defined ACCELERATION_RAMPING
|
#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) {
|
if (dda->c_min < c_limit) {
|
||||||
dda->c_min = c_limit;
|
dda->c_min = c_limit;
|
||||||
dda->endpoint.F = move_duration / dda->c_min;
|
dda->endpoint.F = move_duration / dda->c_min;
|
||||||
|
|
@ -463,7 +463,7 @@ void dda_create(DDA *dda, TARGET *target) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
dda->c = move_duration / target->F;
|
dda->c = move_duration / dda->endpoint.F;
|
||||||
if (dda->c < c_limit)
|
if (dda->c < c_limit)
|
||||||
dda->c = c_limit;
|
dda->c = c_limit;
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -473,7 +473,7 @@ void dda_create(DDA *dda, TARGET *target) {
|
||||||
serial_writestr_P(PSTR("] }\n"));
|
serial_writestr_P(PSTR("] }\n"));
|
||||||
|
|
||||||
// next dda starts where we finish
|
// next dda starts where we finish
|
||||||
memcpy(&startpoint, target, sizeof(TARGET));
|
memcpy(&startpoint, &dda->endpoint, sizeof(TARGET));
|
||||||
#ifdef LOOKAHEAD
|
#ifdef LOOKAHEAD
|
||||||
prev_dda = dda;
|
prev_dda = dda;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
2
dda.h
2
dda.h
|
|
@ -190,7 +190,7 @@ void dda_init(void);
|
||||||
void dda_new_startpoint(void);
|
void dda_new_startpoint(void);
|
||||||
|
|
||||||
// create a DDA
|
// 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)
|
// start a created DDA (called from timer interrupt)
|
||||||
void dda_start(DDA *dda);
|
void dda_start(DDA *dda);
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
|
|
||||||
void
|
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) {
|
axes_uint32_t delta_um, axes_int32_t steps) {
|
||||||
enum axis_e i;
|
enum axis_e i;
|
||||||
|
|
||||||
|
|
@ -31,7 +31,7 @@ carthesian_to_carthesian(TARGET *startpoint, TARGET *target,
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
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) {
|
axes_uint32_t delta_um, axes_int32_t steps) {
|
||||||
|
|
||||||
delta_um[X] = (uint32_t)labs((target->axis[X] - startpoint->axis[X]) +
|
delta_um[X] = (uint32_t)labs((target->axis[X] - startpoint->axis[X]) +
|
||||||
|
|
|
||||||
|
|
@ -8,19 +8,19 @@
|
||||||
#include "dda.h"
|
#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);
|
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);
|
axes_uint32_t delta_um, axes_int32_t steps);
|
||||||
|
|
||||||
//void carthesian_to_scara(TARGET *startpoint, TARGET *target,
|
//void carthesian_to_scara(TARGET *startpoint, TARGET *target,
|
||||||
// axes_uint32_t delta_um, axes_int32_t steps);
|
// 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)
|
axes_int32_t)
|
||||||
__attribute__ ((always_inline));
|
__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_uint32_t delta_um,
|
||||||
axes_int32_t steps) {
|
axes_int32_t steps) {
|
||||||
#if defined KINEMATICS_STRAIGHT
|
#if defined KINEMATICS_STRAIGHT
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue