From bc08ce86be128c35a6ba474b45afbe961af5feb2 Mon Sep 17 00:00:00 2001 From: Sebastianv650 Date: Mon, 5 Mar 2018 04:18:35 +0100 Subject: [PATCH] Fix broken reverse planner (#9914) See MarlinFirmware/Marlin#9913 for details. --- Marlin/planner.cpp | 28 +++++++++++++++------------- Marlin/planner.h | 4 ---- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/Marlin/planner.cpp b/Marlin/planner.cpp index 0c919b13f0..fc78441f55 100644 --- a/Marlin/planner.cpp +++ b/Marlin/planner.cpp @@ -278,18 +278,26 @@ void Planner::reverse_pass_kernel(block_t* const current, const block_t * const * Once in reverse and once forward. This implements the reverse pass. */ void Planner::reverse_pass() { - if (movesplanned() > 3) { - const uint8_t endnr = BLOCK_MOD(block_buffer_tail + 2); // tail is running. tail+1 shouldn't be altered because it's connected to the running block. - // tail+2 because the index is not yet advanced when checked + if (movesplanned() > 2) { + const uint8_t endnr = BLOCK_MOD(block_buffer_tail + 1); // tail is running. tail+1 shouldn't be altered because it's connected to the running block. uint8_t blocknr = prev_block_index(block_buffer_head); block_t* current = &block_buffer[blocknr]; + // Last/newest block in buffer: + const float max_entry_speed = current->max_entry_speed; + if (current->entry_speed != max_entry_speed) { + // If nominal length true, max junction speed is guaranteed to be reached. Only compute + // for max allowable speed if block is decelerating and nominal length is false. + current->entry_speed = TEST(current->flag, BLOCK_BIT_NOMINAL_LENGTH) + ? max_entry_speed + : min(max_entry_speed, max_allowable_speed(-current->acceleration, MINIMUM_PLANNER_SPEED, current->millimeters)); + SBI(current->flag, BLOCK_BIT_RECALCULATE); + } + do { const block_t * const next = current; blocknr = prev_block_index(blocknr); current = &block_buffer[blocknr]; - if (TEST(current->flag, BLOCK_BIT_START_FROM_FULL_HALT)) // Up to this every block is already optimized. - break; reverse_pass_kernel(current, next); } while (blocknr != endnr); } @@ -1413,17 +1421,11 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE] // Now the transition velocity is known, which maximizes the shared exit / entry velocity while // respecting the jerk factors, it may be possible, that applying separate safe exit / entry velocities will achieve faster prints. const float vmax_junction_threshold = vmax_junction * 0.99f; - if (previous_safe_speed > vmax_junction_threshold && safe_speed > vmax_junction_threshold) { - // Not coasting. The machine will stop and start the movements anyway, - // better to start the segment from start. - SBI(block->flag, BLOCK_BIT_START_FROM_FULL_HALT); + if (previous_safe_speed > vmax_junction_threshold && safe_speed > vmax_junction_threshold) vmax_junction = safe_speed; - } } - else { - SBI(block->flag, BLOCK_BIT_START_FROM_FULL_HALT); + else vmax_junction = safe_speed; - } // Max entry speed of this block equals the max exit speed of the previous block. block->max_entry_speed = vmax_junction; diff --git a/Marlin/planner.h b/Marlin/planner.h index eb257685cd..d55fa0da02 100644 --- a/Marlin/planner.h +++ b/Marlin/planner.h @@ -49,9 +49,6 @@ enum BlockFlagBit { // from a safe speed (in consideration of jerking from zero speed). BLOCK_BIT_NOMINAL_LENGTH, - // Start from a halt at the start of this block, respecting the maximum allowed jerk. - BLOCK_BIT_START_FROM_FULL_HALT, - // The block is busy BLOCK_BIT_BUSY, @@ -62,7 +59,6 @@ enum BlockFlagBit { enum BlockFlag { BLOCK_FLAG_RECALCULATE = _BV(BLOCK_BIT_RECALCULATE), BLOCK_FLAG_NOMINAL_LENGTH = _BV(BLOCK_BIT_NOMINAL_LENGTH), - BLOCK_FLAG_START_FROM_FULL_HALT = _BV(BLOCK_BIT_START_FROM_FULL_HALT), BLOCK_FLAG_BUSY = _BV(BLOCK_BIT_BUSY), BLOCK_FLAG_CONTINUED = _BV(BLOCK_BIT_CONTINUED) };