From 26c5bbc5a7e9caaf129835b4b1db6b89d1bb07cb Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 2 Dec 2017 20:12:35 -0600 Subject: [PATCH] Rename inverse_mm_s => inverse_secs --- Marlin/planner.cpp | 29 +++++++++++++++++------------ Marlin/planner.h | 3 ++- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/Marlin/planner.cpp b/Marlin/planner.cpp index 6d2cf9815..071c3c608 100644 --- a/Marlin/planner.cpp +++ b/Marlin/planner.cpp @@ -204,14 +204,18 @@ void Planner::calculate_trapezoid_for_block(block_t* const block, const float &e NOLESS(initial_rate, MINIMAL_STEP_RATE); NOLESS(final_rate, MINIMAL_STEP_RATE); - int32_t accel = block->acceleration_steps_per_s2, - accelerate_steps = CEIL(estimate_acceleration_distance(initial_rate, block->nominal_rate, accel)), + const int32_t accel = block->acceleration_steps_per_s2; + + // Steps required for acceleration, deceleration to/from nominal rate + int32_t accelerate_steps = CEIL(estimate_acceleration_distance(initial_rate, block->nominal_rate, accel)), decelerate_steps = FLOOR(estimate_acceleration_distance(block->nominal_rate, final_rate, -accel)), + // Steps between acceleration and deceleration, if any plateau_steps = block->step_event_count - accelerate_steps - decelerate_steps; - // Is the Plateau of Nominal Rate smaller than nothing? That means no cruising, and we will - // have to use intersection_distance() to calculate when to abort accel and start braking - // in order to reach the final_rate exactly at the end of this block. + // Does accelerate_steps + decelerate_steps exceed step_event_count? + // Then we can't possibly reach the nominal rate, there will be no cruising. + // Use intersection_distance() to calculate accel / braking time in order to + // reach the final_rate exactly at the end of this block. if (plateau_steps < 0) { accelerate_steps = CEIL(intersection_distance(initial_rate, final_rate, accel, block->step_event_count)); NOLESS(accelerate_steps, 0); // Check limits due to numerical round-off @@ -1045,22 +1049,23 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const } float inverse_millimeters = 1.0 / block->millimeters; // Inverse millimeters to remove multiple divides - // Calculate moves/second for this move. No divide by zero due to previous checks. - float inverse_mm_s = fr_mm_s * inverse_millimeters; + // Calculate inverse time for this move. No divide by zero due to previous checks. + // Example: At 120mm/s a 60mm move takes 0.5s. So this will give 2.0. + float inverse_secs = fr_mm_s * inverse_millimeters; const uint8_t moves_queued = movesplanned(); // Slow down when the buffer starts to empty, rather than wait at the corner for a buffer refill #if ENABLED(SLOWDOWN) || ENABLED(ULTRA_LCD) || defined(XY_FREQUENCY_LIMIT) // Segment time im micro seconds - uint32_t segment_time_us = LROUND(1000000.0 / inverse_mm_s); + uint32_t segment_time_us = LROUND(1000000.0 / inverse_secs); #endif #if ENABLED(SLOWDOWN) if (WITHIN(moves_queued, 2, (BLOCK_BUFFER_SIZE) / 2 - 1)) { if (segment_time_us < min_segment_time_us) { // buffer is draining, add extra time. The amount of time added increases if the buffer is still emptied more. const uint32_t nst = segment_time_us + LROUND(2 * (min_segment_time_us - segment_time_us) / moves_queued); - inverse_mm_s = 1000000.0 / nst; + inverse_secs = 1000000.0 / nst; #if defined(XY_FREQUENCY_LIMIT) || ENABLED(ULTRA_LCD) segment_time_us = nst; #endif @@ -1074,8 +1079,8 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const CRITICAL_SECTION_END #endif - block->nominal_speed = block->millimeters * inverse_mm_s; // (mm/sec) Always > 0 - block->nominal_rate = CEIL(block->step_event_count * inverse_mm_s); // (step/sec) Always > 0 + block->nominal_speed = block->millimeters * inverse_secs; // (mm/sec) Always > 0 + block->nominal_rate = CEIL(block->step_event_count * inverse_secs); // (step/sec) Always > 0 #if ENABLED(FILAMENT_WIDTH_SENSOR) static float filwidth_e_count = 0, filwidth_delay_dist = 0; @@ -1114,7 +1119,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const // Calculate and limit speed in mm/sec for each axis float current_speed[NUM_AXIS], speed_factor = 1.0; // factor <1 decreases speed LOOP_XYZE(i) { - const float cs = FABS((current_speed[i] = delta_mm[i] * inverse_mm_s)); + const float cs = FABS((current_speed[i] = delta_mm[i] * inverse_secs)); #if ENABLED(DISTINCT_E_FACTORS) if (i == E_AXIS) i += extruder; #endif diff --git a/Marlin/planner.h b/Marlin/planner.h index 6d658b2a8..a00b637d2 100644 --- a/Marlin/planner.h +++ b/Marlin/planner.h @@ -448,6 +448,7 @@ class Planner { /** * The current block. NULL if the buffer is empty. * This also marks the block as busy. + * WARNING: Called from Stepper ISR context! */ static block_t* get_current_block() { if (blocks_queued()) { @@ -514,7 +515,7 @@ class Planner { } /** - * Return the point at which you must start braking (at the rate of -'acceleration') if + * Return the point at which you must start braking (at the rate of -'accel') if * you start at 'initial_rate', accelerate (until reaching the point), and want to end at * 'final_rate' after traveling 'distance'. *