From f6f2b7f44f41850977319ab5c2fdf397217885f0 Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Sat, 25 Sep 2010 17:58:15 +0200 Subject: [PATCH] Enhance ACCELERATION_RAMPING on short moves. Problem was: For short moves, you have to ramp down before reaching target speed. The point of return was set to half of the number of total steps. Now, what happens is there's an uneven number of steps? In integer math, 3 / 2 = 1, so the move would ramp one step up, one step down and ... well, one step even further down, resulting in a really sloooow step. Slow, like a full second or so. Adding one to the first half, the movement ramps two steps up, one down and would do another step at minimum speed, if it wasn't already at target position. This is about as accurate as we can get it without introducing more code at interrupt time. --- dda.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dda.c b/dda.c index a4557cb..5b7ef8c 100644 --- a/dda.c +++ b/dda.c @@ -272,7 +272,8 @@ void dda_create(DDA *dda, TARGET *target) { else dda->accel = 0; #elif defined ACCELERATION_RAMPING - dda->ramp_steps = dda->total_steps / 2; + // add the last bit of dda->total_steps to always round up + dda->ramp_steps = dda->total_steps / 2 + (dda->total_steps & 1); dda->step_no = 0; // c is initial step time in IOclk ticks dda->c = ACCELERATION_STEEPNESS << 8;