Kaynağa Gözat

Improve planner & stepper PR #263

Richard Wackerbarth 9 yıl önce
ebeveyn
işleme
7a670e3911
2 değiştirilmiş dosya ile 27 ekleme ve 30 silme
  1. 5
    4
      Marlin/planner.cpp
  2. 22
    26
      Marlin/stepper.cpp

+ 5
- 4
Marlin/planner.cpp Dosyayı Görüntüle

@@ -227,16 +227,17 @@ void planner_reverse_pass_kernel(block_t* previous, block_t* current, block_t* n
227 227
     // If entry speed is already at the maximum entry speed, no need to recheck. Block is cruising.
228 228
     // If not, block in state of acceleration or deceleration. Reset entry speed to maximum and
229 229
     // check for maximum allowable speed reductions to ensure maximum possible planned speed.
230
-    if (current->entry_speed != current->max_entry_speed) {
230
+    float max_entry_speed = current->max_entry_speed;
231
+    if (current->entry_speed != max_entry_speed) {
231 232
 
232 233
       // If nominal length true, max junction speed is guaranteed to be reached. Only compute
233 234
       // for max allowable speed if block is decelerating and nominal length is false.
234
-      if (!current->nominal_length_flag && current->max_entry_speed > next->entry_speed) {
235
-        current->entry_speed = min(current->max_entry_speed,
235
+      if (!current->nominal_length_flag && max_entry_speed > next->entry_speed) {
236
+        current->entry_speed = min(max_entry_speed,
236 237
                                    max_allowable_speed(-current->acceleration, next->entry_speed, current->millimeters));
237 238
       }
238 239
       else {
239
-        current->entry_speed = current->max_entry_speed;
240
+        current->entry_speed = max_entry_speed;
240 241
       }
241 242
       current->recalculate_flag = true;
242 243
 

+ 22
- 26
Marlin/stepper.cpp Dosyayı Görüntüle

@@ -68,9 +68,9 @@ volatile static unsigned long step_events_completed; // The number of step event
68 68
 static long acceleration_time, deceleration_time;
69 69
 //static unsigned long accelerate_until, decelerate_after, acceleration_rate, initial_rate, final_rate, nominal_rate;
70 70
 static unsigned short acc_step_rate; // needed for deceleration start point
71
-static char step_loops;
71
+static uint8_t step_loops;
72
+static uint8_t step_loops_nominal;
72 73
 static unsigned short OCR1A_nominal;
73
-static unsigned short step_loops_nominal;
74 74
 
75 75
 volatile long endstops_trigsteps[3] = { 0 };
76 76
 volatile long endstops_stepsTotal, endstops_stepsDone;
@@ -480,7 +480,8 @@ void st_wake_up() {
480 480
 
481 481
 FORCE_INLINE unsigned short calc_timer(unsigned short step_rate) {
482 482
   unsigned short timer;
483
-  if (step_rate > MAX_STEP_FREQUENCY) step_rate = MAX_STEP_FREQUENCY;
483
+
484
+  NOMORE(step_rate, MAX_STEP_FREQUENCY);
484 485
 
485 486
   if (step_rate > 20000) { // If steprate > 20kHz >> step 4 times
486 487
     step_rate = (step_rate >> 2) & 0x3fff;
@@ -494,8 +495,8 @@ FORCE_INLINE unsigned short calc_timer(unsigned short step_rate) {
494 495
     step_loops = 1;
495 496
   }
496 497
 
497
-  if (step_rate < (F_CPU / 500000)) step_rate = (F_CPU / 500000);
498
-  step_rate -= (F_CPU / 500000); // Correct for minimal speed
498
+  NOLESS(step_rate, F_CPU / 500000);
499
+  step_rate -= F_CPU / 500000; // Correct for minimal speed
499 500
   if (step_rate >= (8 * 256)) { // higher step rate
500 501
     unsigned short table_address = (unsigned short)&speed_lookuptable_fast[(unsigned char)(step_rate >> 8)][0];
501 502
     unsigned char tmp_step_rate = (step_rate & 0x00ff);
@@ -699,8 +700,7 @@ ISR(TIMER1_COMPA_vect) {
699 700
       acc_step_rate += current_block->initial_rate;
700 701
 
701 702
       // upper limit
702
-      if (acc_step_rate > current_block->nominal_rate)
703
-        acc_step_rate = current_block->nominal_rate;
703
+      NOMORE(acc_step_rate, current_block->nominal_rate);
704 704
 
705 705
       // step_rate to timer interval
706 706
       timer = calc_timer(acc_step_rate);
@@ -709,10 +709,9 @@ ISR(TIMER1_COMPA_vect) {
709 709
 
710 710
       #if ENABLED(ADVANCE)
711 711
 
712
-        for (int8_t i = 0; i < step_loops; i++) {
713
-          advance += advance_rate;
714
-        }
715
-        //if (advance > current_block->advance) advance = current_block->advance;
712
+        advance += advance_rate * step_loops;
713
+        //NOLESS(advance, current_block->advance);
714
+
716 715
         // Do E steps + advance steps
717 716
         e_steps[current_block->active_extruder] += ((advance >> 8) - old_advance);
718 717
         old_advance = advance >> 8;
@@ -722,29 +721,26 @@ ISR(TIMER1_COMPA_vect) {
722 721
     else if (step_events_completed > (unsigned long)current_block->decelerate_after) {
723 722
       MultiU24X32toH16(step_rate, deceleration_time, current_block->acceleration_rate);
724 723
 
725
-      if (step_rate > acc_step_rate) { // Check step_rate stays positive
726
-        step_rate = current_block->final_rate;
727
-      }
728
-      else {
729
-        step_rate = acc_step_rate - step_rate; // Decelerate from aceleration end point.
724
+      if (step_rate <= acc_step_rate) { // Still decelerating?
725
+        step_rate = acc_step_rate - step_rate;
726
+        NOLESS(step_rate, current_block->final_rate);
730 727
       }
731
-
732
-      // lower limit
733
-      if (step_rate < current_block->final_rate)
728
+      else
734 729
         step_rate = current_block->final_rate;
735 730
 
736 731
       // step_rate to timer interval
737 732
       timer = calc_timer(step_rate);
738 733
       OCR1A = timer;
739 734
       deceleration_time += timer;
735
+
740 736
       #if ENABLED(ADVANCE)
741
-        for (int8_t i = 0; i < step_loops; i++) {
742
-          advance -= advance_rate;
743
-        }
744
-        if (advance < final_advance) advance = final_advance;
737
+        advance -= advance_rate * step_loops;
738
+        NOLESS(advance, final_advance);
739
+
745 740
         // Do E steps + advance steps
746
-        e_steps[current_block->active_extruder] += ((advance >> 8) - old_advance);
747
-        old_advance = advance >> 8;
741
+        uint32_t advance_whole = advance >> 8;
742
+        e_steps[current_block->active_extruder] += advance_whole - old_advance;
743
+        old_advance = advance_whole;
748 744
       #endif //ADVANCE
749 745
     }
750 746
     else {
@@ -1201,7 +1197,7 @@ void digipot_init() {
1201 1197
 
1202 1198
     SPI.begin();
1203 1199
     pinMode(DIGIPOTSS_PIN, OUTPUT);
1204
-    for (int i = 0; i <= 4; i++) {
1200
+    for (int i = 0; i < COUNT(digipot_motor_current); i++) {
1205 1201
       //digitalPotWrite(digipot_ch[i], digipot_motor_current[i]);
1206 1202
       digipot_current(i, digipot_motor_current[i]);
1207 1203
     }

Loading…
İptal
Kaydet