diff --git a/dda.c b/dda.c index 4385013..e2a998e 100644 --- a/dda.c +++ b/dda.c @@ -85,7 +85,7 @@ static void set_direction(DDA *dda, enum axis_e n, int32_t delta) { /*! Find the direction of the 'n' axis */ -static int8_t get_direction(DDA *dda, enum axis_e n) { +int8_t get_direction(DDA *dda, enum axis_e n) { if ((n == X && dda->x_direction) || (n == Y && dda->y_direction) || (n == Z && dda->z_direction) || @@ -198,21 +198,6 @@ void dda_create(DDA *dda, const TARGET *target) { startpoint_steps.axis[i] = steps[i]; set_direction(dda, i, delta_steps); - #ifdef LOOKAHEAD - // Also displacements in micrometers, but for the lookahead alogrithms. - // TODO: this is redundant. delta_um[] and dda->delta_um[] differ by - // just signedness and storage location. Ideally, dda is used - // as storage place only if neccessary (LOOKAHEAD turned on?) - // because this space is multiplied by the movement queue size. - // - // Update 2014/10: it was tried to use delta_um[]'s sign to set stepper - // direction in dda_start() to allow getting rid of - // some of this redundancy, but this increases dda_start() - // by at least 20 clock cycles. Not good for performance. - // Tried code can be found in the archive folder. - dda->delta_um[i] = (delta_steps >= 0) ? - (int32_t)delta_um[i] : -(int32_t)delta_um[i]; - #endif } // Handle extruder axes. They act independently from the bots kinematics @@ -235,24 +220,12 @@ void dda_create(DDA *dda, const TARGET *target) { startpoint_steps.axis[E] = steps[E]; set_direction(dda, E, delta_steps); - #ifdef LOOKAHEAD - // Also displacements in micrometers, but for the lookahead alogrithms. - // TODO: this is redundant. delta_um[] and dda->delta_um[] differ by - // just signedness and storage location. Ideally, dda is used - // as storage place only if neccessary (LOOKAHEAD turned on?) - // because this space is multiplied by the movement queue size. - dda->delta_um[E] = (delta_steps >= 0) ? - (int32_t)delta_um[E] : -(int32_t)delta_um[E]; - #endif } else { // When we get more extruder axes: // for (i = E; i < AXIS_COUNT; i++) { ... delta_um[E] = (uint32_t)labs(target->axis[E]); dda->delta[E] = (uint32_t)labs(steps[E]); - #ifdef LOOKAHEAD - dda->delta_um[E] = target->axis[E]; - #endif dda->e_direction = (target->axis[E] >= 0)?1:0; } diff --git a/dda.h b/dda.h index 48edefe..51ab484 100644 --- a/dda.h +++ b/dda.h @@ -134,10 +134,6 @@ typedef struct { // These two are based on the "fast" axis, the axis with the most steps. uint32_t start_steps; ///< would be required to reach start feedrate uint32_t end_steps; ///< would be required to stop from end feedrate - // Displacement vector, in um, based between the difference of the starting - // point and the target. Required to obtain the jerk between 2 moves. - // Note: x_delta and co are in steps, not um. - axes_int32_t delta_um; // Number the moves to be able to test at the end of lookahead if the moves // are the same. Note: we do not need a lot of granularity here: more than // MOVEBUFFER_SIZE is already enough. @@ -177,6 +173,8 @@ extern TARGET current_position; methods */ +int8_t get_direction(DDA *dda, enum axis_e n); + // initialize dda structures void dda_init(void); diff --git a/dda_lookahead.c b/dda_lookahead.c index 64fc1ba..63cb49c 100644 --- a/dda_lookahead.c +++ b/dda_lookahead.c @@ -73,13 +73,12 @@ void dda_find_crossing_speed(DDA *prev, DDA *current) { // Find individual axis speeds. // TODO: this is eight expensive muldiv()s. It should be possible to store // currF as prevF for the next calculation somehow, to save 4 of - // these 8 muldiv()s. This would also allow to get rid of - // dda->delta_um[] and using delta_um[] from dda_create() instead. + // these 8 muldiv()s. // Caveat: bail out condition above and some other non-continuous // situations might need some extra code for handling. for (i = X; i < AXIS_COUNT; i++) { - prevF[i] = muldiv(prev->delta_um[i], F, prev->distance); - currF[i] = muldiv(current->delta_um[i], F, current->distance); + prevF[i] = muldiv(prev->delta[i], F, prev->total_steps); + currF[i] = muldiv(current->delta[i], F, current->total_steps); } if (DEBUG_DDA && (debug_flags & DEBUG_DDA)) @@ -111,7 +110,11 @@ void dda_find_crossing_speed(DDA *prev, DDA *current) { max_speed_factor = (uint32_t)2 << 8; for (i = X; i < AXIS_COUNT; i++) { - dv = currF[i] > prevF[i] ? currF[i] - prevF[i] : prevF[i] - currF[i]; + if (get_direction(prev, i) == get_direction(current, i)) + dv = currF[i] > prevF[i] ? currF[i] - prevF[i] : prevF[i] - currF[i]; + else + dv = currF[i] + prevF[i]; + if (dv) { speed_factor = ((uint32_t)pgm_read_dword(&maximum_jerk_P[i]) << 8) / dv; if (speed_factor < max_speed_factor)