Merge pull request #7965 from thinkyhead/bf1_ubl_remove_z_offset

[1.1.x] Unify Z fade factor
master
Scott Lahteine 7 years ago committed by GitHub
commit 1c3d06876e

@ -783,9 +783,12 @@
#define UBL_DELTA (ENABLED(AUTO_BED_LEVELING_UBL) && (ENABLED(DELTA) || ENABLED(UBL_GRANULAR_SEGMENTATION_FOR_CARTESIAN)))
#define ABL_PLANAR (ENABLED(AUTO_BED_LEVELING_LINEAR) || ENABLED(AUTO_BED_LEVELING_3POINT))
#define ABL_GRID (ENABLED(AUTO_BED_LEVELING_LINEAR) || ENABLED(AUTO_BED_LEVELING_BILINEAR))
#define HAS_ABL (ABL_PLANAR || ABL_GRID || ENABLED(AUTO_BED_LEVELING_UBL))
#define OLDSCHOOL_ABL (ABL_PLANAR || ABL_GRID)
#define HAS_ABL (OLDSCHOOL_ABL || ENABLED(AUTO_BED_LEVELING_UBL))
#define HAS_LEVELING (HAS_ABL || ENABLED(MESH_BED_LEVELING))
#define PLANNER_LEVELING (ABL_PLANAR || ABL_GRID || ENABLED(MESH_BED_LEVELING) || UBL_DELTA)
#define HAS_AUTOLEVEL (HAS_ABL && DISABLED(PROBE_MANUALLY))
#define HAS_MESH (ENABLED(AUTO_BED_LEVELING_BILINEAR) || ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(MESH_BED_LEVELING))
#define PLANNER_LEVELING (OLDSCHOOL_ABL || ENABLED(MESH_BED_LEVELING) || UBL_DELTA)
#define HAS_PROBING_PROCEDURE (HAS_ABL || ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST))
#if HAS_PROBING_PROCEDURE
#define PROBE_BED_WIDTH abs(RIGHT_PROBE_BED_POSITION - (LEFT_PROBE_BED_POSITION))

@ -323,7 +323,6 @@ extern float soft_endstop_min[XYZ], soft_endstop_max[XYZ];
#if HAS_LEVELING
bool leveling_is_valid();
bool leveling_is_active();
void set_bed_leveling_enabled(const bool enable=true);
void reset_bed_level();
#endif

