Overhaul of the planner (#11578)
- Move FWRETRACT to the planner - Combine leveling, skew, etc. in a single modifier method - Have kinematic and non-kinematic moves call one planner method
This commit is contained in:
committed by
Scott Lahteine
parent
8323a08642
commit
c437bb08f1
@ -25,15 +25,12 @@
|
||||
#if HAS_LEVELING
|
||||
|
||||
#include "bedlevel.h"
|
||||
#include "../../module/planner.h"
|
||||
|
||||
#if ENABLED(MESH_BED_LEVELING) || ENABLED(PROBE_MANUALLY)
|
||||
#include "../../module/motion.h"
|
||||
#endif
|
||||
|
||||
#if PLANNER_LEVELING
|
||||
#include "../../module/planner.h"
|
||||
#endif
|
||||
|
||||
#if ENABLED(PROBE_MANUALLY)
|
||||
bool g29_in_progress = false;
|
||||
#endif
|
||||
@ -79,74 +76,24 @@ void set_bed_leveling_enabled(const bool enable/*=true*/) {
|
||||
|
||||
planner.synchronize();
|
||||
|
||||
#if ENABLED(MESH_BED_LEVELING)
|
||||
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
||||
// Force bilinear_z_offset to re-calculate next time
|
||||
const float reset[XYZ] = { -9999.999, -9999.999, 0 };
|
||||
(void)bilinear_z_offset(reset);
|
||||
#endif
|
||||
|
||||
if (!enable)
|
||||
planner.apply_leveling(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS]);
|
||||
if (planner.leveling_active) { // leveling from on to off
|
||||
// change unleveled current_position to physical current_position without moving steppers.
|
||||
planner.apply_leveling(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS]);
|
||||
planner.leveling_active = false; // disable only AFTER calling apply_leveling
|
||||
}
|
||||
else { // leveling from off to on
|
||||
planner.leveling_active = true; // enable BEFORE calling unapply_leveling, otherwise ignored
|
||||
// change physical current_position to unleveled current_position without moving steppers.
|
||||
planner.unapply_leveling(current_position);
|
||||
}
|
||||
|
||||
const bool enabling = enable && leveling_is_valid();
|
||||
planner.leveling_active = enabling;
|
||||
if (enabling) planner.unapply_leveling(current_position);
|
||||
|
||||
#elif ENABLED(AUTO_BED_LEVELING_UBL)
|
||||
#if PLANNER_LEVELING
|
||||
if (planner.leveling_active) { // leveling from on to off
|
||||
// change unleveled current_position to physical current_position without moving steppers.
|
||||
planner.apply_leveling(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS]);
|
||||
planner.leveling_active = false; // disable only AFTER calling apply_leveling
|
||||
}
|
||||
else { // leveling from off to on
|
||||
planner.leveling_active = true; // enable BEFORE calling unapply_leveling, otherwise ignored
|
||||
// change physical current_position to unleveled current_position without moving steppers.
|
||||
planner.unapply_leveling(current_position);
|
||||
}
|
||||
#else
|
||||
// UBL equivalents for apply/unapply_leveling
|
||||
#if ENABLED(SKEW_CORRECTION)
|
||||
float pos[XYZ] = { current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] };
|
||||
planner.skew(pos[X_AXIS], pos[Y_AXIS], pos[Z_AXIS]);
|
||||
#else
|
||||
const float (&pos)[XYZE] = current_position;
|
||||
#endif
|
||||
if (planner.leveling_active) {
|
||||
current_position[Z_AXIS] += ubl.get_z_correction(pos[X_AXIS], pos[Y_AXIS]);
|
||||
planner.leveling_active = false;
|
||||
}
|
||||
else {
|
||||
planner.leveling_active = true;
|
||||
current_position[Z_AXIS] -= ubl.get_z_correction(pos[X_AXIS], pos[Y_AXIS]);
|
||||
}
|
||||
#endif
|
||||
|
||||
#else // OLDSCHOOL_ABL
|
||||
|
||||
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
||||
// Force bilinear_z_offset to re-calculate next time
|
||||
const float reset[XYZ] = { -9999.999, -9999.999, 0 };
|
||||
(void)bilinear_z_offset(reset);
|
||||
#endif
|
||||
|
||||
// Enable or disable leveling compensation in the planner
|
||||
planner.leveling_active = enable;
|
||||
|
||||
if (!enable)
|
||||
// When disabling just get the current position from the steppers.
|
||||
// This will yield the smallest error when first converted back to steps.
|
||||
set_current_from_steppers_for_axis(
|
||||
#if ABL_PLANAR
|
||||
ALL_AXES
|
||||
#else
|
||||
Z_AXIS
|
||||
#endif
|
||||
);
|
||||
else
|
||||
// When enabling, remove compensation from the current position,
|
||||
// so compensation will give the right stepper counts.
|
||||
planner.unapply_leveling(current_position);
|
||||
|
||||
SYNC_PLAN_POSITION_KINEMATIC();
|
||||
|
||||
#endif // OLDSCHOOL_ABL
|
||||
sync_plan_position();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user