diff --git a/planner.c b/planner.c index 19a7558..dd231e2 100644 --- a/planner.c +++ b/planner.c @@ -259,17 +259,17 @@ static uint8_t planner_recalculate() // check for maximum allowable speed reductions to ensure maximum possible planned speed. if (curr_block->entry_speed_sqr != curr_block->max_entry_speed_sqr) { // default if next_entry_speed_sqr > curr_block->max_entry_speed_sqr || max_entry_speed_sqr > curr_block->max_entry_speed_sqr - curr_block->entry_speed_sqr = curr_block->max_entry_speed_sqr; + curr_block->new_entry_speed_sqr = curr_block->max_entry_speed_sqr; if (next_entry_speed_sqr < curr_block->max_entry_speed_sqr) { // Computes: v_entry^2 = v_exit^2 + 2*acceleration*distance max_entry_speed_sqr = next_entry_speed_sqr + 2*curr_block->acceleration*curr_block->millimeters; if (max_entry_speed_sqr < curr_block->max_entry_speed_sqr) { - curr_block->entry_speed_sqr = max_entry_speed_sqr; + curr_block->new_entry_speed_sqr = max_entry_speed_sqr; } } } - next_entry_speed_sqr= curr_block->entry_speed_sqr; + next_entry_speed_sqr= curr_block->new_entry_speed_sqr; current_block_idx= prev_block_index( current_block_idx ); curr_block= &block_buffer[current_block_idx]; @@ -286,7 +286,7 @@ static uint8_t planner_recalculate() // If the current block is an acceleration block, but it is not long enough to complete the // full speed change within the block, we need to adjust the exit speed accordingly. Entry // speeds have already been reset, maximized, and reverse planned by reverse planner. - if (curr_block->entry_speed_sqr < next_block->entry_speed_sqr) { + if (curr_block->entry_speed_sqr < next_block->new_entry_speed_sqr) { // Compute block exit speed based on the current block speed and distance // Computes: v_exit^2 = v_entry^2 + 2*acceleration*distance max_exit_speed_sqr = curr_block->entry_speed_sqr + 2*curr_block->acceleration*curr_block->millimeters; @@ -296,8 +296,8 @@ static uint8_t planner_recalculate() } // adjust max_exit_speed_sqr in case this is a deceleration block or max accel cannot be reached - if(max_exit_speed_sqr>next_block->entry_speed_sqr) { - max_exit_speed_sqr= next_block->entry_speed_sqr; + if(max_exit_speed_sqr>next_block->new_entry_speed_sqr) { + max_exit_speed_sqr= next_block->new_entry_speed_sqr; } else { // this block has reached max acceleration, it is optimal planned_block_tail= next_block_idx; diff --git a/planner.h b/planner.h index a16c8c9..693344d 100644 --- a/planner.h +++ b/planner.h @@ -40,6 +40,7 @@ typedef struct { float nominal_speed_sqr; // The nominal speed for this block in mm/min float entry_speed_sqr; // Entry speed at previous-current block junction in mm/min float max_entry_speed_sqr; // Maximum allowable junction entry speed in mm/min + float new_entry_speed_sqr; // Temporary entry speed used by the planner float millimeters; // The total travel of this block in mm float acceleration; uint8_t recalculate_flag; // Planner flag to recalculate trapezoids on entry junction diff --git a/stepper.c b/stepper.c index 77213ea..8c066af 100644 --- a/stepper.c +++ b/stepper.c @@ -120,6 +120,7 @@ void st_go_idle() STEPPERS_DISABLE_PORT |= (1<