Переглянути джерело

Apply @AnHardt reverse_pass changes

Plus: 3 times 2 float / to 1 float / and 2 float *
      and, reciprocal is an optimized operation
AnHardt 7 роки тому
джерело
коміт
22baf3356a
3 змінених файлів з 27 додано та 32 видалено
  1. 23
    28
      Marlin/planner.cpp
  2. 2
    2
      Marlin/planner.h
  3. 2
    2
      Marlin/ubl.h

+ 23
- 28
Marlin/planner.cpp Переглянути файл

247
 
247
 
248
 
248
 
249
 // The kernel called by recalculate() when scanning the plan from last to first entry.
249
 // The kernel called by recalculate() when scanning the plan from last to first entry.
250
-void Planner::reverse_pass_kernel(block_t* const current, const block_t *next) {
250
+void Planner::reverse_pass_kernel(block_t* const current, const block_t * const next) {
251
   if (!current || !next) return;
251
   if (!current || !next) return;
252
   // If entry speed is already at the maximum entry speed, no need to recheck. Block is cruising.
252
   // If entry speed is already at the maximum entry speed, no need to recheck. Block is cruising.
253
   // If not, block in state of acceleration or deceleration. Reset entry speed to maximum and
253
   // If not, block in state of acceleration or deceleration. Reset entry speed to maximum and
268
  * Once in reverse and once forward. This implements the reverse pass.
268
  * Once in reverse and once forward. This implements the reverse pass.
269
  */
269
  */
270
 void Planner::reverse_pass() {
270
 void Planner::reverse_pass() {
271
-
272
   if (movesplanned() > 3) {
271
   if (movesplanned() > 3) {
273
-
274
-    block_t* block[3] = { NULL, NULL, NULL };
275
-
276
-    // Make a local copy of block_buffer_tail, because the interrupt can alter it
277
-    // Is a critical section REALLY needed for a single byte change?
278
-    //CRITICAL_SECTION_START;
279
-    uint8_t tail = block_buffer_tail;
280
-    //CRITICAL_SECTION_END
281
-
282
-    uint8_t b = BLOCK_MOD(block_buffer_head - 3);
283
-    while (b != tail) {
284
-      if (block[0] && TEST(block[0]->flag, BLOCK_BIT_START_FROM_FULL_HALT)) break;
285
-      b = prev_block_index(b);
286
-      block[2] = block[1];
287
-      block[1] = block[0];
288
-      block[0] = &block_buffer[b];
289
-      reverse_pass_kernel(block[1], block[2]);
290
-    }
272
+    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.
273
+                                                            // tail+2 because the index is not yet advanced when checked
274
+    uint8_t blocknr = prev_block_index(block_buffer_head);
275
+    block_t* current = &block_buffer[blocknr];
276
+
277
+    do {
278
+      const block_t * const next = current;
279
+      blocknr = prev_block_index(blocknr);
280
+      current = &block_buffer[blocknr];
281
+      if (TEST(current->flag, BLOCK_BIT_START_FROM_FULL_HALT)) // Up to this every block is already optimized.
282
+        break;
283
+      reverse_pass_kernel(current, next);
284
+    } while (blocknr != endnr);
291
   }
285
   }
292
 }
286
 }
293
 
287
 
294
 // The kernel called by recalculate() when scanning the plan from first to last entry.
288
 // The kernel called by recalculate() when scanning the plan from first to last entry.
295
-void Planner::forward_pass_kernel(const block_t* previous, block_t* const current) {
289
+void Planner::forward_pass_kernel(const block_t * const previous, block_t* const current) {
296
   if (!previous) return;
290
   if (!previous) return;
297
 
291
 
298
   // If the previous block is an acceleration block, but it is not long enough to complete the
292
   // If the previous block is an acceleration block, but it is not long enough to complete the
344
       // Recalculate if current block entry or exit junction speed has changed.
338
       // Recalculate if current block entry or exit junction speed has changed.
345
       if (TEST(current->flag, BLOCK_BIT_RECALCULATE) || TEST(next->flag, BLOCK_BIT_RECALCULATE)) {
339
       if (TEST(current->flag, BLOCK_BIT_RECALCULATE) || TEST(next->flag, BLOCK_BIT_RECALCULATE)) {
346
         // NOTE: Entry and exit factors always > 0 by all previous logic operations.
340
         // NOTE: Entry and exit factors always > 0 by all previous logic operations.
347
-        float nom = current->nominal_speed;
348
-        calculate_trapezoid_for_block(current, current->entry_speed / nom, next->entry_speed / nom);
341
+        const float nomr = 1.0 / current->nominal_speed;
342
+        calculate_trapezoid_for_block(current, current->entry_speed * nomr, next->entry_speed * nomr);
349
         CBI(current->flag, BLOCK_BIT_RECALCULATE); // Reset current only to ensure next trapezoid is computed
343
         CBI(current->flag, BLOCK_BIT_RECALCULATE); // Reset current only to ensure next trapezoid is computed
350
       }
344
       }
351
     }
345
     }
353
   }
347
   }
354
   // Last/newest block in buffer. Exit speed is set with MINIMUM_PLANNER_SPEED. Always recalculated.
348
   // Last/newest block in buffer. Exit speed is set with MINIMUM_PLANNER_SPEED. Always recalculated.
