Move fade_scaling_factor_for_z to Planner

This commit is contained in:
Scott Lahteine
2017-10-13 10:39:11 -05:00
parent 9a930ebec2
commit ca1e47375c
5 changed files with 65 additions and 76 deletions

View File

@ -134,20 +134,16 @@ void set_bed_leveling_enabled(const bool enable/*=true*/) {
const bool level_active = LEVELING_IS_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)
planner.z_fade_height = zfh;
planner.inverse_z_fade_height = RECIPROCAL(zfh);
if (level_active) {
#if ENABLED(AUTO_BED_LEVELING_UBL)
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);
if (level_active) {
#else
set_current_from_steppers_for_axis(
#if ABL_PLANAR
ALL_AXES
@ -155,8 +151,8 @@ void set_bed_leveling_enabled(const bool enable/*=true*/) {
Z_AXIS
#endif
);
}
#endif
#endif
}
}
#endif // ENABLE_LEVELING_FADE_HEIGHT

View File

@ -367,31 +367,6 @@ class unified_bed_leveling {
return z0;
}
/**
* This function sets the Z leveling fade factor based on the given Z height,
* only re-calculating when necessary.
*
* Returns 1.0 if planner.z_fade_height is 0.0.
* Returns 0.0 if Z is past the specified 'Fade Height'.
*/
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
static inline float fade_scaling_factor_for_z(const float &lz) {
if (planner.z_fade_height == 0.0) return 1.0;
static float fade_scaling_factor = 1.0;
const float rz = RAW_Z_POSITION(lz);
if (last_specified_z != rz) {
last_specified_z = rz;
fade_scaling_factor =
rz < planner.z_fade_height
? 1.0 - (rz * planner.inverse_z_fade_height)
: 0.0;
}
return fade_scaling_factor;
}
#else
FORCE_INLINE static float fade_scaling_factor_for_z(const float &lz) { return 1.0; }
#endif
FORCE_INLINE static float mesh_index_to_xpos(const uint8_t i) {
return i < GRID_MAX_POINTS_X ? pgm_read_float(&_mesh_index_to_xpos[i]) : UBL_MESH_MIN_X + i * (MESH_X_DIST);
}

View File

@ -173,7 +173,7 @@
// are going to apply the Y-Distance into the cell to interpolate the final Z correction.
const float yratio = (RAW_Y_POSITION(end[Y_AXIS]) - mesh_index_to_ypos(cell_dest_yi)) * (1.0 / (MESH_Y_DIST));
float z0 = cell_dest_yi < GRID_MAX_POINTS_Y - 1 ? (z1 + (z2 - z1) * yratio) * fade_scaling_factor_for_z(end[Z_AXIS]) : 0.0;
float z0 = cell_dest_yi < GRID_MAX_POINTS_Y - 1 ? (z1 + (z2 - z1) * yratio) * planner.fade_scaling_factor_for_z(end[Z_AXIS]) : 0.0;
/**
* If part of the Mesh is undefined, it will show up as NAN
@ -259,7 +259,7 @@
float z0 = z_correction_for_x_on_horizontal_mesh_line(x, current_xi, current_yi);
z0 *= fade_scaling_factor_for_z(end[Z_AXIS]);
z0 *= planner.fade_scaling_factor_for_z(end[Z_AXIS]);
/**
* If part of the Mesh is undefined, it will show up as NAN
@ -324,7 +324,7 @@
float z0 = z_correction_for_y_on_vertical_mesh_line(y, current_xi, current_yi);
z0 *= fade_scaling_factor_for_z(end[Z_AXIS]);
z0 *= planner.fade_scaling_factor_for_z(end[Z_AXIS]);
/**
* If part of the Mesh is undefined, it will show up as NAN
@ -397,7 +397,7 @@
// Yes! Crossing a Y Mesh Line next
float z0 = z_correction_for_x_on_horizontal_mesh_line(x, current_xi - left_flag, current_yi + dyi);
z0 *= fade_scaling_factor_for_z(end[Z_AXIS]);
z0 *= planner.fade_scaling_factor_for_z(end[Z_AXIS]);
/**
* If part of the Mesh is undefined, it will show up as NAN
@ -425,7 +425,7 @@
// Yes! Crossing a X Mesh Line next
float z0 = z_correction_for_y_on_vertical_mesh_line(y, current_xi + dxi, current_yi - down_flag);
z0 *= fade_scaling_factor_for_z(end[Z_AXIS]);
z0 *= planner.fade_scaling_factor_for_z(end[Z_AXIS]);
/**
* If part of the Mesh is undefined, it will show up as NAN
@ -616,7 +616,7 @@
// Otherwise perform per-segment leveling
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
const float fade_scaling_factor = fade_scaling_factor_for_z(ltarget[Z_AXIS]);
const float fade_scaling_factor = planner.fade_scaling_factor_for_z(ltarget[Z_AXIS]);
#endif
// increment to first segment destination