Browse Source

Merge pull request #4365 from thinkyhead/rc_shrink_planner_accel

Adjustments to planner acceleration limit
Scott Lahteine 8 years ago
parent
commit
7d869ad98b
1 changed files with 16 additions and 24 deletions
  1. 16
    24
      Marlin/planner.cpp

+ 16
- 24
Marlin/planner.cpp View File

946
 
946
 
947
   // Compute and limit the acceleration rate for the trapezoid generator.
947
   // Compute and limit the acceleration rate for the trapezoid generator.
948
   float steps_per_mm = block->step_event_count / block->millimeters;
948
   float steps_per_mm = block->step_event_count / block->millimeters;
949
-  long bsx = block->steps[X_AXIS], bsy = block->steps[Y_AXIS], bsz = block->steps[Z_AXIS], bse = block->steps[E_AXIS];
950
-  if (bsx == 0 && bsy == 0 && bsz == 0) {
949
+  if (!block->steps[X_AXIS] && !block->steps[Y_AXIS] && !block->steps[Z_AXIS]) {
951
     block->acceleration_steps_per_s2 = ceil(retract_acceleration * steps_per_mm); // convert to: acceleration steps/sec^2
950
     block->acceleration_steps_per_s2 = ceil(retract_acceleration * steps_per_mm); // convert to: acceleration steps/sec^2
952
   }
951
   }
953
-  else if (bse == 0) {
954
-    block->acceleration_steps_per_s2 = ceil(travel_acceleration * steps_per_mm); // convert to: acceleration steps/sec^2
955
-  }
956
   else {
952
   else {
957
-    block->acceleration_steps_per_s2 = ceil(acceleration * steps_per_mm); // convert to: acceleration steps/sec^2
953
+    // Limit acceleration per axis
954
+    block->acceleration_steps_per_s2 = ceil((block->steps[E_AXIS] ? acceleration : travel_acceleration) * steps_per_mm);
955
+    if (max_acceleration_steps_per_s2[X_AXIS] < (block->acceleration_steps_per_s2 * block->steps[X_AXIS]) / block->step_event_count)
956
+      block->acceleration_steps_per_s2 = (max_acceleration_steps_per_s2[X_AXIS] * block->step_event_count) / block->steps[X_AXIS];
957
+    if (max_acceleration_steps_per_s2[Y_AXIS] < (block->acceleration_steps_per_s2 * block->steps[Y_AXIS]) / block->step_event_count)
958
+      block->acceleration_steps_per_s2 = (max_acceleration_steps_per_s2[Y_AXIS] * block->step_event_count) / block->steps[Y_AXIS];
959
+    if (max_acceleration_steps_per_s2[Z_AXIS] < (block->acceleration_steps_per_s2 * block->steps[Z_AXIS]) / block->step_event_count)
960
+      block->acceleration_steps_per_s2 = (max_acceleration_steps_per_s2[Z_AXIS] * block->step_event_count) / block->steps[Z_AXIS];
961
+    if (max_acceleration_steps_per_s2[E_AXIS] < (block->acceleration_steps_per_s2 * block->steps[E_AXIS]) / block->step_event_count)
962
+      block->acceleration_steps_per_s2 = (max_acceleration_steps_per_s2[E_AXIS] * block->step_event_count) / block->steps[E_AXIS];
958
   }
963
   }
959
-  // Limit acceleration per axis
960
-  unsigned long acc_st = block->acceleration_steps_per_s2,
961
-                x_acc_st = max_acceleration_steps_per_s2[X_AXIS],
962
-                y_acc_st = max_acceleration_steps_per_s2[Y_AXIS],
963
-                z_acc_st = max_acceleration_steps_per_s2[Z_AXIS],
964
-                e_acc_st = max_acceleration_steps_per_s2[E_AXIS],
965
-                allsteps = block->step_event_count;
966
-  if (x_acc_st < (acc_st * bsx) / allsteps) acc_st = (x_acc_st * allsteps) / bsx;
967
-  if (y_acc_st < (acc_st * bsy) / allsteps) acc_st = (y_acc_st * allsteps) / bsy;
968
-  if (z_acc_st < (acc_st * bsz) / allsteps) acc_st = (z_acc_st * allsteps) / bsz;
969
-  if (e_acc_st < (acc_st * bse) / allsteps) acc_st = (e_acc_st * allsteps) / bse;
970
-
971
-  block->acceleration_steps_per_s2 = acc_st;
972
-  block->acceleration = acc_st / steps_per_mm;
973
-  block->acceleration_rate = (long)(acc_st * 16777216.0 / (F_CPU / 8.0));
964
+  block->acceleration = block->acceleration_steps_per_s2 / steps_per_mm;
965
+  block->acceleration_rate = (long)(block->acceleration_steps_per_s2 * 16777216.0 / ((F_CPU) / 8.0));
974
 
966
 
975
   #if 0  // Use old jerk for now
967
   #if 0  // Use old jerk for now
976
 
968
 
1064
 
1056
 
1065
   #if ENABLED(LIN_ADVANCE)
1057
   #if ENABLED(LIN_ADVANCE)
1066
 
1058
 
1067
-    // bse == allsteps: A problem occurs when there's a very tiny move before a retract.
1059
+    // block->steps[E_AXIS] == block->step_event_count: A problem occurs when there's a very tiny move before a retract.
1068
     // In this case, the retract and the move will be executed together.
1060
     // In this case, the retract and the move will be executed together.
1069
     // This leads to an enormous number of advance steps due to a huge e_acceleration.
1061
     // This leads to an enormous number of advance steps due to a huge e_acceleration.
1070
     // The math is correct, but you don't want a retract move done with advance!
1062
     // The math is correct, but you don't want a retract move done with advance!
1071
     // So this situation is filtered out here.
1063
     // So this situation is filtered out here.
1072
-    if (!bse || (!bsx && !bsy && !bsz) || stepper.get_advance_k() == 0 || (uint32_t) bse == allsteps) {
1064
+    if (!block->steps[E_AXIS] || (!block->steps[X_AXIS] && !block->steps[Y_AXIS] && !block->steps[Z_AXIS]) || stepper.get_advance_k() == 0 || (uint32_t) block->steps[E_AXIS] == block->step_event_count) {
1073
       block->use_advance_lead = false;
1065
       block->use_advance_lead = false;
1074
     }
1066
     }
1075
     else {
1067
     else {
1080
   #elif ENABLED(ADVANCE)
1072
   #elif ENABLED(ADVANCE)
1081
 
1073
 
1082
     // Calculate advance rate
1074
     // Calculate advance rate
1083
-    if (!bse || (!bsx && !bsy && !bsz)) {
1075
+    if (!block->steps[E_AXIS] || (!block->steps[X_AXIS] && !block->steps[Y_AXIS] && !block->steps[Z_AXIS])) {
1084
       block->advance_rate = 0;
1076
       block->advance_rate = 0;
1085
       block->advance = 0;
1077
       block->advance = 0;
1086
     }
1078
     }

Loading…
Cancel
Save