355
   if (next) {
349
   if (next) {
356
-    float nom = next->nominal_speed;
357
-    calculate_trapezoid_for_block(next, next->entry_speed / nom, (MINIMUM_PLANNER_SPEED) / nom);
350
+    const float nomr = 1.0 / next->nominal_speed;
351
+    calculate_trapezoid_for_block(next, next->entry_speed * nomr, (MINIMUM_PLANNER_SPEED) * nomr);
358
     CBI(next->flag, BLOCK_BIT_RECALCULATE);
352
     CBI(next->flag, BLOCK_BIT_RECALCULATE);
359
   }
353
   }
360
 }
354
 }
1009
       #endif
1003
       #endif
1010
     );
1004
     );
1011
   }
1005
   }
1012
-  float inverse_millimeters = 1.0 / block->millimeters;  // Inverse millimeters to remove multiple divides
1006
+  const float inverse_millimeters = 1.0 / block->millimeters;  // Inverse millimeters to remove multiple divides
1013
 
1007
 
1014
   // Calculate inverse time for this move. No divide by zero due to previous checks.
1008
   // Calculate inverse time for this move. No divide by zero due to previous checks.
1015
   // Example: At 120mm/s a 60mm move takes 0.5s. So this will give 2.0.
1009
   // Example: At 120mm/s a 60mm move takes 0.5s. So this will give 2.0.
1048
     //FMM update ring buffer used for delay with filament measurements
1042
     //FMM update ring buffer used for delay with filament measurements
1049
     if (extruder == FILAMENT_SENSOR_EXTRUDER_NUM && filwidth_delay_index[1] >= 0) {  //only for extruder with filament sensor and if ring buffer is initialized
1043
     if (extruder == FILAMENT_SENSOR_EXTRUDER_NUM && filwidth_delay_index[1] >= 0) {  //only for extruder with filament sensor and if ring buffer is initialized
1050
 
1044
 
1051
-      const int MMD_CM = MAX_MEASUREMENT_DELAY + 1, MMD_MM = MMD_CM * 10;
1045
+      constexpr int MMD_CM = MAX_MEASUREMENT_DELAY + 1, MMD_MM = MMD_CM * 10;
1052
 
1046
 
1053
       // increment counters with next move in e axis
1047
       // increment counters with next move in e axis
1054
       filwidth_e_count += delta_mm[E_AXIS];
1048
       filwidth_e_count += delta_mm[E_AXIS];
1345
 
1339
 
1346
   #endif // LIN_ADVANCE
1340
   #endif // LIN_ADVANCE
1347
 
1341
 
1348
-  calculate_trapezoid_for_block(block, block->entry_speed / block->nominal_speed, safe_speed / block->nominal_speed);
1342
+  const float bnsr = 1.0 / block->nominal_speed;
1343
+  calculate_trapezoid_for_block(block, block->entry_speed * bnsr, safe_speed * bnsr);
1349
 
1344
 
1350
   // Move buffer head
1345
   // Move buffer head
1351
   block_buffer_head = next_buffer_head;
1346
   block_buffer_head = next_buffer_head;

+ 2
- 2
Marlin/planner.h Переглянути файл

565
 
565
 
566
     static void calculate_trapezoid_for_block(block_t* const block, const float &entry_factor, const float &exit_factor);
566
     static void calculate_trapezoid_for_block(block_t* const block, const float &entry_factor, const float &exit_factor);
567
 
567
 
568
-    static void reverse_pass_kernel(block_t* const current, const block_t *next);
569
-    static void forward_pass_kernel(const block_t *previous, block_t* const current);
568
+    static void reverse_pass_kernel(block_t* const current, const block_t * const next);
569
+    static void forward_pass_kernel(const block_t * const previous, block_t* const current);
570
 
570
 
571
     static void reverse_pass();
571
     static void reverse_pass();
572
     static void forward_pass();
572
     static void forward_pass();

+ 2
- 2
Marlin/ubl.h Переглянути файл

222
                     z1 = z_values[x1_i][yi];
222
                     z1 = z_values[x1_i][yi];
223
 
223
 
224
         return z1 + xratio * (z_values[min(x1_i, GRID_MAX_POINTS_X - 2) + 1][yi] - z1); // Don't allow x1_i+1 to be past the end of the array
224
         return z1 + xratio * (z_values[min(x1_i, GRID_MAX_POINTS_X - 2) + 1][yi] - z1); // Don't allow x1_i+1 to be past the end of the array
225
-                                                                                        // If it is, it is clamped to the last element of the 
225
+                                                                                        // If it is, it is clamped to the last element of the
226
                                                                                         // z_values[][] array and no correction is applied.
226
                                                                                         // z_values[][] array and no correction is applied.
227
       }
227
       }
228
 
228
 
248
                     z1 = z_values[xi][y1_i];
248
                     z1 = z_values[xi][y1_i];
249
 
249
 
250
         return z1 + yratio * (z_values[xi][min(y1_i, GRID_MAX_POINTS_Y - 2) + 1] - z1); // Don't allow y1_i+1 to be past the end of the array
250
         return z1 + yratio * (z_values[xi][min(y1_i, GRID_MAX_POINTS_Y - 2) + 1] - z1); // Don't allow y1_i+1 to be past the end of the array
251
-                                                                                        // If it is, it is clamped to the last element of the 
251
+                                                                                        // If it is, it is clamped to the last element of the
252
                                                                                         // z_values[][] array and no correction is applied.
252
                                                                                         // z_values[][] array and no correction is applied.
253
       }
253
       }
254
 
254
 

Завантаження…
Відмінити
Зберегти