@ -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)
@ -2471,18 +2471,6 @@ static void clean_up_after_endstop_or_probe_move() {
;
}
bool leveling_is_active() {
return
#if ENABLED(MESH_BED_LEVELING)
mbl.active()
#elif ENABLED(AUTO_BED_LEVELING_UBL)
ubl.state.active
#else
planner.abl_enabled
#endif
;
}
/**
* Turn bed leveling on or off, fixing the current
* position as-needed.
@ -2498,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)
@ -2506,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
@ -2534,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.
@ -2559,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
@ -2583,8 +2566,8 @@ static void clean_up_after_endstop_or_probe_move() {
Z_AXIS
#endif
);
}
#endif
#endif
}
}
#endif // LEVELING_FADE_HEIGHT
@ -2597,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)
@ -3771,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] = {
@ -3802,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)");
@ -3971,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
@ -4211,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)
@ -4261,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
@ -4374,7 +4357,7 @@ void home_all_axes() { gcode_G28(true); }
report_current_position();
}
#elif HAS_ABL && DISABLED(AUTO_BED_LEVELING_UBL)
#elif OLDSCHOOL_ABL
#if ABL_GRID
#if ENABLED(PROBE_Y_FIRST)
@ -4580,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)
@ -4720,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
@ -4734,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
@ -4753,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();
@ -4798,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;
@ -4999,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;
}
@ -5035,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;
@ -5058,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;
}
}
@ -5226,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))
@ -5280,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
@ -5294,11 +5277,11 @@ void home_all_axes() { gcode_G28(true); }
KEEPALIVE_STATE(IN_HANDLER);
if (planner.abl_enabled)
if (planner.leveling_active)
SYNC_PLAN_POSITION_KINEMATIC();
}
#endif // HAS_ABL && !AUTO_BED_LEVELING_UBL
#endif // OLDSCHOOL_ABL
#if HAS_BED_PROBE
@ -5886,7 +5869,7 @@ void home_all_axes() { gcode_G28(true); }
#endif // G38_PROBE_TARGET
#if ENABLED(AUTO_BED_LEVELING_BILINEAR) || ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(MESH_BED_LEVELING)
#if HAS_MESH
/**
* G42: Move X & Y axes to mesh coordinates (I & J)
@ -5938,7 +5921,7 @@ void home_all_axes() { gcode_G28(true); }
}
}
#endif // AUTO_BED_LEVELING_UBL
#endif // HAS_MESH
/**
* G92: Set current position to given X Y Z E
@ -7077,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
@ -9352,7 +9335,7 @@ void quickstop_stepper() {
if (parser.seen('L')) {
#if ENABLED(EEPROM_SETTINGS)
const int8_t storage_slot = parser.has_value() ? parser.value_int() : ubl.state.storage_slot;
const int8_t storage_slot = parser.has_value() ? parser.value_int() : ubl.storage_slot;
const int16_t a = settings.calc_num_meshes();
if (!a) {
@ -9367,7 +9350,7 @@ void quickstop_stepper() {
}
settings.load_mesh(storage_slot);
ubl.state.storage_slot = storage_slot;
ubl.storage_slot = storage_slot;
#else
@ -9381,7 +9364,7 @@ void quickstop_stepper() {
if (parser.seen('L') || parser.seen('V')) {
ubl.display_map(0); // Currently only supports one map type
SERIAL_ECHOLNPAIR("UBL_MESH_VALID = ", UBL_MESH_VALID);
SERIAL_ECHOLNPAIR("ubl.state.storage_slot = ", ubl.state.storage_slot);
SERIAL_ECHOLNPAIR("ubl.storage_slot = ", ubl.storage_slot);
}
#endif // AUTO_BED_LEVELING_UBL
@ -9413,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();
@ -9644,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);
@ -10521,13 +10504,13 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
+ (tmp_extruder == 0 ? -(PARKING_EXTRUDER_GRAB_DISTANCE) : PARKING_EXTRUDER_GRAB_DISTANCE);
/**
* Steps:
* 1. raise Z-Axis to have enough clearance
* 2. move to park poition of old extruder
* 3. disengage magnetc field, wait for delay
* 4. move near new extruder
* 5. engage magnetic field for new extruder
* 6. move to parking incl. offset of new extruder
* 7. lower Z-Axis
* 1. Raise Z-Axis to give enough clearance
* 2. Move to park position of old extruder
* 3. Disengage magnetic field, wait for delay
* 4. Move near new extruder
* 5. Engage magnetic field for new extruder
* 6. Move to parking incl. offset of new extruder
* 7. Lower Z-Axis
*/
// STEP 1
@ -10691,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
@ -10809,7 +10792,7 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
* F[units/min] Set the movement feedrate
* S1 Don't move the tool in XY after change
*/
inline void gcode_T(uint8_t tmp_extruder) {
inline void gcode_T(const uint8_t tmp_extruder) {
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {
@ -11006,7 +10989,7 @@ void process_next_command() {
gcode_G92();
break;
#if ENABLED(AUTO_BED_LEVELING_BILINEAR) || ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(MESH_BED_LEVELING)
#if HAS_MESH
case 42:
gcode_G42();
break;
@ -11491,7 +11474,7 @@ void process_next_command() {
break;
#endif
#if ENABLED(MESH_BED_LEVELING) || ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(AUTO_BED_LEVELING_BILINEAR)
#if HAS_MESH
case 421: // M421: Set a Mesh Bed Leveling Z coordinate
gcode_M421();
break;
@ -12389,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_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;
}

@ -651,7 +651,7 @@ static_assert(1 >= 0
/**
* Require some kind of probe for bed leveling and probe testing
*/
#if HAS_ABL && DISABLED(AUTO_BED_LEVELING_UBL)
#if OLDSCHOOL_ABL
#error "Auto Bed Leveling requires one of these: PROBE_MANUALLY, FIX_MOUNTED_PROBE, BLTOUCH, SOLENOID_PROBE, Z_PROBE_ALLEN_KEY, Z_PROBE_SLED, or a Z Servo."
#endif

@ -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,8 +88,8 @@
* 316 z_values[][] (float x9, up to float x256) +988
*
* AUTO_BED_LEVELING_UBL: 6 bytes
* 324 G29 A ubl.state.active (bool)
* 325 G29 S ubl.state.storage_slot (int8_t)
* 324 G29 A planner.leveling_active (bool)
* 325 G29 S ubl.storage_slot (int8_t)
*
* DELTA: 48 bytes
* 348 M666 XYZ endstop_adj (float x3)
@ -204,6 +204,10 @@ MarlinSettings settings;
extern void refresh_bed_level();
#endif
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
float new_z_fade_height;
#endif
/**
* Post-process after Retrieve or Reset
*/
@ -233,7 +237,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
@ -372,7 +376,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);
@ -435,8 +439,8 @@ void MarlinSettings::postprocess() {
#endif // AUTO_BED_LEVELING_BILINEAR
#if ENABLED(AUTO_BED_LEVELING_UBL)
EEPROM_WRITE(ubl.state.active);
EEPROM_WRITE(ubl.state.storage_slot);
EEPROM_WRITE(planner.leveling_active);
EEPROM_WRITE(ubl.storage_slot);
#else
const bool ubl_active = false;
const int8_t storage_slot = -1;
@ -661,8 +665,8 @@ void MarlinSettings::postprocess() {
}
#if ENABLED(UBL_SAVE_ACTIVE_ON_M500)
if (ubl.state.storage_slot >= 0)
store_mesh(ubl.state.storage_slot);
if (ubl.storage_slot >= 0)
store_mesh(ubl.storage_slot);
#endif
return !eeprom_error;
@ -751,7 +755,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
@ -768,7 +772,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
@ -824,8 +828,8 @@ void MarlinSettings::postprocess() {
}
#if ENABLED(AUTO_BED_LEVELING_UBL)
EEPROM_READ(ubl.state.active);
EEPROM_READ(ubl.state.storage_slot);
EEPROM_READ(planner.leveling_active);
EEPROM_READ(ubl.storage_slot);
#else
uint8_t dummyui8;
EEPROM_READ(dummyb);
@ -1042,10 +1046,10 @@ void MarlinSettings::postprocess() {
ubl.reset();
}
if (ubl.state.storage_slot >= 0) {
load_mesh(ubl.state.storage_slot);
if (ubl.storage_slot >= 0) {
load_mesh(ubl.storage_slot);
#if ENABLED(EEPROM_CHITCHAT)
SERIAL_ECHOPAIR("Mesh ", ubl.state.storage_slot);
SERIAL_ECHOPAIR("Mesh ", ubl.storage_slot);
SERIAL_ECHOLNPGM(" loaded from storage.");
#endif
}
@ -1186,7 +1190,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 = 10.0;
#endif
#if HAS_HOME_OFFSET
@ -1563,65 +1567,71 @@ void MarlinSettings::reset() {
}
#endif
#if ENABLED(MESH_BED_LEVELING)
/**
* Bed Leveling
*/
#if HAS_LEVELING
if (!forReplay) {
#if ENABLED(MESH_BED_LEVELING)
if (!forReplay) {
CONFIG_ECHO_START;
SERIAL_ECHOLNPGM("Mesh Bed Leveling:");
}
CONFIG_ECHO_START;
SERIAL_ECHOLNPGM("Mesh Bed Leveling:");
}
CONFIG_ECHO_START;
SERIAL_ECHOPAIR(" M420 S", leveling_is_valid() ? 1 : 0);
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(planner.z_fade_height));
#endif
SERIAL_EOL();
for (uint8_t py = 0; py < GRID_MAX_POINTS_Y; py++) {
for (uint8_t px = 0; px < GRID_MAX_POINTS_X; px++) {
#elif ENABLED(AUTO_BED_LEVELING_UBL)
if (!forReplay) {
CONFIG_ECHO_START;
SERIAL_ECHOPAIR(" G29 S3 X", (int)px + 1);
SERIAL_ECHOPAIR(" Y", (int)py + 1);
SERIAL_ECHOPGM(" Z");
SERIAL_PROTOCOL_F(LINEAR_UNIT(mbl.z_values[px][py]), 5);
SERIAL_EOL();
ubl.echo_name();
SERIAL_ECHOLNPGM(":");
}
}
CONFIG_ECHO_START;
#elif ENABLED(AUTO_BED_LEVELING_UBL)
#elif HAS_ABL
if (!forReplay) {
if (!forReplay) {
CONFIG_ECHO_START;
SERIAL_ECHOLNPGM("Auto Bed Leveling:");
}
CONFIG_ECHO_START;
ubl.echo_name();
SERIAL_ECHOLNPGM(":");
}
#endif
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();
if (!forReplay) {
SERIAL_EOL();
ubl.report_state();
SERIAL_ECHOLNPAIR("\nActive Mesh Slot: ", ubl.state.storage_slot);
SERIAL_ECHOPAIR("EEPROM can hold ", calc_num_meshes());
SERIAL_ECHOLNPGM(" meshes.\n");
}
#if ENABLED(MESH_BED_LEVELING)
#elif HAS_ABL
for (uint8_t py = 0; py < GRID_MAX_POINTS_Y; py++) {
for (uint8_t px = 0; px < GRID_MAX_POINTS_X; px++) {
CONFIG_ECHO_START;
SERIAL_ECHOPAIR(" G29 S3 X", (int)px + 1);
SERIAL_ECHOPAIR(" Y", (int)py + 1);
SERIAL_ECHOPGM(" Z");
SERIAL_PROTOCOL_F(LINEAR_UNIT(mbl.z_values[px][py]), 5);
SERIAL_EOL();
}
}
#elif ENABLED(AUTO_BED_LEVELING_UBL)
if (!forReplay) {
SERIAL_EOL();
ubl.report_state();
SERIAL_ECHOLNPAIR("\nActive Mesh Slot: ", ubl.storage_slot);
SERIAL_ECHOPAIR("EEPROM can hold ", calc_num_meshes());
SERIAL_ECHOLNPGM(" meshes.\n");
}
if (!forReplay) {
CONFIG_ECHO_START;
SERIAL_ECHOLNPGM("Auto Bed Leveling:");
}
CONFIG_ECHO_START;
SERIAL_ECHOPAIR(" M420 S", leveling_is_active() ? 1 : 0);
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(planner.z_fade_height));
#endif
SERIAL_EOL();
#endif
#endif // HAS_LEVELING
#if ENABLED(DELTA)
if (!forReplay) {
@ -1757,7 +1767,7 @@ void MarlinSettings::reset() {
#endif // FWRETRACT
/**
* Auto Bed Leveling
* Probe Offset
*/
#if HAS_BED_PROBE
if (!forReplay) {

@ -26,7 +26,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],
@ -42,7 +42,7 @@
}
void mesh_bed_leveling::reset() {
status = MBL_STATUS_NONE;
has_mesh = false;
z_offset = 0;
ZERO(z_values);
}

@ -33,18 +33,12 @@
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],
@ -56,11 +50,6 @@
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);

@ -104,17 +104,16 @@ float Planner::min_feedrate_mm_s,
Planner::max_jerk[XYZE], // The largest speed change requiring no acceleration
Planner::min_travel_feedrate_mm_s;
#if HAS_ABL
bool Planner::abl_enabled = false; // Flag that auto bed leveling is enabled
#endif
#if ABL_PLANAR
matrix_3x3 Planner::bed_level_matrix; // Transform to compensate for bed level
#endif
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
float Planner::z_fade_height, // Initialized by settings.load()
Planner::inverse_z_fade_height;
#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
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
float Planner::z_fade_height, // Initialized by settings.load()
Planner::inverse_z_fade_height,
Planner::last_raw_lz;
#endif
#endif
#if ENABLED(AUTOTEMP)
@ -528,46 +527,31 @@ void Planner::check_axes_activity() {
*/
void Planner::apply_leveling(float &lx, float &ly, float &lz) {
#if ENABLED(AUTO_BED_LEVELING_UBL)
if (!ubl.state.active) return;
#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 HAS_ABL
if (!abl_enabled) return;
#endif
if (!leveling_active) return;
#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)
if (mbl.active())
lz += mbl.get_z(RAW_X_POSITION(lx), RAW_Y_POSITION(ly)
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
, z_fade_factor
#endif
);
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)
, 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);
@ -581,63 +565,56 @@ void Planner::check_axes_activity() {
#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
}
void Planner::unapply_leveling(float logical[XYZ]) {
#if ENABLED(AUTO_BED_LEVELING_UBL)
#if HAS_LEVELING
if (!leveling_active) return;
#endif
if (ubl.state.active) {
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
if (!leveling_active_at_z(logical[Z_AXIS])) return;
#endif
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(AUTO_BED_LEVELING_UBL)
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
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);
// 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 ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
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;
}
// 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
#endif // ENABLE_LEVELING_FADE_HEIGHT
logical[Z_AXIS] = z_logical;
}
logical[Z_AXIS] = z_logical;
return; // don't fall thru to other ENABLE_LEVELING_FADE_HEIGHT logic
#endif
#if HAS_ABL
if (!abl_enabled) return;
#endif
#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 (mbl.active()) {
if (leveling_active) {
#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);
logical[Z_AXIS] = (z_fade_height * (RAW_Z_POSITION(logical[Z_AXIS]) - c)) / (z_fade_height - c);

@ -154,15 +154,14 @@ class Planner {
max_jerk[XYZE], // The largest speed change requiring no acceleration
min_travel_feedrate_mm_s;
#if HAS_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)
@ -192,6 +191,10 @@ class Planner {
*/
static uint32_t cutoff_long;
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
static float last_raw_lz;
#endif
#if ENABLED(DISABLE_INACTIVE_EXTRUDER)
/**
* Counters to manage disabling inactive extruders
@ -243,6 +246,52 @@ class Planner {
static bool is_full() { return (block_buffer_tail == BLOCK_MOD(block_buffer_head + 1)); }
#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;
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;
}
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) {
UNUSED(lz);
return 1.0;
}
FORCE_INLINE static bool leveling_active_at_z(const float &lz) { return true; }
#endif
#if PLANNER_LEVELING
#define ARG_X float lx

@ -2093,7 +2093,8 @@ void Temperature::isr() {
} // temp_count >= OVERSAMPLENR
// Go to the next state, up to SensorsReady
adc_sensor_state = (ADCSensorState)((int(adc_sensor_state) + 1) % int(StartupDelay));
adc_sensor_state = (ADCSensorState)(int(adc_sensor_state) + 1);
if (adc_sensor_state > SensorsReady) adc_sensor_state = (ADCSensorState)0;
#if ENABLED(BABYSTEPPING)
LOOP_XYZ(axis) {

@ -28,8 +28,7 @@
#include "ubl.h"
#include "hex_print_routines.h"
#include "temperature.h"
extern Planner planner;
#include "planner.h"
/**
* These support functions allow the use of large bit arrays of flags that take very
@ -48,7 +47,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);
}
@ -62,10 +61,9 @@
safe_delay(10);
}
ubl_state unified_bed_leveling::state;
int8_t unified_bed_leveling::storage_slot;
float unified_bed_leveling::z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y],
unified_bed_leveling::last_specified_z;
float unified_bed_leveling::z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
// 15 is the maximum nubmer of grid points supported + 1 safety margin for now,
// until determinism prevails
@ -84,12 +82,11 @@
void unified_bed_leveling::reset() {
set_bed_leveling_enabled(false);
state.storage_slot = -1;
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;
}
void unified_bed_leveling::invalidate() {

@ -76,16 +76,9 @@
#define MESH_X_DIST (float(UBL_MESH_MAX_X - (UBL_MESH_MIN_X)) / float(GRID_MAX_POINTS_X - 1))
#define MESH_Y_DIST (float(UBL_MESH_MAX_Y - (UBL_MESH_MIN_Y)) / float(GRID_MAX_POINTS_Y - 1))
typedef struct {
bool active = false;
int8_t storage_slot = -1;
} ubl_state;
class unified_bed_leveling {
private:
static float last_specified_z;
static int g29_verbose_level,
g29_phase_value,
g29_repetition_cnt,
@ -167,7 +160,7 @@
static void G26();
#endif
static ubl_state state;
static int8_t storage_slot;
static float z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
@ -361,31 +354,6 @@
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);
}

@ -423,8 +423,8 @@
#endif // HAS_BED_PROBE
if (parser.seen('P')) {
if (WITHIN(g29_phase_value, 0, 1) && state.storage_slot == -1) {
state.storage_slot = 0;
if (WITHIN(g29_phase_value, 0, 1) && storage_slot == -1) {
storage_slot = 0;
SERIAL_PROTOCOLLNPGM("Default storage slot 0 selected.");
}
@ -603,7 +603,7 @@
//
if (parser.seen('L')) { // Load Current Mesh Data
g29_storage_slot = parser.has_value() ? parser.value_int() : state.storage_slot;
g29_storage_slot = parser.has_value() ? parser.value_int() : storage_slot;
int16_t a = settings.calc_num_meshes();
@ -619,7 +619,7 @@
}
settings.load_mesh(g29_storage_slot);
state.storage_slot = g29_storage_slot;
storage_slot = g29_storage_slot;
SERIAL_PROTOCOLLNPGM("Done.");
}
@ -629,7 +629,7 @@
//
if (parser.seen('S')) { // Store (or Save) Current Mesh Data
g29_storage_slot = parser.has_value() ? parser.value_int() : state.storage_slot;
g29_storage_slot = parser.has_value() ? parser.value_int() : storage_slot;
if (g29_storage_slot == -1) { // Special case, we are going to 'Export' the mesh to the
SERIAL_ECHOLNPGM("G29 I 999"); // host in a form it can be reconstructed on a different machine
@ -661,7 +661,7 @@
}
settings.store_mesh(g29_storage_slot);
state.storage_slot = g29_storage_slot;
storage_slot = g29_storage_slot;
SERIAL_PROTOCOLLNPGM("Done.");
}
@ -1165,7 +1165,7 @@
return;
}
ubl_state_at_invocation = state.active;
ubl_state_at_invocation = planner.leveling_active;
set_bed_leveling_enabled(false);
}
@ -1190,10 +1190,10 @@
void unified_bed_leveling::g29_what_command() {
report_state();
if (state.storage_slot == -1)
if (storage_slot == -1)
SERIAL_PROTOCOLPGM("No Mesh Loaded.");
else {
SERIAL_PROTOCOLPAIR("Mesh ", state.storage_slot);
SERIAL_PROTOCOLPAIR("Mesh ", storage_slot);
SERIAL_PROTOCOLPGM(" Loaded.");
}
SERIAL_EOL();

@ -186,7 +186,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
@ -270,9 +270,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 *= 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
@ -335,9 +334,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 *= 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
@ -408,9 +406,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 *= 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
@ -436,9 +433,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 *= 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
@ -603,7 +599,7 @@
// 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 {
@ -629,7 +625,9 @@
// 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]);
#else
constexpr float fade_scaling_factor = 1.0;
#endif
// increment to first segment destination
@ -661,7 +659,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
@ -690,11 +688,7 @@
for(;;) { // for all segments within this mesh cell
float z_cxcy = z_cxy0 + z_cxym * cy; // interpolated mesh z height along cx at cy
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
z_cxcy *= fade_scaling_factor; // apply fade factor to interpolated mesh height
#endif
float z_cxcy = (z_cxy0 + z_cxym * cy) * fade_scaling_factor; // interpolated mesh z height along cx at cy, scaled for fade
if (--segments == 0) { // if this is last segment, use ltarget for exact
seg_rx = RAW_X_POSITION(ltarget[X_AXIS]);

@ -50,6 +50,11 @@
#if ENABLED(AUTO_BED_LEVELING_UBL)
#include "ubl.h"
bool ubl_lcd_map_control = false;
#elif HAS_ABL
#include "planner.h"
#elif ENABLED(MESH_BED_LEVELING) && ENABLED(LCD_BED_LEVELING)
#include "mesh_bed_leveling.h"
extern void mesh_probing_done();
#endif
// Initialized by settings.load()
@ -194,11 +199,6 @@ uint16_t max_display_update_time = 0;
void lcd_delta_calibrate_menu();
#endif
#if ENABLED(MESH_BED_LEVELING) && ENABLED(LCD_BED_LEVELING)
#include "mesh_bed_leveling.h"
extern void mesh_probing_done();
#endif
////////////////////////////////////////////
//////////// Menu System Actions ///////////
////////////////////////////////////////////
@ -1089,7 +1089,7 @@ void kill_screen(const char* lcd_msg) {
const float new_zoffset = zprobe_zoffset + planner.steps_to_mm[Z_AXIS] * babystep_increment;
if (WITHIN(new_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) {
if (planner.abl_enabled)
if (planner.leveling_active)
thermalManager.babystep_axis(Z_AXIS, babystep_increment);
zprobe_zoffset = new_zoffset;
@ -1791,7 +1791,7 @@ void kill_screen(const char* lcd_msg) {
_lcd_after_probing();
mbl.set_has_mesh(true);
mbl.has_mesh = true;
mesh_probing_done();
#endif
@ -1909,11 +1909,12 @@ void kill_screen(const char* lcd_msg) {
enqueue_and_echo_commands_P(PSTR("G28"));
}
static bool _level_state;
void _lcd_toggle_bed_leveling() { set_bed_leveling_enabled(_level_state); }
static bool new_level_state;
void _lcd_toggle_bed_leveling() { set_bed_leveling_enabled(new_level_state); }
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
void _lcd_set_z_fade_height() { set_z_fade_height(planner.z_fade_height); }
static float new_z_fade_height;
void _lcd_set_z_fade_height() { set_z_fade_height(new_z_fade_height); }
#endif
/**
@ -1936,14 +1937,11 @@ void kill_screen(const char* lcd_msg) {
if (!(axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS]))
MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
else if (leveling_is_valid()) {
_level_state = leveling_is_active();
MENU_ITEM_EDIT_CALLBACK(bool, MSG_BED_LEVELING, &_level_state, _lcd_toggle_bed_leveling);
}
else if (leveling_is_valid())
MENU_ITEM_EDIT_CALLBACK(bool, MSG_BED_LEVELING, &new_level_state, _lcd_toggle_bed_leveling);
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
set_z_fade_height(planner.z_fade_height);
MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_Z_FADE_HEIGHT, &planner.z_fade_height, 0.0, 100.0, _lcd_set_z_fade_height);
MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_Z_FADE_HEIGHT, &new_z_fade_height, 0.0, 100.0, _lcd_set_z_fade_height);
#endif
//
@ -1974,6 +1972,16 @@ void kill_screen(const char* lcd_msg) {
END_MENU();
}
void _lcd_goto_bed_leveling() {
currentScreen = lcd_bed_leveling;
#if ENABLED(LCD_BED_LEVELING)
new_level_state = planner.leveling_active;
#endif
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
new_z_fade_height = planner.z_fade_height;
#endif
}
#elif ENABLED(AUTO_BED_LEVELING_UBL)
void _lcd_ubl_level_bed();
@ -2542,7 +2550,13 @@ void kill_screen(const char* lcd_msg) {
#if ENABLED(PROBE_MANUALLY)
if (!g29_in_progress)
#endif
MENU_ITEM(submenu, MSG_BED_LEVELING, lcd_bed_leveling);
MENU_ITEM(submenu, MSG_BED_LEVELING,
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
_lcd_goto_bed_leveling
#else
lcd_bed_leveling
#endif
);
#else
#if PLANNER_LEVELING
MENU_ITEM(gcode, MSG_BED_LEVELING, PSTR("G28\nG29"));

@ -792,7 +792,7 @@ static void lcd_implementation_status_screen() {
lcd.print(ftostr52sp(FIXFLOAT(current_position[Z_AXIS])));
#if HAS_LEVELING
lcd.write(leveling_is_active() || blink ? '_' : ' ');
lcd.write(planner.leveling_active || blink ? '_' : ' ');
#endif
#endif // LCD_HEIGHT > 2
@ -1145,9 +1145,9 @@ static void lcd_implementation_status_screen() {
return ret_val;
}
coordinate pixel_location(uint8_t x, uint8_t y) { return pixel_location((int16_t)x, (int16_t)y); }
inline coordinate pixel_location(const uint8_t x, const uint8_t y) { return pixel_location((int16_t)x, (int16_t)y); }
void lcd_implementation_ubl_plot(uint8_t x, uint8_t inverted_y) {
void lcd_implementation_ubl_plot(const uint8_t x, const uint8_t inverted_y) {
#if LCD_WIDTH >= 20
#define _LCD_W_POS 12

Loading…
Cancel
Save