Use planner.leveling_active for all leveling systems

This commit is contained in:
Scott Lahteine
2017-10-13 17:21:25 -05:00
parent 32c607ffe2
commit 3e3911fb81
21 changed files with 143 additions and 180 deletions

View File

@ -44,7 +44,7 @@
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)
@ -70,7 +70,7 @@ void set_bed_leveling_enabled(const bool enable/*=true*/) {
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)
@ -78,23 +78,23 @@ void set_bed_leveling_enabled(const bool enable/*=true*/) {
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 // OLDSCHOOL_ABL
@ -106,7 +106,7 @@ void set_bed_leveling_enabled(const bool enable/*=true*/) {
#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.
@ -131,15 +131,13 @@ void set_bed_leveling_enabled(const bool enable/*=true*/) {
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
planner.z_fade_height = zfh;
planner.inverse_z_fade_height = RECIPROCAL(zfh);
planner.force_fade_recalc();
planner.set_z_fade_height(zfh);
if (level_active) {
#if ENABLED(AUTO_BED_LEVELING_UBL)
@ -166,7 +164,7 @@ void reset_bed_level() {
#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)

View File

@ -43,16 +43,6 @@ bool leveling_is_valid();
void set_bed_leveling_enabled(const bool enable=true);
void reset_bed_level();
#if ENABLED(MESH_BED_LEVELING)
#define LEVELING_IS_ACTIVE() (mbl.active())
#elif ENABLED(AUTO_BED_LEVELING_UBL)
#define LEVELING_IS_ACTIVE() (ubl.state.active)
#elif HAS_ABL
#define LEVELING_IS_ACTIVE() (planner.abl_enabled)
#else
#define LEVELING_IS_ACTIVE() (false)
#endif
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
void set_z_fade_height(const float zfh);
#endif

View File

@ -31,7 +31,7 @@
mesh_bed_leveling mbl;
uint8_t mesh_bed_leveling::status;
bool mesh_bed_leveling::has_mesh;
float mesh_bed_leveling::z_offset,
mesh_bed_leveling::z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y],
@ -47,7 +47,7 @@
}
void mesh_bed_leveling::reset() {
status = MBL_STATUS_NONE;
has_mesh = false;
z_offset = 0;
ZERO(z_values);
}

View File

@ -34,18 +34,12 @@ enum MeshLevelingState {
MeshReset
};
enum MBLStatus {
MBL_STATUS_NONE = 0,
MBL_STATUS_HAS_MESH_BIT = 0,
MBL_STATUS_ACTIVE_BIT = 1
};
#define MESH_X_DIST ((MESH_MAX_X - (MESH_MIN_X)) / (GRID_MAX_POINTS_X - 1))
#define MESH_Y_DIST ((MESH_MAX_Y - (MESH_MIN_Y)) / (GRID_MAX_POINTS_Y - 1))
class mesh_bed_leveling {
public:
static uint8_t status; // Has Mesh and Is Active bits
static bool has_mesh;
static float z_offset,
z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y],
index_to_xpos[GRID_MAX_POINTS_X],
@ -57,11 +51,6 @@ public:
static void set_z(const int8_t px, const int8_t py, const float &z) { z_values[px][py] = z; }
static bool active() { return TEST(status, MBL_STATUS_ACTIVE_BIT); }
static void set_active(const bool onOff) { onOff ? SBI(status, MBL_STATUS_ACTIVE_BIT) : CBI(status, MBL_STATUS_ACTIVE_BIT); }
static bool has_mesh() { return TEST(status, MBL_STATUS_HAS_MESH_BIT); }
static void set_has_mesh(const bool onOff) { onOff ? SBI(status, MBL_STATUS_HAS_MESH_BIT) : CBI(status, MBL_STATUS_HAS_MESH_BIT); }
static inline void zigzag(const int8_t index, int8_t &px, int8_t &py) {
px = index % (GRID_MAX_POINTS_X);
py = index / (GRID_MAX_POINTS_X);

View File

@ -51,7 +51,7 @@
void unified_bed_leveling::report_state() {
echo_name();
SERIAL_PROTOCOLPGM(" System v" UBL_VERSION " ");
if (!state.active) SERIAL_PROTOCOLPGM("in");
if (!planner.leveling_active) SERIAL_PROTOCOLPGM("in");
SERIAL_PROTOCOLLNPGM("active.");
safe_delay(50);
}
@ -93,7 +93,7 @@
set_bed_leveling_enabled(false);
state.storage_slot = -1;
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
planner.z_fade_height = 10.0;
planner.set_z_fade_height(10.0);
#endif
ZERO(z_values);
last_specified_z = -999.9;

View File

@ -1170,7 +1170,7 @@
return;
}
ubl_state_at_invocation = state.active;
ubl_state_at_invocation = planner.leveling_active;
set_bed_leveling_enabled(false);
}

View File

@ -257,9 +257,8 @@
*/
const float x = inf_m_flag ? start[X_AXIS] : (next_mesh_line_y - c) / m;
float z0 = z_correction_for_x_on_horizontal_mesh_line(x, current_xi, current_yi);
z0 *= planner.fade_scaling_factor_for_z(end[Z_AXIS]);
float z0 = z_correction_for_x_on_horizontal_mesh_line(x, current_xi, current_yi)
* planner.fade_scaling_factor_for_z(end[Z_AXIS]);
/**
* If part of the Mesh is undefined, it will show up as NAN
@ -322,9 +321,8 @@
const float next_mesh_line_x = LOGICAL_X_POSITION(mesh_index_to_xpos(current_xi)),
y = m * next_mesh_line_x + c; // Calculate Y at the next X mesh line
float z0 = z_correction_for_y_on_vertical_mesh_line(y, current_xi, current_yi);
z0 *= planner.fade_scaling_factor_for_z(end[Z_AXIS]);
float z0 = z_correction_for_y_on_vertical_mesh_line(y, current_xi, current_yi)
* planner.fade_scaling_factor_for_z(end[Z_AXIS]);
/**
* If part of the Mesh is undefined, it will show up as NAN
@ -395,9 +393,8 @@
if (left_flag == (x > next_mesh_line_x)) { // Check if we hit the Y line first
// 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 *= planner.fade_scaling_factor_for_z(end[Z_AXIS]);
float z0 = z_correction_for_x_on_horizontal_mesh_line(x, current_xi - left_flag, current_yi + dyi)
* planner.fade_scaling_factor_for_z(end[Z_AXIS]);
/**
* If part of the Mesh is undefined, it will show up as NAN
@ -423,9 +420,8 @@
}
else {
// 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 *= planner.fade_scaling_factor_for_z(end[Z_AXIS]);
float z0 = z_correction_for_y_on_vertical_mesh_line(y, current_xi + dxi, current_yi - down_flag)
* planner.fade_scaling_factor_for_z(end[Z_AXIS]);
/**
* If part of the Mesh is undefined, it will show up as NAN
@ -580,17 +576,9 @@
seg_rz = RAW_Z_POSITION(current_position[Z_AXIS]),
seg_le = current_position[E_AXIS];
const bool above_fade_height = (
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
planner.z_fade_height != 0 && planner.z_fade_height < RAW_Z_POSITION(ltarget[Z_AXIS])
#else
false
#endif
);
// Only compute leveling per segment if ubl active and target below z_fade_height.
if (!state.active || above_fade_height) { // no mesh leveling
if (!planner.leveling_active || !planner.leveling_active_at_z(ltarget[Z_AXIS])) { // no mesh leveling
do {
@ -648,7 +636,7 @@
z_x0y1 = z_values[cell_xi ][cell_yi+1], // z at lower right corner
z_x1y1 = z_values[cell_xi+1][cell_yi+1]; // z at upper right corner
if (isnan(z_x0y0)) z_x0y0 = 0; // ideally activating state.active (G29 A)
if (isnan(z_x0y0)) z_x0y0 = 0; // ideally activating planner.leveling_active (G29 A)
if (isnan(z_x1y0)) z_x1y0 = 0; // should refuse if any invalid mesh points
if (isnan(z_x0y1)) z_x0y1 = 0; // in order to avoid isnan tests per cell,
if (isnan(z_x1y1)) z_x1y1 = 0; // thus guessing zero for undefined points