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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,12 +49,11 @@
|
||||
* as possible to determine if this is the case. If this move is within the same cell, we will
|
||||
* just do the required Z-Height correction, call the Planner's buffer_line() routine, and leave
|
||||
*/
|
||||
#if ENABLED(SKEW_CORRECTION)
|
||||
// For skew correction just adjust the destination point and we're done
|
||||
#if HAS_POSITION_MODIFIERS
|
||||
float start[XYZE] = { current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS] },
|
||||
end[XYZE] = { destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS] };
|
||||
planner.skew(start[X_AXIS], start[Y_AXIS], start[Z_AXIS]);
|
||||
planner.skew(end[X_AXIS], end[Y_AXIS], end[Z_AXIS]);
|
||||
planner.apply_modifiers(start);
|
||||
planner.apply_modifiers(end);
|
||||
#else
|
||||
const float (&start)[XYZE] = current_position,
|
||||
(&end)[XYZE] = destination;
|
||||
@ -364,47 +363,6 @@
|
||||
|
||||
#else // UBL_SEGMENTED
|
||||
|
||||
#if IS_SCARA // scale the feed rate from mm/s to degrees/s
|
||||
static float scara_feed_factor, scara_oldA, scara_oldB;
|
||||
#endif
|
||||
|
||||
// We don't want additional apply_leveling() performed by regular buffer_line or buffer_line_kinematic,
|
||||
// so we call buffer_segment directly here. Per-segmented leveling and kinematics performed first.
|
||||
|
||||
inline void _O2 ubl_buffer_segment_raw(const float (&in_raw)[XYZE], const float &fr) {
|
||||
|
||||
#if ENABLED(SKEW_CORRECTION)
|
||||
float raw[XYZE] = { in_raw[X_AXIS], in_raw[Y_AXIS], in_raw[Z_AXIS] };
|
||||
planner.skew(raw[X_AXIS], raw[Y_AXIS], raw[Z_AXIS]);
|
||||
#else
|
||||
const float (&raw)[XYZE] = in_raw;
|
||||
#endif
|
||||
|
||||
#if ENABLED(DELTA) // apply delta inverse_kinematics
|
||||
|
||||
DELTA_IK(raw);
|
||||
planner.buffer_segment(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], in_raw[E_AXIS], fr, active_extruder);
|
||||
|
||||
#elif IS_SCARA // apply scara inverse_kinematics (should be changed to save raw->logical->raw)
|
||||
|
||||
inverse_kinematics(raw); // this writes delta[ABC] from raw[XYZE]
|
||||
// should move the feedrate scaling to scara inverse_kinematics
|
||||
|
||||
const float adiff = ABS(delta[A_AXIS] - scara_oldA),
|
||||
bdiff = ABS(delta[B_AXIS] - scara_oldB);
|
||||
scara_oldA = delta[A_AXIS];
|
||||
scara_oldB = delta[B_AXIS];
|
||||
float s_feedrate = MAX(adiff, bdiff) * scara_feed_factor;
|
||||
|
||||
planner.buffer_segment(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], in_raw[E_AXIS], s_feedrate, active_extruder);
|
||||
|
||||
#else // CARTESIAN
|
||||
|
||||
planner.buffer_segment(raw[X_AXIS], raw[Y_AXIS], raw[Z_AXIS], in_raw[E_AXIS], fr, active_extruder);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
#if IS_SCARA
|
||||
#define DELTA_SEGMENT_MIN_LENGTH 0.25 // SCARA minimum segment size is 0.25mm
|
||||
#elif ENABLED(DELTA)
|
||||
@ -449,10 +407,9 @@
|
||||
NOLESS(segments, 1U); // must have at least one segment
|
||||
const float inv_segments = 1.0f / segments; // divide once, multiply thereafter
|
||||
|
||||
#if IS_SCARA // scale the feed rate from mm/s to degrees/s
|
||||
scara_feed_factor = cartesian_xy_mm * inv_segments * feedrate;
|
||||
scara_oldA = planner.get_axis_position_degrees(A_AXIS);
|
||||
scara_oldB = planner.get_axis_position_degrees(B_AXIS);
|
||||
const float segment_xyz_mm = HYPOT(cartesian_xy_mm, total[Z_AXIS]) * inv_segments; // length of each segment
|
||||
#if ENABLED(SCARA_FEEDRATE_SCALING)
|
||||
const float inv_duration = feedrate / segment_xyz_mm;
|
||||
#endif
|
||||
|
||||
const float diff[XYZE] = {
|
||||
@ -476,9 +433,17 @@
|
||||
if (!planner.leveling_active || !planner.leveling_active_at_z(rtarget[Z_AXIS])) { // no mesh leveling
|
||||
while (--segments) {
|
||||
LOOP_XYZE(i) raw[i] += diff[i];
|
||||
ubl_buffer_segment_raw(raw, feedrate);
|
||||
planner.buffer_line(raw, feedrate, active_extruder, segment_xyz_mm
|
||||
#if ENABLED(SCARA_FEEDRATE_SCALING)
|
||||
, inv_duration
|
||||
#endif
|
||||
);
|
||||
}
|
||||
ubl_buffer_segment_raw(rtarget, feedrate);
|
||||
planner.buffer_line(rtarget, feedrate, active_extruder, segment_xyz_mm
|
||||
#if ENABLED(SCARA_FEEDRATE_SCALING)
|
||||
, inv_duration
|
||||
#endif
|
||||
);
|
||||
return false; // moved but did not set_current_from_destination();
|
||||
}
|
||||
|
||||
@ -554,7 +519,11 @@
|
||||
|
||||
const float z = raw[Z_AXIS];
|
||||
raw[Z_AXIS] += z_cxcy;
|
||||
ubl_buffer_segment_raw(raw, feedrate);
|
||||
planner.buffer_line(raw, feedrate, active_extruder, segment_xyz_mm
|
||||
#if ENABLED(SCARA_FEEDRATE_SCALING)
|
||||
, inv_duration
|
||||
#endif
|
||||
);
|
||||
raw[Z_AXIS] = z;
|
||||
|
||||
if (segments == 0) // done with last segment
|
||||
|
Reference in New Issue
Block a user