Move fade_scaling_factor_for_z to Planner
This commit is contained in:
@ -131,7 +131,8 @@ float Planner::min_feedrate_mm_s,
|
||||
|
||||
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
|
||||
float Planner::z_fade_height, // Initialized by settings.load()
|
||||
Planner::inverse_z_fade_height;
|
||||
Planner::inverse_z_fade_height,
|
||||
Planner::last_raw_lz;
|
||||
#endif
|
||||
|
||||
#if ENABLED(AUTOTEMP)
|
||||
@ -557,40 +558,29 @@ void Planner::calculate_volumetric_multipliers() {
|
||||
|
||||
if (!LEVELING_IS_ACTIVE()) return;
|
||||
|
||||
#if ENABLED(AUTO_BED_LEVELING_UBL)
|
||||
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
|
||||
// if z_fade_height enabled (nonzero) and raw_z above it, no leveling required
|
||||
if (planner.z_fade_height && planner.z_fade_height <= RAW_Z_POSITION(lz)) return;
|
||||
lz += ubl.get_z_correction(lx, ly) * ubl.fade_scaling_factor_for_z(lz);
|
||||
#else // no fade
|
||||
lz += ubl.get_z_correction(lx, ly);
|
||||
#endif // FADE
|
||||
#endif // UBL
|
||||
|
||||
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) && DISABLED(AUTO_BED_LEVELING_UBL)
|
||||
static float z_fade_factor = 1.0, last_raw_lz = -999.0;
|
||||
if (z_fade_height) {
|
||||
const float raw_lz = RAW_Z_POSITION(lz);
|
||||
if (raw_lz >= z_fade_height) return;
|
||||
if (last_raw_lz != raw_lz) {
|
||||
last_raw_lz = raw_lz;
|
||||
z_fade_factor = 1.0 - raw_lz * inverse_z_fade_height;
|
||||
}
|
||||
}
|
||||
else
|
||||
z_fade_factor = 1.0;
|
||||
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
|
||||
const float fade_scaling_factor = fade_scaling_factor_for_z(lz);
|
||||
if (!fade_scaling_factor) return;
|
||||
#else
|
||||
constexpr float fade_scaling_factor = 1.0;
|
||||
#endif
|
||||
|
||||
#if ENABLED(MESH_BED_LEVELING)
|
||||
#if ENABLED(AUTO_BED_LEVELING_UBL)
|
||||
|
||||
lz += ubl.get_z_correction(lx, ly) * fade_scaling_factor;
|
||||
|
||||
#elif ENABLED(MESH_BED_LEVELING)
|
||||
|
||||
lz += mbl.get_z(RAW_X_POSITION(lx), RAW_Y_POSITION(ly)
|
||||
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
|
||||
, z_fade_factor
|
||||
, fade_scaling_factor
|
||||
#endif
|
||||
);
|
||||
);
|
||||
|
||||
#elif ABL_PLANAR
|
||||
|
||||
UNUSED(fade_scaling_factor);
|
||||
|
||||
float dx = RAW_X_POSITION(lx) - (X_TILT_FULCRUM),
|
||||
dy = RAW_Y_POSITION(ly) - (Y_TILT_FULCRUM),
|
||||
dz = RAW_Z_POSITION(lz);
|
||||
@ -604,11 +594,7 @@ void Planner::calculate_volumetric_multipliers() {
|
||||
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
||||
|
||||
float tmp[XYZ] = { lx, ly, 0 };
|
||||
lz += bilinear_z_offset(tmp)
|
||||
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
|
||||
* z_fade_factor
|
||||
#endif
|
||||
;
|
||||
lz += bilinear_z_offset(tmp) * fade_scaling_factor;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
@ -263,6 +263,38 @@ class Planner {
|
||||
if (!filament_size[i]) filament_size[i] = DEFAULT_NOMINAL_FILAMENT_DIA;
|
||||
}
|
||||
|
||||
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
|
||||
|
||||
/**
|
||||
* Get the Z leveling fade factor based on the given Z height,
|
||||
* re-calculating only when needed.
|
||||
*
|
||||
* Returns 1.0 if planner.z_fade_height is 0.0.
|
||||
* Returns 0.0 if Z is past the specified 'Fade Height'.
|
||||
*/
|
||||
inline static float fade_scaling_factor_for_z(const float &lz) {
|
||||
static float z_fade_factor = 1.0, last_raw_lz = -999.0;
|
||||
if (z_fade_height) {
|
||||
const float raw_lz = RAW_Z_POSITION(lz);
|
||||
if (raw_lz >= z_fade_height) return 0.0;
|
||||
if (last_raw_lz != raw_lz) {
|
||||
last_raw_lz = raw_lz;
|
||||
z_fade_factor = 1.0 - raw_lz * inverse_z_fade_height;
|
||||
}
|
||||
return z_fade_factor;
|
||||
}
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
FORCE_INLINE static float fade_scaling_factor_for_z(const float &lz) {
|
||||
UNUSED(lz);
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if PLANNER_LEVELING
|
||||
|
||||
#define ARG_X float lx
|
||||
|
Reference in New Issue
Block a user