DDA: get rid of fast_spm.

We need the fastest axis instead of its steps.

Eleminates also an overflow when ACCELERATION > 596.

We save 118 bytes program and 2 bytes data.

Reviewer Traumflug's note: I see 100 bytes program and 32 bytes
RAM saving on ATmegas here. 16 and 32 on the LPC 1114. Either way:
great stuff!
This commit is contained in:
wurstnase 2016-07-05 08:16:21 +02:00 committed by Markus Hitter
parent 39cababb07
commit 2b1f3371c7
4 changed files with 18 additions and 20 deletions

12
dda.c
View File

@ -49,15 +49,6 @@ TARGET BSS current_position;
/// \brief numbers for tracking the current state of movement
MOVE_STATE BSS move_state;
/// \var steps_per_m_P
/// \brief motor steps required to advance one meter on each axis
static const axes_uint32_t PROGMEM steps_per_m_P = {
STEPS_PER_M_X,
STEPS_PER_M_Y,
STEPS_PER_M_Z,
STEPS_PER_M_E
};
/// \var maximum_feedrate_P
/// \brief maximum allowed feedrate on each axis
static const axes_uint32_t PROGMEM maximum_feedrate_P = {
@ -279,7 +270,6 @@ void dda_create(DDA *dda, const TARGET *target) {
dda->fast_axis = i;
dda->total_steps = dda->delta[i];
dda->fast_um = delta_um[i];
dda->fast_spm = pgm_read_dword(&steps_per_m_P[i]);
}
}
@ -428,7 +418,7 @@ void dda_create(DDA *dda, const TARGET *target) {
// Acceleration ramps are based on the fast axis, not the combined speed.
dda->rampup_steps =
acc_ramp_len(muldiv(dda->fast_um, dda->endpoint.F, distance),
dda->fast_spm);
dda->fast_axis);
if (dda->rampup_steps > dda->total_steps / 2)
dda->rampup_steps = dda->total_steps / 2;

1
dda.h
View File

@ -115,7 +115,6 @@ typedef struct {
// uint8_t fast_axis; (see below)
uint32_t total_steps; ///< steps of the "fast" axis
uint32_t fast_um; ///< movement length of this fast axis
uint32_t fast_spm; ///< steps per meter of the fast axis
uint32_t c; ///< time until next step, 24.8 fixed point

View File

@ -256,9 +256,19 @@ const uint8_t msbloc (uint32_t v) {
return 0;
}
/*!
Pre-calculated constant values for acceleration ramp calculations.
*/
static const axes_uint32_t PROGMEM acc_ramp_div_P = {
(uint32_t)((7200000.0f * ACCELERATION) / STEPS_PER_M_X),
(uint32_t)((7200000.0f * ACCELERATION) / STEPS_PER_M_Y),
(uint32_t)((7200000.0f * ACCELERATION) / STEPS_PER_M_Z),
(uint32_t)((7200000.0f * ACCELERATION) / STEPS_PER_M_E)
};
/*! Acceleration ramp length in steps.
* \param feedrate Target feedrate of the accelerateion.
* \param steps_per_m Steps/m of the axis.
* \param fast_axis Number of the fastest axis.
* \return Accelerating steps neccessary to achieve target feedrate.
*
* s = 1/2 * a * t^2, v = a * t ==> s = v^2 / (2 * a)
@ -268,8 +278,7 @@ const uint8_t msbloc (uint32_t v) {
* 2000 to 4096000 steps/m (and higher). The numbers are a few percent
* too high at very low acceleration. Test code see commit message.
*/
uint32_t acc_ramp_len(uint32_t feedrate, uint32_t steps_per_m) {
return (feedrate * feedrate) /
(((uint32_t)7200000UL * ACCELERATION) / steps_per_m);
uint32_t acc_ramp_len(uint32_t feedrate, uint8_t fast_axis) {
return (feedrate * feedrate) / pgm_read_dword(&acc_ramp_div_P[fast_axis]);
}

View File

@ -51,7 +51,7 @@ uint16_t int_inv_sqrt(uint16_t a);
const uint8_t msbloc (uint32_t v);
// Calculates acceleration ramp length in steps.
uint32_t acc_ramp_len(uint32_t feedrate, uint32_t steps_per_m);
uint32_t acc_ramp_len(uint32_t feedrate, uint8_t fast_axis);
// For X axis only, should become obsolete:
#define ACCELERATE_RAMP_LEN(speed) (((speed)*(speed)) / (uint32_t)((7200000.0f * ACCELERATION) / (float)STEPS_PER_M_X))