|
|
|
@ -544,14 +544,14 @@ static uint8_t target_extruder;
|
|
|
|
|
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
|
|
|
|
#if ENABLED(DELTA)
|
|
|
|
|
#define ADJUST_DELTA(V) \
|
|
|
|
|
if (planner.abl_enabled) { \
|
|
|
|
|
if (planner.leveling_active) { \
|
|
|
|
|
const float zadj = bilinear_z_offset(V); \
|
|
|
|
|
delta[A_AXIS] += zadj; \
|
|
|
|
|
delta[B_AXIS] += zadj; \
|
|
|
|
|
delta[C_AXIS] += zadj; \
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
#define ADJUST_DELTA(V) if (planner.abl_enabled) { delta[Z_AXIS] += bilinear_z_offset(V); }
|
|
|
|
|
#define ADJUST_DELTA(V) if (planner.leveling_active) { delta[Z_AXIS] += bilinear_z_offset(V); }
|
|
|
|
|
#endif
|
|
|
|
|
#elif IS_KINEMATIC
|
|
|
|
|
#define ADJUST_DELTA(V) NOOP
|
|
|
|
@ -2460,7 +2460,7 @@ static void clean_up_after_endstop_or_probe_move() {
|
|
|
|
|
bool leveling_is_valid() {
|
|
|
|
|
return
|
|
|
|
|
#if ENABLED(MESH_BED_LEVELING)
|
|
|
|
|
mbl.has_mesh()
|
|
|
|
|
mbl.has_mesh
|
|
|
|
|
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
|
|
|
|
!!bilinear_grid_spacing[X_AXIS]
|
|
|
|
|
#elif ENABLED(AUTO_BED_LEVELING_UBL)
|
|
|
|
@ -2486,7 +2486,7 @@ static void clean_up_after_endstop_or_probe_move() {
|
|
|
|
|
constexpr bool can_change = true;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if (can_change && enable != LEVELING_IS_ACTIVE()) {
|
|
|
|
|
if (can_change && enable != planner.leveling_active) {
|
|
|
|
|
|
|
|
|
|
#if ENABLED(MESH_BED_LEVELING)
|
|
|
|
|
|
|
|
|
@ -2494,23 +2494,23 @@ static void clean_up_after_endstop_or_probe_move() {
|
|
|
|
|
planner.apply_leveling(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS]);
|
|
|
|
|
|
|
|
|
|
const bool enabling = enable && leveling_is_valid();
|
|
|
|
|
mbl.set_active(enabling);
|
|
|
|
|
planner.leveling_active = enabling;
|
|
|
|
|
if (enabling) planner.unapply_leveling(current_position);
|
|
|
|
|
|
|
|
|
|
#elif ENABLED(AUTO_BED_LEVELING_UBL)
|
|
|
|
|
#if PLANNER_LEVELING
|
|
|
|
|
if (ubl.state.active) { // leveling from on to off
|
|
|
|
|
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]);
|
|
|
|
|
ubl.state.active = false; // disable only AFTER calling apply_leveling
|
|
|
|
|
planner.leveling_active = false; // disable only AFTER calling apply_leveling
|
|
|
|
|
}
|
|
|
|
|
else { // leveling from off to on
|
|
|
|
|
ubl.state.active = true; // enable BEFORE calling unapply_leveling, otherwise ignored
|
|
|
|
|
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.state.active = enable; // just flip the bit, current_position will be wrong until next move.
|
|
|
|
|
planner.leveling_active = enable; // just flip the bit, current_position will be wrong until next move.
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#else // ABL
|
|
|
|
@ -2522,7 +2522,7 @@ static void clean_up_after_endstop_or_probe_move() {
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Enable or disable leveling compensation in the planner
|
|
|
|
|
planner.abl_enabled = enable;
|
|
|
|
|
planner.leveling_active = enable;
|
|
|
|
|
|
|
|
|
|
if (!enable)
|
|
|
|
|
// When disabling just get the current position from the steppers.
|
|
|
|
@ -2547,23 +2547,18 @@ static void clean_up_after_endstop_or_probe_move() {
|
|
|
|
|
|
|
|
|
|
void set_z_fade_height(const float zfh) {
|
|
|
|
|
|
|
|
|
|
const bool level_active = LEVELING_IS_ACTIVE();
|
|
|
|
|
const bool level_active = planner.leveling_active;
|
|
|
|
|
|
|
|
|
|
#if ENABLED(AUTO_BED_LEVELING_UBL)
|
|
|
|
|
if (level_active) set_bed_leveling_enabled(false); // turn off before changing fade height for proper apply/unapply leveling to maintain current_position
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if (level_active)
|
|
|
|
|
set_bed_leveling_enabled(false); // turn off before changing fade height for proper apply/unapply leveling to maintain current_position
|
|
|
|
|
planner.z_fade_height = zfh;
|
|
|
|
|
planner.inverse_z_fade_height = RECIPROCAL(zfh);
|
|
|
|
|
if (level_active)
|
|
|
|
|
set_bed_leveling_enabled(true); // turn back on after changing fade height
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
planner.z_fade_height = zfh;
|
|
|
|
|
planner.inverse_z_fade_height = RECIPROCAL(zfh);
|
|
|
|
|
planner.set_z_fade_height(zfh);
|
|
|
|
|
|
|
|
|
|
if (level_active) {
|
|
|
|
|
if (level_active) {
|
|
|
|
|
#if ENABLED(AUTO_BED_LEVELING_UBL)
|
|
|
|
|
set_bed_leveling_enabled(true); // turn back on after changing fade height
|
|
|
|
|
#else
|
|
|
|
|
set_current_from_steppers_for_axis(
|
|
|
|
|
#if ABL_PLANAR
|
|
|
|
|
ALL_AXES
|
|
|
|
@ -2571,8 +2566,8 @@ static void clean_up_after_endstop_or_probe_move() {
|
|
|
|
|
Z_AXIS
|
|
|
|
|
#endif
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif // LEVELING_FADE_HEIGHT
|
|
|
|
@ -2585,7 +2580,7 @@ static void clean_up_after_endstop_or_probe_move() {
|
|
|
|
|
#if ENABLED(MESH_BED_LEVELING)
|
|
|
|
|
if (leveling_is_valid()) {
|
|
|
|
|
mbl.reset();
|
|
|
|
|
mbl.set_has_mesh(false);
|
|
|
|
|
mbl.has_mesh = false;
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
#if ENABLED(DEBUG_LEVELING_FEATURE)
|
|
|
|
@ -3759,7 +3754,7 @@ inline void gcode_G4() {
|
|
|
|
|
#elif ENABLED(AUTO_BED_LEVELING_UBL)
|
|
|
|
|
SERIAL_ECHOPGM("UBL");
|
|
|
|
|
#endif
|
|
|
|
|
if (LEVELING_IS_ACTIVE()) {
|
|
|
|
|
if (planner.leveling_active) {
|
|
|
|
|
SERIAL_ECHOLNPGM(" (enabled)");
|
|
|
|
|
#if ABL_PLANAR
|
|
|
|
|
const float diff[XYZ] = {
|
|
|
|
@ -3790,7 +3785,7 @@ inline void gcode_G4() {
|
|
|
|
|
#elif ENABLED(MESH_BED_LEVELING)
|
|
|
|
|
|
|
|
|
|
SERIAL_ECHOPGM("Mesh Bed Leveling");
|
|
|
|
|
if (LEVELING_IS_ACTIVE()) {
|
|
|
|
|
if (planner.leveling_active) {
|
|
|
|
|
float lz = current_position[Z_AXIS];
|
|
|
|
|
planner.apply_leveling(current_position[X_AXIS], current_position[Y_AXIS], lz);
|
|
|
|
|
SERIAL_ECHOLNPGM(" (enabled)");
|
|
|
|
@ -3959,7 +3954,7 @@ inline void gcode_G28(const bool always_home_all) {
|
|
|
|
|
// Disable the leveling matrix before homing
|
|
|
|
|
#if HAS_LEVELING
|
|
|
|
|
#if ENABLED(AUTO_BED_LEVELING_UBL)
|
|
|
|
|
const bool ubl_state_at_entry = LEVELING_IS_ACTIVE();
|
|
|
|
|
const bool ubl_state_at_entry = planner.leveling_active;
|
|
|
|
|
#endif
|
|
|
|
|
set_bed_leveling_enabled(false);
|
|
|
|
|
#endif
|
|
|
|
@ -4199,7 +4194,7 @@ void home_all_axes() { gcode_G28(true); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void mesh_probing_done() {
|
|
|
|
|
mbl.set_has_mesh(true);
|
|
|
|
|
mbl.has_mesh = true;
|
|
|
|
|
home_all_axes();
|
|
|
|
|
set_bed_leveling_enabled(true);
|
|
|
|
|
#if ENABLED(MESH_G28_REST_ORIGIN)
|
|
|
|
@ -4249,7 +4244,7 @@ void home_all_axes() { gcode_G28(true); }
|
|
|
|
|
switch (state) {
|
|
|
|
|
case MeshReport:
|
|
|
|
|
if (leveling_is_valid()) {
|
|
|
|
|
SERIAL_PROTOCOLLNPAIR("State: ", LEVELING_IS_ACTIVE() ? MSG_ON : MSG_OFF);
|
|
|
|
|
SERIAL_PROTOCOLLNPAIR("State: ", planner.leveling_active ? MSG_ON : MSG_OFF);
|
|
|
|
|
mbl_mesh_report();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
@ -4568,7 +4563,7 @@ void home_all_axes() { gcode_G28(true); }
|
|
|
|
|
abl_probe_index = -1;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
abl_should_enable = LEVELING_IS_ACTIVE();
|
|
|
|
|
abl_should_enable = planner.leveling_active;
|
|
|
|
|
|
|
|
|
|
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
|
|
|
|
|
|
|
|
@ -4708,7 +4703,7 @@ void home_all_axes() { gcode_G28(true); }
|
|
|
|
|
stepper.synchronize();
|
|
|
|
|
|
|
|
|
|
// Disable auto bed leveling during G29
|
|
|
|
|
planner.abl_enabled = false;
|
|
|
|
|
planner.leveling_active = false;
|
|
|
|
|
|
|
|
|
|
if (!dryrun) {
|
|
|
|
|
// Re-orient the current position without leveling
|
|
|
|
@ -4722,7 +4717,7 @@ void home_all_axes() { gcode_G28(true); }
|
|
|
|
|
#if HAS_BED_PROBE
|
|
|
|
|
// Deploy the probe. Probe will raise if needed.
|
|
|
|
|
if (DEPLOY_PROBE()) {
|
|
|
|
|
planner.abl_enabled = abl_should_enable;
|
|
|
|
|
planner.leveling_active = abl_should_enable;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
@ -4741,7 +4736,7 @@ void home_all_axes() { gcode_G28(true); }
|
|
|
|
|
) {
|
|
|
|
|
if (dryrun) {
|
|
|
|
|
// Before reset bed level, re-enable to correct the position
|
|
|
|
|
planner.abl_enabled = abl_should_enable;
|
|
|
|
|
planner.leveling_active = abl_should_enable;
|
|
|
|
|
}
|
|
|
|
|
// Reset grid to 0.0 or "not probed". (Also disables ABL)
|
|
|
|
|
reset_bed_level();
|
|
|
|
@ -4786,7 +4781,7 @@ void home_all_axes() { gcode_G28(true); }
|
|
|
|
|
#if HAS_SOFTWARE_ENDSTOPS
|
|
|
|
|
soft_endstops_enabled = enable_soft_endstops;
|
|
|
|
|
#endif
|
|
|
|
|
planner.abl_enabled = abl_should_enable;
|
|
|
|
|
planner.leveling_active = abl_should_enable;
|
|
|
|
|
g29_in_progress = false;
|
|
|
|
|
#if ENABLED(LCD_BED_LEVELING)
|
|
|
|
|
lcd_wait_for_move = false;
|
|
|
|
@ -4987,7 +4982,7 @@ void home_all_axes() { gcode_G28(true); }
|
|
|
|
|
measured_z = faux ? 0.001 * random(-100, 101) : probe_pt(xProbe, yProbe, stow_probe_after_each, verbose_level);
|
|
|
|
|
|
|
|
|
|
if (isnan(measured_z)) {
|
|
|
|
|
planner.abl_enabled = abl_should_enable;
|
|
|
|
|
planner.leveling_active = abl_should_enable;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -5023,7 +5018,7 @@ void home_all_axes() { gcode_G28(true); }
|
|
|
|
|
yProbe = LOGICAL_Y_POSITION(points[i].y);
|
|
|
|
|
measured_z = faux ? 0.001 * random(-100, 101) : probe_pt(xProbe, yProbe, stow_probe_after_each, verbose_level);
|
|
|
|
|
if (isnan(measured_z)) {
|
|
|
|
|
planner.abl_enabled = abl_should_enable;
|
|
|
|
|
planner.leveling_active = abl_should_enable;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
points[i].z = measured_z;
|
|
|
|
@ -5046,7 +5041,7 @@ void home_all_axes() { gcode_G28(true); }
|
|
|
|
|
|
|
|
|
|
// Raise to _Z_CLEARANCE_DEPLOY_PROBE. Stow the probe.
|
|
|
|
|
if (STOW_PROBE()) {
|
|
|
|
|
planner.abl_enabled = abl_should_enable;
|
|
|
|
|
planner.leveling_active = abl_should_enable;
|
|
|
|
|
measured_z = NAN;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -5214,9 +5209,9 @@ void home_all_axes() { gcode_G28(true); }
|
|
|
|
|
float converted[XYZ];
|
|
|
|
|
COPY(converted, current_position);
|
|
|
|
|
|
|
|
|
|
planner.abl_enabled = true;
|
|
|
|
|
planner.leveling_active = true;
|
|
|
|
|
planner.unapply_leveling(converted); // use conversion machinery
|
|
|
|
|
planner.abl_enabled = false;
|
|
|
|
|
planner.leveling_active = false;
|
|
|
|
|
|
|
|
|
|
// Use the last measured distance to the bed, if possible
|
|
|
|
|
if ( NEAR(current_position[X_AXIS], xProbe - (X_PROBE_OFFSET_FROM_EXTRUDER))
|
|
|
|
@ -5268,7 +5263,7 @@ void home_all_axes() { gcode_G28(true); }
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Auto Bed Leveling is complete! Enable if possible.
|
|
|
|
|
planner.abl_enabled = dryrun ? abl_should_enable : true;
|
|
|
|
|
planner.leveling_active = dryrun ? abl_should_enable : true;
|
|
|
|
|
} // !isnan(measured_z)
|
|
|
|
|
|
|
|
|
|
// Restore state after probing
|
|
|
|
@ -5282,7 +5277,7 @@ void home_all_axes() { gcode_G28(true); }
|
|
|
|
|
|
|
|
|
|
KEEPALIVE_STATE(IN_HANDLER);
|
|
|
|
|
|
|
|
|
|
if (planner.abl_enabled)
|
|
|
|
|
if (planner.leveling_active)
|
|
|
|
|
SYNC_PLAN_POSITION_KINEMATIC();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -7065,7 +7060,7 @@ inline void gcode_M42() {
|
|
|
|
|
// Disable bed level correction in M48 because we want the raw data when we probe
|
|
|
|
|
|
|
|
|
|
#if HAS_LEVELING
|
|
|
|
|
const bool was_enabled = LEVELING_IS_ACTIVE();
|
|
|
|
|
const bool was_enabled = planner.leveling_active;
|
|
|
|
|
set_bed_leveling_enabled(false);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
@ -9401,7 +9396,7 @@ void quickstop_stepper() {
|
|
|
|
|
if (parser.seen('Z')) set_z_fade_height(parser.value_linear_units());
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
const bool new_status = LEVELING_IS_ACTIVE();
|
|
|
|
|
const bool new_status = planner.leveling_active;
|
|
|
|
|
|
|
|
|
|
if (to_enable && !new_status) {
|
|
|
|
|
SERIAL_ERROR_START();
|
|
|
|
@ -9632,7 +9627,7 @@ inline void gcode_M502() {
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if ENABLED(BABYSTEP_ZPROBE_OFFSET)
|
|
|
|
|
if (!no_babystep && LEVELING_IS_ACTIVE())
|
|
|
|
|
if (!no_babystep && planner.leveling_active)
|
|
|
|
|
thermalManager.babystep_axis(Z_AXIS, -LROUND(diff * planner.axis_steps_per_mm[Z_AXIS]));
|
|
|
|
|
#else
|
|
|
|
|
UNUSED(no_babystep);
|
|
|
|
@ -10679,7 +10674,7 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
|
|
|
|
|
|
|
|
|
|
#if ENABLED(MESH_BED_LEVELING)
|
|
|
|
|
|
|
|
|
|
if (LEVELING_IS_ACTIVE()) {
|
|
|
|
|
if (planner.leveling_active) {
|
|
|
|
|
#if ENABLED(DEBUG_LEVELING_FEATURE)
|
|
|
|
|
if (DEBUGGING(LEVELING)) SERIAL_ECHOPAIR("Z before MBL: ", current_position[Z_AXIS]);
|
|
|
|
|
#endif
|
|
|
|
@ -12377,39 +12372,28 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
|
|
|
|
|
* Prepare a linear move in a Cartesian setup.
|
|
|
|
|
* If Mesh Bed Leveling is enabled, perform a mesh move.
|
|
|
|
|
*
|
|
|
|
|
* Returns true if the caller didn't update current_position.
|
|
|
|
|
* Returns true if current_position[] was set to destination[]
|
|
|
|
|
*/
|
|
|
|
|
inline bool prepare_move_to_destination_cartesian() {
|
|
|
|
|
#if ENABLED(AUTO_BED_LEVELING_UBL)
|
|
|
|
|
if (current_position[X_AXIS] != destination[X_AXIS] || current_position[Y_AXIS] != destination[Y_AXIS]) {
|
|
|
|
|
const float fr_scaled = MMS_SCALED(feedrate_mm_s);
|
|
|
|
|
if (ubl.state.active) { // direct use of ubl.state.active for speed
|
|
|
|
|
ubl.line_to_destination_cartesian(fr_scaled, active_extruder);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
line_to_destination(fr_scaled);
|
|
|
|
|
#else
|
|
|
|
|
// Do not use feedrate_percentage for E or Z only moves
|
|
|
|
|
if (current_position[X_AXIS] == destination[X_AXIS] && current_position[Y_AXIS] == destination[Y_AXIS])
|
|
|
|
|
line_to_destination();
|
|
|
|
|
else {
|
|
|
|
|
const float fr_scaled = MMS_SCALED(feedrate_mm_s);
|
|
|
|
|
#if ENABLED(MESH_BED_LEVELING)
|
|
|
|
|
if (mbl.active()) { // direct used of mbl.active() for speed
|
|
|
|
|
#if HAS_LEVELING
|
|
|
|
|
if (planner.leveling_active) {
|
|
|
|
|
#if ENABLED(AUTO_BED_LEVELING_UBL)
|
|
|
|
|
ubl.line_to_destination_cartesian(fr_scaled, active_extruder);
|
|
|
|
|
#elif ENABLED(MESH_BED_LEVELING)
|
|
|
|
|
mesh_line_to_destination(fr_scaled);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
|
|
|
|
if (planner.abl_enabled) { // direct use of abl_enabled for speed
|
|
|
|
|
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
|
|
|
|
bilinear_line_to_destination(fr_scaled);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
#endif
|
|
|
|
|
line_to_destination(fr_scaled);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
#endif // HAS_LEVELING
|
|
|
|
|
line_to_destination(fr_scaled);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
line_to_destination();
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|