Browse Source

Improve planner & stepper PR #263

Richard Wackerbarth 8 years ago
parent
commit
7a670e3911
2 changed files with 27 additions and 30 deletions
  1. 5
    4
      Marlin/planner.cpp
  2. 22
    26
      Marlin/stepper.cpp

+ 5
- 4
Marlin/planner.cpp View File

227
     // If entry speed is already at the maximum entry speed, no need to recheck. Block is cruising.
227
     // If entry speed is already at the maximum entry speed, no need to recheck. Block is cruising.
228
     // If not, block in state of acceleration or deceleration. Reset entry speed to maximum and
228
     // If not, block in state of acceleration or deceleration. Reset entry speed to maximum and
229
     // check for maximum allowable speed reductions to ensure maximum possible planned speed.
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
       // If nominal length true, max junction speed is guaranteed to be reached. Only compute
233
       // If nominal length true, max junction speed is guaranteed to be reached. Only compute
233
       // for max allowable speed if block is decelerating and nominal length is false.
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
                                    max_allowable_speed(-current->acceleration, next->entry_speed, current->millimeters));
237
                                    max_allowable_speed(-current->acceleration, next->entry_speed, current->millimeters));
237
       }
238
       }
238
       else {
239
       else {
239
-        current->entry_speed = current->max_entry_speed;
240
+        current->entry_speed = max_entry_speed;
240
       }
241
       }
241
       current->recalculate_flag = true;
242
       current->recalculate_flag = true;
242
 
243
 

+ 22
- 26
Marlin/stepper.cpp View File

68
 static long acceleration_time, deceleration_time;
68
 static long acceleration_time, deceleration_time;
69
 //static unsigned long accelerate_until, decelerate_after, acceleration_rate, initial_rate, final_rate, nominal_rate;
69
 //static unsigned long accelerate_until, decelerate_after, acceleration_rate, initial_rate, final_rate, nominal_rate;
70
 static unsigned short acc_step_rate; // needed for deceleration start point
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
 static unsigned short OCR1A_nominal;
73
 static unsigned short OCR1A_nominal;
73
-static unsigned short step_loops_nominal;
74
 
74
 
75
 volatile long endstops_trigsteps[3] = { 0 };
75
 volatile long endstops_trigsteps[3] = { 0 };
76
 volatile long endstops_stepsTotal, endstops_stepsDone;
76
 volatile long endstops_stepsTotal, endstops_stepsDone;
480
 
480
 
481
 FORCE_INLINE unsigned short calc_timer(unsigned short step_rate) {
481
 FORCE_INLINE unsigned short calc_timer(unsigned short step_rate) {
482
   unsigned short timer;
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
   if (step_rate > 20000) { // If steprate > 20kHz >> step 4 times
486
   if (step_rate > 20000) { // If steprate > 20kHz >> step 4 times
486
     step_rate = (step_rate >> 2) & 0x3fff;
487
     step_rate = (step_rate >> 2) & 0x3fff;
494
     step_loops = 1;
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
   if (step_rate >= (8 * 256)) { // higher step rate
500
   if (step_rate >= (8 * 256)) { // higher step rate
500
     unsigned short table_address = (unsigned short)&speed_lookuptable_fast[(unsigned char)(step_rate >> 8)][0];
501
     unsigned short table_address = (unsigned short)&speed_lookuptable_fast[(unsigned char)(step_rate >> 8)][0];
501
     unsigned char tmp_step_rate = (step_rate & 0x00ff);
502
     unsigned char tmp_step_rate = (step_rate & 0x00ff);
699
       acc_step_rate += current_block->initial_rate;
700
       acc_step_rate += current_block->initial_rate;
700
 
701
 
701
       // upper limit
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
       // step_rate to timer interval
705
       // step_rate to timer interval
706
       timer = calc_timer(acc_step_rate);
706
       timer = calc_timer(acc_step_rate);
709
 
709
 
710
       #if ENABLED(ADVANCE)
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
         // Do E steps + advance steps
715
         // Do E steps + advance steps
717
         e_steps[current_block->active_extruder] += ((advance >> 8) - old_advance);
716
         e_steps[current_block->active_extruder] += ((advance >> 8) - old_advance);
718
         old_advance = advance >> 8;
717
         old_advance = advance >> 8;
722
     else if (step_events_completed > (unsigned long)current_block->decelerate_after) {
721
     else if (step_events_completed > (unsigned long)current_block->decelerate_after) {
723
       MultiU24X32toH16(step_rate, deceleration_time, current_block->acceleration_rate);
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
         step_rate = current_block->final_rate;
729
         step_rate = current_block->final_rate;
735
 
730
 
736
       // step_rate to timer interval
731
       // step_rate to timer interval
737
       timer = calc_timer(step_rate);
732
       timer = calc_timer(step_rate);
738
       OCR1A = timer;
733
       OCR1A = timer;
739
       deceleration_time += timer;
734
       deceleration_time += timer;
735
+
740
       #if ENABLED(ADVANCE)
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
         // Do E steps + advance steps
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
       #endif //ADVANCE
744
       #endif //ADVANCE
749
     }
745
     }
750
     else {
746
     else {
1201
 
1197
 
1202
     SPI.begin();
1198
     SPI.begin();
1203
     pinMode(DIGIPOTSS_PIN, OUTPUT);
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
       //digitalPotWrite(digipot_ch[i], digipot_motor_current[i]);
1201
       //digitalPotWrite(digipot_ch[i], digipot_motor_current[i]);
1206
       digipot_current(i, digipot_motor_current[i]);
1202
       digipot_current(i, digipot_motor_current[i]);
1207
     }
1203
     }

Loading…
Cancel
Save