Browse Source

Rename inverse_mm_s => inverse_secs

Scott Lahteine 7 years ago
parent
commit
26c5bbc5a7
2 changed files with 19 additions and 13 deletions
  1. 17
    12
      Marlin/planner.cpp
  2. 2
    1
      Marlin/planner.h

+ 17
- 12
Marlin/planner.cpp View File

@@ -204,14 +204,18 @@ void Planner::calculate_trapezoid_for_block(block_t* const block, const float &e
204 204
   NOLESS(initial_rate, MINIMAL_STEP_RATE);
205 205
   NOLESS(final_rate, MINIMAL_STEP_RATE);
206 206
 
207
-  int32_t accel = block->acceleration_steps_per_s2,
208
-          accelerate_steps = CEIL(estimate_acceleration_distance(initial_rate, block->nominal_rate, accel)),
207
+  const int32_t accel = block->acceleration_steps_per_s2;
208
+
209
+          // Steps required for acceleration, deceleration to/from nominal rate
210
+  int32_t accelerate_steps = CEIL(estimate_acceleration_distance(initial_rate, block->nominal_rate, accel)),
209 211
           decelerate_steps = FLOOR(estimate_acceleration_distance(block->nominal_rate, final_rate, -accel)),
212
+          // Steps between acceleration and deceleration, if any
210 213
           plateau_steps = block->step_event_count - accelerate_steps - decelerate_steps;
211 214
 
212
-  // Is the Plateau of Nominal Rate smaller than nothing? That means no cruising, and we will
213
-  // have to use intersection_distance() to calculate when to abort accel and start braking
214
-  // in order to reach the final_rate exactly at the end of this block.
215
+  // Does accelerate_steps + decelerate_steps exceed step_event_count?
216
+  // Then we can't possibly reach the nominal rate, there will be no cruising.
217
+  // Use intersection_distance() to calculate accel / braking time in order to
218
+  // reach the final_rate exactly at the end of this block.
215 219
   if (plateau_steps < 0) {
216 220
     accelerate_steps = CEIL(intersection_distance(initial_rate, final_rate, accel, block->step_event_count));
217 221
     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
1045 1049
   }
1046 1050
   float inverse_millimeters = 1.0 / block->millimeters;  // Inverse millimeters to remove multiple divides
1047 1051
 
1048
-  // Calculate moves/second for this move. No divide by zero due to previous checks.
1049
-  float inverse_mm_s = fr_mm_s * inverse_millimeters;
1052
+  // Calculate inverse time for this move. No divide by zero due to previous checks.
1053
+  // Example: At 120mm/s a 60mm move takes 0.5s. So this will give 2.0.
1054
+  float inverse_secs = fr_mm_s * inverse_millimeters;
1050 1055
 
1051 1056
   const uint8_t moves_queued = movesplanned();
1052 1057
 
1053 1058
   // Slow down when the buffer starts to empty, rather than wait at the corner for a buffer refill
1054 1059
   #if ENABLED(SLOWDOWN) || ENABLED(ULTRA_LCD) || defined(XY_FREQUENCY_LIMIT)
1055 1060
     // Segment time im micro seconds
1056
-    uint32_t segment_time_us = LROUND(1000000.0 / inverse_mm_s);
1061
+    uint32_t segment_time_us = LROUND(1000000.0 / inverse_secs);
1057 1062
   #endif
1058 1063
   #if ENABLED(SLOWDOWN)
1059 1064
     if (WITHIN(moves_queued, 2, (BLOCK_BUFFER_SIZE) / 2 - 1)) {
1060 1065
       if (segment_time_us < min_segment_time_us) {
1061 1066
         // buffer is draining, add extra time.  The amount of time added increases if the buffer is still emptied more.
1062 1067
         const uint32_t nst = segment_time_us + LROUND(2 * (min_segment_time_us - segment_time_us) / moves_queued);
1063
-        inverse_mm_s = 1000000.0 / nst;
1068
+        inverse_secs = 1000000.0 / nst;
1064 1069
         #if defined(XY_FREQUENCY_LIMIT) || ENABLED(ULTRA_LCD)
1065 1070
           segment_time_us = nst;
1066 1071
         #endif
@@ -1074,8 +1079,8 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
1074 1079
     CRITICAL_SECTION_END
1075 1080
   #endif
1076 1081
 
1077
-  block->nominal_speed = block->millimeters * inverse_mm_s; // (mm/sec) Always > 0
1078
-  block->nominal_rate = CEIL(block->step_event_count * inverse_mm_s); // (step/sec) Always > 0
1082
+  block->nominal_speed = block->millimeters * inverse_secs;           //   (mm/sec) Always > 0
1083
+  block->nominal_rate = CEIL(block->step_event_count * inverse_secs); // (step/sec) Always > 0
1079 1084
 
1080 1085
   #if ENABLED(FILAMENT_WIDTH_SENSOR)
1081 1086
     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
1114 1119
   // Calculate and limit speed in mm/sec for each axis
1115 1120
   float current_speed[NUM_AXIS], speed_factor = 1.0; // factor <1 decreases speed
1116 1121
   LOOP_XYZE(i) {
1117
-    const float cs = FABS((current_speed[i] = delta_mm[i] * inverse_mm_s));
1122
+    const float cs = FABS((current_speed[i] = delta_mm[i] * inverse_secs));
1118 1123
     #if ENABLED(DISTINCT_E_FACTORS)
1119 1124
       if (i == E_AXIS) i += extruder;
1120 1125
     #endif

+ 2
- 1
Marlin/planner.h View File

@@ -448,6 +448,7 @@ class Planner {
448 448
     /**
449 449
      * The current block. NULL if the buffer is empty.
450 450
      * This also marks the block as busy.
451
+     * WARNING: Called from Stepper ISR context!
451 452
      */
452 453
     static block_t* get_current_block() {
453 454
       if (blocks_queued()) {
@@ -514,7 +515,7 @@ class Planner {
514 515
     }
515 516
 
516 517
     /**
517
-     * Return the point at which you must start braking (at the rate of -'acceleration') if
518
+     * Return the point at which you must start braking (at the rate of -'accel') if
518 519
      * you start at 'initial_rate', accelerate (until reaching the point), and want to end at
519 520
      * 'final_rate' after traveling 'distance'.
520 521
      *

Loading…
Cancel
Save