Updated some comments and fixed a bug in the new stepper logic.
- The stepper logic was not initiating the decelerations for certain cases. Just re-arranged the logic to fix it.
This commit is contained in:
parent
2be0d66872
commit
05ed6c122d
29
stepper.c
29
stepper.c
@ -71,8 +71,8 @@ static uint32_t trapezoid_adjusted_rate; // The current rate of step_events
|
|||||||
// The trapezoid is the shape the speed curve over time. It starts at block->initial_rate, accelerates by block->rate_delta
|
// The trapezoid is the shape the speed curve over time. It starts at block->initial_rate, accelerates by block->rate_delta
|
||||||
// during the first block->accelerate_until step_events_completed, then keeps going at constant speed until
|
// during the first block->accelerate_until step_events_completed, then keeps going at constant speed until
|
||||||
// step_events_completed reaches block->decelerate_after after which it decelerates until the trapezoid generator is reset.
|
// step_events_completed reaches block->decelerate_after after which it decelerates until the trapezoid generator is reset.
|
||||||
// The slope of acceleration is always +/- block->rate_delta and is applied at a constant rate by trapezoid_generator_tick()
|
// The slope of acceleration is always +/- block->rate_delta and is applied at a constant rate following the midpoint rule
|
||||||
// that is called ACCELERATION_TICKS_PER_SECOND times per second.
|
// by the trapezoid generator, which is called ACCELERATION_TICKS_PER_SECOND times per second.
|
||||||
|
|
||||||
static void set_step_events_per_minute(uint32_t steps_per_minute);
|
static void set_step_events_per_minute(uint32_t steps_per_minute);
|
||||||
|
|
||||||
@ -172,11 +172,9 @@ SIGNAL(TIMER1_COMPA_vect)
|
|||||||
// While in block steps, check for de/ac-celeration events and execute them accordingly.
|
// While in block steps, check for de/ac-celeration events and execute them accordingly.
|
||||||
if (step_events_completed < current_block->step_event_count) {
|
if (step_events_completed < current_block->step_event_count) {
|
||||||
|
|
||||||
// Always check step event location to ensure de/ac-celerations are executed and terminated at
|
// The trapezoid generator always checks step event location to ensure de/ac-celerations are
|
||||||
// exactly the right time. This helps prevent over/under-shooting the target position and speed.
|
// executed and terminated at exactly the right time. This helps prevent over/under-shooting
|
||||||
// Trapezoid de/ac-celeration is approximated by discrete increases or decreases in velocity,
|
// the target position and speed.
|
||||||
// defined by ACCELERATION_TICKS_PER_SECOND and block->rate_delta. The accelerations employ the
|
|
||||||
// midpoint rule to obtain an accurate representation of the exact acceleration curve.
|
|
||||||
|
|
||||||
// NOTE: By increasing the ACCELERATION_TICKS_PER_SECOND in config.h, the resolution of the
|
// NOTE: By increasing the ACCELERATION_TICKS_PER_SECOND in config.h, the resolution of the
|
||||||
// discrete velocity changes increase and accuracy can increase as well to a point. Numerical
|
// discrete velocity changes increase and accuracy can increase as well to a point. Numerical
|
||||||
@ -193,7 +191,13 @@ SIGNAL(TIMER1_COMPA_vect)
|
|||||||
}
|
}
|
||||||
set_step_events_per_minute(trapezoid_adjusted_rate);
|
set_step_events_per_minute(trapezoid_adjusted_rate);
|
||||||
}
|
}
|
||||||
} else if (step_events_completed > current_block->decelerate_after) {
|
} else if (step_events_completed >= current_block->decelerate_after) {
|
||||||
|
// Reset trapezoid tick cycle counter to make sure that the deceleration is performed the
|
||||||
|
// same every time. Reset to CYCLES_PER_ACCELERATION_TICK/2 to follow the midpoint rule for
|
||||||
|
// an accurate approximation of the deceleration curve.
|
||||||
|
if (step_events_completed == current_block-> decelerate_after) {
|
||||||
|
trapezoid_tick_cycle_counter = CYCLES_PER_ACCELERATION_TICK/2;
|
||||||
|
} else {
|
||||||
// Iterate cycle counter and check if speeds need to be reduced.
|
// Iterate cycle counter and check if speeds need to be reduced.
|
||||||
if ( iterate_trapezoid_cycle_counter() ) {
|
if ( iterate_trapezoid_cycle_counter() ) {
|
||||||
// NOTE: We will only reduce speed if the result will be > 0. This catches small
|
// NOTE: We will only reduce speed if the result will be > 0. This catches small
|
||||||
@ -207,18 +211,13 @@ SIGNAL(TIMER1_COMPA_vect)
|
|||||||
}
|
}
|
||||||
set_step_events_per_minute(trapezoid_adjusted_rate);
|
set_step_events_per_minute(trapezoid_adjusted_rate);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// No accelerations. Make sure we cruise exactly at nominal rate.
|
// No accelerations. Make sure we cruise exactly at the nominal rate.
|
||||||
if (trapezoid_adjusted_rate != current_block->nominal_rate) {
|
if (trapezoid_adjusted_rate != current_block->nominal_rate) {
|
||||||
trapezoid_adjusted_rate = current_block->nominal_rate;
|
trapezoid_adjusted_rate = current_block->nominal_rate;
|
||||||
set_step_events_per_minute(trapezoid_adjusted_rate);
|
set_step_events_per_minute(trapezoid_adjusted_rate);
|
||||||
}
|
}
|
||||||
// Check to reset trapezoid tick cycle counter to make sure that the deceleration is
|
|
||||||
// performed the same every time. Reset to CYCLES_PER_ACCELERATION_TICK/2 to follow the
|
|
||||||
// midpoint rule for an accurate approximation of the deceleration curve.
|
|
||||||
if (step_events_completed >= current_block-> decelerate_after) {
|
|
||||||
trapezoid_tick_cycle_counter = CYCLES_PER_ACCELERATION_TICK/2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user