Use planner.leveling_active for all leveling systems
This commit is contained in:
@@ -68,7 +68,7 @@
|
||||
* 219 z_fade_height (float)
|
||||
*
|
||||
* MESH_BED_LEVELING: 43 bytes
|
||||
* 223 M420 S from mbl.status (bool)
|
||||
* 223 M420 S planner.leveling_active (bool)
|
||||
* 224 mbl.z_offset (float)
|
||||
* 228 GRID_MAX_POINTS_X (uint8_t)
|
||||
* 229 GRID_MAX_POINTS_Y (uint8_t)
|
||||
@@ -88,7 +88,7 @@
|
||||
* 316 z_values[][] (float x9, up to float x256) +988
|
||||
*
|
||||
* AUTO_BED_LEVELING_UBL: 2 bytes
|
||||
* 324 G29 A ubl.state.active (bool)
|
||||
* 324 G29 A planner.leveling_active (bool)
|
||||
* 325 G29 S ubl.state.storage_slot (int8_t)
|
||||
*
|
||||
* DELTA: 48 bytes
|
||||
@@ -202,6 +202,10 @@ MarlinSettings settings;
|
||||
#include "../feature/fwretract.h"
|
||||
#endif
|
||||
|
||||
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
|
||||
float new_z_fade_height;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Post-process after Retrieve or Reset
|
||||
*/
|
||||
@@ -231,7 +235,7 @@ void MarlinSettings::postprocess() {
|
||||
#endif
|
||||
|
||||
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
|
||||
set_z_fade_height(planner.z_fade_height);
|
||||
set_z_fade_height(new_z_fade_height);
|
||||
#endif
|
||||
|
||||
#if HAS_BED_PROBE
|
||||
@@ -329,7 +333,7 @@ void MarlinSettings::postprocess() {
|
||||
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
|
||||
const float zfh = planner.z_fade_height;
|
||||
#else
|
||||
const float zfh = 10.0;
|
||||
const float zfh = 0.0;
|
||||
#endif
|
||||
EEPROM_WRITE(zfh);
|
||||
|
||||
@@ -343,7 +347,7 @@ void MarlinSettings::postprocess() {
|
||||
sizeof(mbl.z_values) == GRID_MAX_POINTS * sizeof(mbl.z_values[0][0]),
|
||||
"MBL Z array is the wrong size."
|
||||
);
|
||||
const bool leveling_is_on = TEST(mbl.status, MBL_STATUS_HAS_MESH_BIT);
|
||||
const bool leveling_is_on = mbl.has_mesh;
|
||||
const uint8_t mesh_num_x = GRID_MAX_POINTS_X, mesh_num_y = GRID_MAX_POINTS_Y;
|
||||
EEPROM_WRITE(leveling_is_on);
|
||||
EEPROM_WRITE(mbl.z_offset);
|
||||
@@ -406,7 +410,7 @@ void MarlinSettings::postprocess() {
|
||||
#endif // AUTO_BED_LEVELING_BILINEAR
|
||||
|
||||
#if ENABLED(AUTO_BED_LEVELING_UBL)
|
||||
EEPROM_WRITE(ubl.state.active);
|
||||
EEPROM_WRITE(planner.leveling_active);
|
||||
EEPROM_WRITE(ubl.state.storage_slot);
|
||||
#else
|
||||
const bool ubl_active = false;
|
||||
@@ -720,7 +724,7 @@ void MarlinSettings::postprocess() {
|
||||
//
|
||||
|
||||
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
|
||||
EEPROM_READ(planner.z_fade_height);
|
||||
EEPROM_READ(new_z_fade_height);
|
||||
#else
|
||||
EEPROM_READ(dummy);
|
||||
#endif
|
||||
@@ -737,7 +741,7 @@ void MarlinSettings::postprocess() {
|
||||
EEPROM_READ(mesh_num_y);
|
||||
|
||||
#if ENABLED(MESH_BED_LEVELING)
|
||||
mbl.status = leveling_is_on ? _BV(MBL_STATUS_HAS_MESH_BIT) : 0;
|
||||
mbl.has_mesh = leveling_is_on;
|
||||
mbl.z_offset = dummy;
|
||||
if (mesh_num_x == GRID_MAX_POINTS_X && mesh_num_y == GRID_MAX_POINTS_Y) {
|
||||
// EEPROM data fits the current mesh
|
||||
@@ -793,7 +797,7 @@ void MarlinSettings::postprocess() {
|
||||
}
|
||||
|
||||
#if ENABLED(AUTO_BED_LEVELING_UBL)
|
||||
EEPROM_READ(ubl.state.active);
|
||||
EEPROM_READ(planner.leveling_active);
|
||||
EEPROM_READ(ubl.state.storage_slot);
|
||||
#else
|
||||
uint8_t dummyui8;
|
||||
@@ -1156,7 +1160,7 @@ void MarlinSettings::reset() {
|
||||
planner.max_jerk[E_AXIS] = DEFAULT_EJERK;
|
||||
|
||||
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
|
||||
planner.z_fade_height = 0.0;
|
||||
new_z_fade_height = 0.0;
|
||||
#endif
|
||||
|
||||
#if HAS_HOME_OFFSET
|
||||
@@ -1556,9 +1560,9 @@ void MarlinSettings::reset() {
|
||||
SERIAL_ECHOLNPGM(":");
|
||||
}
|
||||
CONFIG_ECHO_START;
|
||||
SERIAL_ECHOPAIR(" M420 S", LEVELING_IS_ACTIVE() ? 1 : 0);
|
||||
SERIAL_ECHOPAIR(" M420 S", planner.leveling_active ? 1 : 0);
|
||||
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
|
||||
SERIAL_ECHOPAIR(" Z", planner.z_fade_height);
|
||||
SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(planner.z_fade_height));
|
||||
#endif
|
||||
SERIAL_EOL();
|
||||
|
||||
@@ -1578,7 +1582,7 @@ void MarlinSettings::reset() {
|
||||
SERIAL_ECHOLNPGM("Auto Bed Leveling:");
|
||||
}
|
||||
CONFIG_ECHO_START;
|
||||
SERIAL_ECHOPAIR(" M420 S", LEVELING_IS_ACTIVE() ? 1 : 0);
|
||||
SERIAL_ECHOPAIR(" M420 S", planner.leveling_active ? 1 : 0);
|
||||
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
|
||||
SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(planner.z_fade_height));
|
||||
#endif
|
||||
|
@@ -490,14 +490,14 @@ float soft_endstop_min[XYZ] = { X_MIN_BED, Y_MIN_BED, Z_MIN_POS },
|
||||
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
||||
#if ENABLED(DELTA)
|
||||
#define ADJUST_DELTA(V) \
|
||||
if (LEVELING_IS_ACTIVE()) { \
|
||||
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 (LEVELING_IS_ACTIVE()) { delta[Z_AXIS] += bilinear_z_offset(V); }
|
||||
#define ADJUST_DELTA(V) if (planner.leveling_active) { delta[Z_AXIS] += bilinear_z_offset(V); }
|
||||
#endif
|
||||
#else
|
||||
#define ADJUST_DELTA(V) NOOP
|
||||
@@ -630,41 +630,30 @@ float soft_endstop_min[XYZ] = { X_MIN_BED, Y_MIN_BED, Z_MIN_POS },
|
||||
|
||||
/**
|
||||
* Prepare a linear move in a Cartesian setup.
|
||||
* If Mesh Bed Leveling is enabled, perform a mesh move.
|
||||
* Bed Leveling will be applied to the move if enabled.
|
||||
*
|
||||
* 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_MESH
|
||||
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_MESH
|
||||
line_to_destination(fr_scaled);
|
||||
}
|
||||
else
|
||||
line_to_destination();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -699,6 +688,8 @@ float soft_endstop_min[XYZ] = { X_MIN_BED, Y_MIN_BED, Z_MIN_POS },
|
||||
|
||||
/**
|
||||
* Prepare a linear move in a dual X axis setup
|
||||
*
|
||||
* Return true if current_position[] was set to destination[]
|
||||
*/
|
||||
inline bool prepare_move_to_destination_dualx() {
|
||||
if (active_extruder_parked) {
|
||||
|
@@ -122,8 +122,8 @@ float Planner::min_feedrate_mm_s,
|
||||
Planner::max_jerk[XYZE], // The largest speed change requiring no acceleration
|
||||
Planner::min_travel_feedrate_mm_s;
|
||||
|
||||
#if OLDSCHOOL_ABL
|
||||
bool Planner::abl_enabled = false; // Flag that auto bed leveling is enabled
|
||||
#if HAS_LEVELING
|
||||
bool Planner::leveling_active = false; // Flag that auto bed leveling is enabled
|
||||
#if ABL_PLANAR
|
||||
matrix_3x3 Planner::bed_level_matrix; // Transform to compensate for bed level
|
||||
#endif
|
||||
@@ -556,7 +556,7 @@ void Planner::calculate_volumetric_multipliers() {
|
||||
*/
|
||||
void Planner::apply_leveling(float &lx, float &ly, float &lz) {
|
||||
|
||||
if (!LEVELING_IS_ACTIVE()) return;
|
||||
if (!planner.leveling_active) return;
|
||||
|
||||
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
|
||||
const float fade_scaling_factor = fade_scaling_factor_for_z(lz);
|
||||
@@ -601,48 +601,41 @@ void Planner::calculate_volumetric_multipliers() {
|
||||
|
||||
void Planner::unapply_leveling(float logical[XYZ]) {
|
||||
|
||||
#if ENABLED(AUTO_BED_LEVELING_UBL)
|
||||
|
||||
if (ubl.state.active) {
|
||||
|
||||
const float z_physical = RAW_Z_POSITION(logical[Z_AXIS]),
|
||||
z_correct = ubl.get_z_correction(logical[X_AXIS], logical[Y_AXIS]),
|
||||
z_virtual = z_physical - z_correct;
|
||||
float z_logical = LOGICAL_Z_POSITION(z_virtual);
|
||||
|
||||
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
|
||||
|
||||
// for P=physical_z, L=logical_z, M=mesh_z, H=fade_height,
|
||||
// Given P=L+M(1-L/H) (faded mesh correction formula for L<H)
|
||||
// then L=P-M(1-L/H)
|
||||
// so L=P-M+ML/H
|
||||
// so L-ML/H=P-M
|
||||
// so L(1-M/H)=P-M
|
||||
// so L=(P-M)/(1-M/H) for L<H
|
||||
|
||||
if (planner.z_fade_height) {
|
||||
if (z_logical >= planner.z_fade_height)
|
||||
z_logical = LOGICAL_Z_POSITION(z_physical);
|
||||
else
|
||||
z_logical /= 1.0 - z_correct * planner.inverse_z_fade_height;
|
||||
}
|
||||
|
||||
#endif // ENABLE_LEVELING_FADE_HEIGHT
|
||||
|
||||
logical[Z_AXIS] = z_logical;
|
||||
}
|
||||
|
||||
return; // don't fall thru to other ENABLE_LEVELING_FADE_HEIGHT logic
|
||||
|
||||
#endif
|
||||
|
||||
if (!LEVELING_IS_ACTIVE()) return;
|
||||
if (!planner.leveling_active) return;
|
||||
|
||||
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
|
||||
if (z_fade_height && RAW_Z_POSITION(logical[Z_AXIS]) >= z_fade_height) return;
|
||||
#endif
|
||||
|
||||
#if ENABLED(MESH_BED_LEVELING)
|
||||
#if ENABLED(AUTO_BED_LEVELING_UBL)
|
||||
|
||||
const float z_physical = RAW_Z_POSITION(logical[Z_AXIS]),
|
||||
z_correct = ubl.get_z_correction(logical[X_AXIS], logical[Y_AXIS]),
|
||||
z_virtual = z_physical - z_correct;
|
||||
float z_logical = LOGICAL_Z_POSITION(z_virtual);
|
||||
|
||||
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
|
||||
|
||||
// for P=physical_z, L=logical_z, M=mesh_z, H=fade_height,
|
||||
// Given P=L+M(1-L/H) (faded mesh correction formula for L<H)
|
||||
// then L=P-M(1-L/H)
|
||||
// so L=P-M+ML/H
|
||||
// so L-ML/H=P-M
|
||||
// so L(1-M/H)=P-M
|
||||
// so L=(P-M)/(1-M/H) for L<H
|
||||
|
||||
if (planner.z_fade_height) {
|
||||
if (z_logical >= planner.z_fade_height)
|
||||
z_logical = LOGICAL_Z_POSITION(z_physical);
|
||||
else
|
||||
z_logical /= 1.0 - z_correct * planner.inverse_z_fade_height;
|
||||
}
|
||||
|
||||
#endif // ENABLE_LEVELING_FADE_HEIGHT
|
||||
|
||||
logical[Z_AXIS] = z_logical;
|
||||
|
||||
#elif ENABLED(MESH_BED_LEVELING)
|
||||
|
||||
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
|
||||
const float c = mbl.get_z(RAW_X_POSITION(logical[X_AXIS]), RAW_Y_POSITION(logical[Y_AXIS]), 1.0);
|
||||
|
@@ -164,15 +164,14 @@ class Planner {
|
||||
max_jerk[XYZE], // The largest speed change requiring no acceleration
|
||||
min_travel_feedrate_mm_s;
|
||||
|
||||
#if OLDSCHOOL_ABL
|
||||
static bool abl_enabled; // Flag that bed leveling is enabled
|
||||
#if HAS_LEVELING
|
||||
static bool leveling_active; // Flag that bed leveling is enabled
|
||||
#if ABL_PLANAR
|
||||
static matrix_3x3 bed_level_matrix; // Transform to compensate for bed level
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
|
||||
static float z_fade_height, inverse_z_fade_height;
|
||||
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
|
||||
static float z_fade_height, inverse_z_fade_height;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if ENABLED(LIN_ADVANCE)
|
||||
@@ -292,6 +291,16 @@ class Planner {
|
||||
|
||||
FORCE_INLINE static void force_fade_recalc() { last_raw_lz = -999.999; }
|
||||
|
||||
FORCE_INLINE static void set_z_fade_height(const float &zfh) {
|
||||
z_fade_height = zfh > 0 ? zfh : 0;
|
||||
inverse_z_fade_height = RECIPROCAL(z_fade_height);
|
||||
force_fade_recalc();
|
||||
}
|
||||
|
||||
FORCE_INLINE static bool leveling_active_at_z(const float &lz) {
|
||||
return !z_fade_height || RAW_Z_POSITION(lz) < z_fade_height;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
FORCE_INLINE static float fade_scaling_factor_for_z(const float &lz) {
|
||||
@@ -299,6 +308,8 @@ class Planner {
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
FORCE_INLINE static bool leveling_active_at_z(const float &lz) { return true; }
|
||||
|
||||
#endif
|
||||
|
||||
#if PLANNER_LEVELING
|
||||
|
@@ -679,7 +679,7 @@ void refresh_zprobe_zoffset(const bool no_babystep/*=false*/) {
|
||||
#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);
|
||||
|
@@ -464,7 +464,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
|
||||
|
Reference in New Issue
Block a user