DDA: make macro ACCELERATE_RAMP_LEN_SPM() a function.

This macro is pretty expensive (700 bytes, well, stuff is now
calculated at runtime), so there's no chance to use it in multiple
places and we likely also need this in dda_lookahead.c to achieve
full 4 axis compatibility there.
This commit is contained in:
Markus Hitter 2013-12-06 01:57:31 +01:00
parent 9739382da9
commit 6fae5a8b7c
3 changed files with 23 additions and 10 deletions

4
dda.c
View File

@ -360,8 +360,8 @@ void dda_create(DDA *dda, TARGET *target) {
// Acceleration ramps are based on the fast axis, not the combined speed. // Acceleration ramps are based on the fast axis, not the combined speed.
dda->rampup_steps = dda->rampup_steps =
ACCELERATE_RAMP_LEN_SPM(muldiv(dda->fast_um, dda->endpoint.F, distance), acc_ramp_len(muldiv(dda->fast_um, dda->endpoint.F, distance),
dda->fast_spm); dda->fast_spm);
if (dda->rampup_steps > dda->total_steps / 2) if (dda->rampup_steps > dda->total_steps / 2)
dda->rampup_steps = dda->total_steps / 2; dda->rampup_steps = dda->total_steps / 2;

View File

@ -235,3 +235,21 @@ const uint8_t msbloc (uint32_t v) {
} }
return 0; return 0;
} }
/*! Acceleration ramp length in steps.
* \param feedrate Target feedrate of the accelerateion.
* \param steps_per_m Steps/m of the axis.
* \return Accelerating steps neccessary to achieve target feedrate.
*
* s = 1/2 * a * t^2, v = a * t ==> s = v^2 / (2 * a)
* 7200000 = 60 * 60 * 1000 * 2 (mm/min -> mm/s, steps/m -> steps/mm, factor 2)
*
* Note: this function has shown to be accurate between 10 and 10'000 mm/s2 and
* 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);
}

View File

@ -66,14 +66,9 @@ uint16_t int_inv_sqrt(uint16_t a);
// 2 ^ msbloc(v) >= v // 2 ^ msbloc(v) >= v
const uint8_t msbloc (uint32_t v); const uint8_t msbloc (uint32_t v);
// s = 1/2 * a * t^2, v = a * t ==> s = v^2 / (2 * a) // Calculates acceleration ramp length in steps.
// 7200000 = 60 * 60 * 1000 * 2 (mm/min -> mm/s, steps/m -> steps/mm, factor 2) uint32_t acc_ramp_len(uint32_t feedrate, uint32_t steps_per_m);
// Note: this macro has shown to be accurate between 10 and 10'000 mm/s2 and
// 2000 to 4096000 steps/m (and higher). The numbers are a few percent
// too high at very low acceleration. Test code see commit message.
#define ACCELERATE_RAMP_LEN_SPM(speed, spm) \
(((speed) * (speed)) / \
(uint32_t)((7200000UL * ACCELERATION) / (spm)))
// For X axis only, should become obsolete: // For X axis only, should become obsolete:
#define ACCELERATE_RAMP_LEN(speed) (((speed)*(speed)) / (uint32_t)((7200000.0f * ACCELERATION) / (float)STEPS_PER_M_X)) #define ACCELERATE_RAMP_LEN(speed) (((speed)*(speed)) / (uint32_t)((7200000.0f * ACCELERATION) / (float)STEPS_PER_M_X))