Fewer temporary vars in planner accel limit

This commit is contained in:
Scott Lahteine 2016-07-20 18:29:29 -07:00
parent 194d9521c3
commit 209f5c03d0

View file

@ -946,28 +946,23 @@ void Planner::check_axes_activity() {
// Compute and limit the acceleration rate for the trapezoid generator. // Compute and limit the acceleration rate for the trapezoid generator.
float steps_per_mm = block->step_event_count / block->millimeters; float steps_per_mm = block->step_event_count / block->millimeters;
long bsx = block->steps[X_AXIS], bsy = block->steps[Y_AXIS], bsz = block->steps[Z_AXIS], bse = block->steps[E_AXIS]; block->acceleration_steps_per_s2 = ceil((
if (bsx == 0 && bsy == 0 && bsz == 0) { (block->steps[X_AXIS] == 0 && block->steps[Y_AXIS] == 0 && block->steps[Z_AXIS] == 0) ?
block->acceleration_steps_per_s2 = ceil(retract_acceleration * steps_per_mm); // convert to: acceleration steps/sec^2 retract_acceleration : block->steps[E_AXIS] == 0 ?
} travel_acceleration :
else if (bse == 0) { acceleration
block->acceleration_steps_per_s2 = ceil(travel_acceleration * steps_per_mm); // convert to: acceleration steps/sec^2 ) * steps_per_mm
} );
else {
block->acceleration_steps_per_s2 = ceil(acceleration * steps_per_mm); // convert to: acceleration steps/sec^2
}
// Limit acceleration per axis // Limit acceleration per axis
unsigned long acc_st = block->acceleration_steps_per_s2, long acc_st = block->acceleration_steps_per_s2;
x_acc_st = max_acceleration_steps_per_s2[X_AXIS], if (max_acceleration_steps_per_s2[X_AXIS] < (acc_st * block->steps[X_AXIS]) / block->step_event_count)
y_acc_st = max_acceleration_steps_per_s2[Y_AXIS], acc_st = (max_acceleration_steps_per_s2[X_AXIS] * block->step_event_count) / block->steps[X_AXIS];
z_acc_st = max_acceleration_steps_per_s2[Z_AXIS], if (max_acceleration_steps_per_s2[Y_AXIS] < (acc_st * block->steps[Y_AXIS]) / block->step_event_count)
e_acc_st = max_acceleration_steps_per_s2[E_AXIS], acc_st = (max_acceleration_steps_per_s2[Y_AXIS] * block->step_event_count) / block->steps[Y_AXIS];
allsteps = block->step_event_count; if (max_acceleration_steps_per_s2[Z_AXIS] < (acc_st * block->steps[Z_AXIS]) / block->step_event_count)
if (x_acc_st < (acc_st * bsx) / allsteps) acc_st = (x_acc_st * allsteps) / bsx; acc_st = (max_acceleration_steps_per_s2[Z_AXIS] * block->step_event_count) / block->steps[Z_AXIS];
if (y_acc_st < (acc_st * bsy) / allsteps) acc_st = (y_acc_st * allsteps) / bsy; if (max_acceleration_steps_per_s2[E_AXIS] < (acc_st * block->steps[E_AXIS]) / block->step_event_count)
if (z_acc_st < (acc_st * bsz) / allsteps) acc_st = (z_acc_st * allsteps) / bsz; acc_st = (max_acceleration_steps_per_s2[E_AXIS] * block->step_event_count) / block->steps[E_AXIS];
if (e_acc_st < (acc_st * bse) / allsteps) acc_st = (e_acc_st * allsteps) / bse;
block->acceleration_steps_per_s2 = acc_st; block->acceleration_steps_per_s2 = acc_st;
block->acceleration = acc_st / steps_per_mm; block->acceleration = acc_st / steps_per_mm;
block->acceleration_rate = (long)(acc_st * 16777216.0 / (F_CPU / 8.0)); block->acceleration_rate = (long)(acc_st * 16777216.0 / (F_CPU / 8.0));
@ -1064,12 +1059,12 @@ void Planner::check_axes_activity() {
#if ENABLED(LIN_ADVANCE) #if ENABLED(LIN_ADVANCE)
// bse == allsteps: A problem occurs when there's a very tiny move before a retract. // block->steps[E_AXIS] == block->step_event_count: A problem occurs when there's a very tiny move before a retract.
// In this case, the retract and the move will be executed together. // In this case, the retract and the move will be executed together.
// This leads to an enormous number of advance steps due to a huge e_acceleration. // This leads to an enormous number of advance steps due to a huge e_acceleration.
// The math is correct, but you don't want a retract move done with advance! // The math is correct, but you don't want a retract move done with advance!
// So this situation is filtered out here. // So this situation is filtered out here.
if (!bse || (!bsx && !bsy && !bsz) || stepper.get_advance_k() == 0 || (uint32_t) bse == allsteps) { 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) {
block->use_advance_lead = false; block->use_advance_lead = false;
} }
else { else {
@ -1080,7 +1075,7 @@ void Planner::check_axes_activity() {
#elif ENABLED(ADVANCE) #elif ENABLED(ADVANCE)
// Calculate advance rate // Calculate advance rate
if (!bse || (!bsx && !bsy && !bsz)) { if (!block->steps[E_AXIS] || (!block->steps[X_AXIS] && !block->steps[Y_AXIS] && !block->steps[Z_AXIS])) {
block->advance_rate = 0; block->advance_rate = 0;
block->advance = 0; block->advance = 0;
} }