Bladeren bron

Fewer temporary vars in planner accel limit

Scott Lahteine 8 jaren geleden
bovenliggende
commit
209f5c03d0
1 gewijzigde bestanden met toevoegingen van 19 en 24 verwijderingen
  1. 19
    24
      Marlin/planner.cpp

+ 19
- 24
Marlin/planner.cpp Bestand weergeven

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

Laden…
Annuleren
Opslaan