From 4f5e087ff49a57790b3e02ca895b15795e595713 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 11 Jan 2018 21:02:13 -0600 Subject: [PATCH] Planner anti-stutter by Sebastian Popp --- Marlin/src/module/planner.cpp | 11 +++++------ Marlin/src/module/planner.h | 10 ++++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Marlin/src/module/planner.cpp b/Marlin/src/module/planner.cpp index 701fe0e36..2d0e4ce38 100644 --- a/Marlin/src/module/planner.cpp +++ b/Marlin/src/module/planner.cpp @@ -1352,7 +1352,9 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE], float fr_mm_s, const // Initialize block entry speed. Compute based on deceleration to user-defined MINIMUM_PLANNER_SPEED. const float v_allowable = max_allowable_speed(-block->acceleration, MINIMUM_PLANNER_SPEED, block->millimeters); - block->entry_speed = min(vmax_junction, v_allowable); + // If stepper ISR is disabled, this indicates buffer_segment wants to add a split block. + // In this case start with the max. allowed speed to avoid an interrupted first move. + block->entry_speed = STEPPER_ISR_ENABLED() ? MINIMUM_PLANNER_SPEED : min(vmax_junction, v_allowable); // Initialize planner efficiency flags // Set flag if block will always reach maximum junction speed regardless of entry/exit speeds. @@ -1362,7 +1364,7 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE], float fr_mm_s, const // block nominal speed limits both the current and next maximum junction speeds. Hence, in both // the reverse and forward planners, the corresponding block junction speed will always be at the // the maximum junction speed and may always be ignored for any speed reduction checks. - block->flag |= BLOCK_FLAG_RECALCULATE | (block->nominal_speed <= v_allowable ? BLOCK_FLAG_NOMINAL_LENGTH : 0); + block->flag |= block->nominal_speed <= v_allowable ? BLOCK_FLAG_RECALCULATE | BLOCK_FLAG_NOMINAL_LENGTH : BLOCK_FLAG_RECALCULATE; // Update previous path unit_vector and nominal speed COPY(previous_speed, current_speed); @@ -1382,7 +1384,7 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE], float fr_mm_s, const * In that case, the retract and move will be executed together. * This leads to too many advance steps due to a huge e_acceleration. * The math is good, but we must avoid retract moves with advance! - * lin_dist_e > 0 : Extruder is running forward (e.g., for "Wipe while retracting" (Slic3r) or "Combing" (Cura) moves) + * lin_dist_e > 0 : Extruder is running forward (e.g., for "Wipe while retracting" (Slic3r) or "Combing" (Cura) moves) */ block->use_advance_lead = esteps && (block->steps[X_AXIS] || block->steps[Y_AXIS]) && extruder_advance_k @@ -1398,9 +1400,6 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE], float fr_mm_s, const #endif // LIN_ADVANCE - const float bnsr = 1.0 / block->nominal_speed; - calculate_trapezoid_for_block(block, block->entry_speed * bnsr, safe_speed * bnsr); - // Move buffer head block_buffer_head = next_buffer_head; diff --git a/Marlin/src/module/planner.h b/Marlin/src/module/planner.h index efdd4c7be..a904caacb 100644 --- a/Marlin/src/module/planner.h +++ b/Marlin/src/module/planner.h @@ -534,6 +534,16 @@ class Planner { static block_t* get_current_block() { if (blocks_queued()) { block_t * const block = &block_buffer[block_buffer_tail]; + + // If the block has no trapezoid calculated, it's unsafe to execute. + if (movesplanned() > 1) { + const block_t * const next = &block_buffer[next_block_index(block_buffer_tail)]; + if (TEST(block->flag, BLOCK_BIT_RECALCULATE) || TEST(next->flag, BLOCK_BIT_RECALCULATE)) + return NULL; + } + else if (TEST(block->flag, BLOCK_BIT_RECALCULATE)) + return NULL; + #if ENABLED(ULTRA_LCD) block_buffer_runtime_us -= block->segment_time_us; // We can't be sure how long an active block will take, so don't count it. #endif