♻️ Common Bed Leveling object name, accessors (#24214)
This commit is contained in:
committed by
Scott Lahteine
parent
06c4a9acdb
commit
b72f9277e9
@ -417,7 +417,7 @@ void line_to_current_position(const_feedRate_t fr_mm_s/*=feedrate_mm_s*/) {
|
||||
|
||||
#if UBL_SEGMENTED
|
||||
// UBL segmented line will do Z-only moves in single segment
|
||||
ubl.line_to_destination_segmented(scaled_fr_mm_s);
|
||||
bedlevel.line_to_destination_segmented(scaled_fr_mm_s);
|
||||
#else
|
||||
if (current_position == destination) return;
|
||||
|
||||
@ -904,7 +904,7 @@ FORCE_INLINE void segment_idle(millis_t &next_idle_ms) {
|
||||
* small incremental moves for DELTA or SCARA.
|
||||
*
|
||||
* For Unified Bed Leveling (Delta or Segmented Cartesian)
|
||||
* the ubl.line_to_destination_segmented method replaces this.
|
||||
* the bedlevel.line_to_destination_segmented method replaces this.
|
||||
*
|
||||
* For Auto Bed Leveling (Bilinear) with SEGMENT_LEVELED_MOVES
|
||||
* this is replaced by segmented_line_to_destination below.
|
||||
@ -1060,7 +1060,7 @@ FORCE_INLINE void segment_idle(millis_t &next_idle_ms) {
|
||||
#if HAS_MESH
|
||||
if (planner.leveling_active && planner.leveling_active_at_z(destination.z)) {
|
||||
#if ENABLED(AUTO_BED_LEVELING_UBL)
|
||||
ubl.line_to_destination_cartesian(scaled_fr_mm_s, active_extruder); // UBL's motion routine needs to know about
|
||||
bedlevel.line_to_destination_cartesian(scaled_fr_mm_s, active_extruder); // UBL's motion routine needs to know about
|
||||
return true; // all moves, including Z-only moves.
|
||||
#elif ENABLED(SEGMENT_LEVELED_MOVES)
|
||||
segmented_line_to_destination(scaled_fr_mm_s);
|
||||
@ -1072,9 +1072,9 @@ FORCE_INLINE void segment_idle(millis_t &next_idle_ms) {
|
||||
*/
|
||||
if (xy_pos_t(current_position) != xy_pos_t(destination)) {
|
||||
#if ENABLED(MESH_BED_LEVELING)
|
||||
mbl.line_to_destination(scaled_fr_mm_s);
|
||||
bedlevel.line_to_destination(scaled_fr_mm_s);
|
||||
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
||||
bbl.line_to_destination(scaled_fr_mm_s);
|
||||
bedlevel.line_to_destination(scaled_fr_mm_s);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
@ -1272,7 +1272,7 @@ void prepare_line_to_destination() {
|
||||
if (
|
||||
#if UBL_SEGMENTED
|
||||
#if IS_KINEMATIC // UBL using Kinematic / Cartesian cases as a workaround for now.
|
||||
ubl.line_to_destination_segmented(MMS_SCALED(feedrate_mm_s))
|
||||
bedlevel.line_to_destination_segmented(MMS_SCALED(feedrate_mm_s))
|
||||
#else
|
||||
line_to_destination_cartesian()
|
||||
#endif
|
||||
|
@ -1581,19 +1581,12 @@ void Planner::check_axes_activity() {
|
||||
|
||||
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
|
||||
const float fade_scaling_factor = fade_scaling_factor_for_z(raw.z);
|
||||
#elif DISABLED(MESH_BED_LEVELING)
|
||||
constexpr float fade_scaling_factor = 1.0;
|
||||
if (fade_scaling_factor) raw.z += fade_scaling_factor * bedlevel.get_z_correction(raw);
|
||||
#else
|
||||
raw.z += bedlevel.get_z_correction(raw);
|
||||
#endif
|
||||
|
||||
raw.z += (
|
||||
#if ENABLED(MESH_BED_LEVELING)
|
||||
mbl.get_z(raw OPTARG(ENABLE_LEVELING_FADE_HEIGHT, fade_scaling_factor))
|
||||
#elif ENABLED(AUTO_BED_LEVELING_UBL)
|
||||
fade_scaling_factor ? fade_scaling_factor * ubl.get_z_correction(raw) : 0.0
|
||||
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
||||
fade_scaling_factor ? fade_scaling_factor * bbl.get_z_correction(raw) : 0.0
|
||||
#endif
|
||||
);
|
||||
TERN_(MESH_BED_LEVELING, raw.z += bedlevel.get_z_offset());
|
||||
|
||||
#endif
|
||||
}
|
||||
@ -1612,22 +1605,15 @@ void Planner::check_axes_activity() {
|
||||
|
||||
#elif HAS_MESH
|
||||
|
||||
TERN_(MESH_BED_LEVELING, raw.z -= bedlevel.get_z_offset());
|
||||
|
||||
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
|
||||
const float fade_scaling_factor = fade_scaling_factor_for_z(raw.z);
|
||||
#elif DISABLED(MESH_BED_LEVELING)
|
||||
constexpr float fade_scaling_factor = 1.0;
|
||||
if (fade_scaling_factor) raw.z -= fade_scaling_factor * bedlevel.get_z_correction(raw);
|
||||
#else
|
||||
raw.z -= bedlevel.get_z_correction(raw);
|
||||
#endif
|
||||
|
||||
raw.z -= (
|
||||
#if ENABLED(MESH_BED_LEVELING)
|
||||
mbl.get_z(raw OPTARG(ENABLE_LEVELING_FADE_HEIGHT, fade_scaling_factor))
|
||||
#elif ENABLED(AUTO_BED_LEVELING_UBL)
|
||||
fade_scaling_factor ? fade_scaling_factor * ubl.get_z_correction(raw) : 0.0
|
||||
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
||||
fade_scaling_factor ? fade_scaling_factor * bbl.get_z_correction(raw) : 0.0
|
||||
#endif
|
||||
);
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -247,9 +247,9 @@ typedef struct SettingsDataStruct {
|
||||
//
|
||||
// MESH_BED_LEVELING
|
||||
//
|
||||
float mbl_z_offset; // mbl.z_offset
|
||||
float mbl_z_offset; // bedlevel.z_offset
|
||||
uint8_t mesh_num_x, mesh_num_y; // GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y
|
||||
float mbl_z_values[TERN(MESH_BED_LEVELING, GRID_MAX_POINTS_X, 3)] // mbl.z_values
|
||||
float mbl_z_values[TERN(MESH_BED_LEVELING, GRID_MAX_POINTS_X, 3)] // bedlevel.z_values
|
||||
[TERN(MESH_BED_LEVELING, GRID_MAX_POINTS_Y, 3)];
|
||||
|
||||
//
|
||||
@ -287,7 +287,7 @@ typedef struct SettingsDataStruct {
|
||||
// AUTO_BED_LEVELING_UBL
|
||||
//
|
||||
bool planner_leveling_active; // M420 S planner.leveling_active
|
||||
int8_t ubl_storage_slot; // ubl.storage_slot
|
||||
int8_t ubl_storage_slot; // bedlevel.storage_slot
|
||||
|
||||
//
|
||||
// SERVO_ANGLES
|
||||
@ -598,7 +598,7 @@ void MarlinSettings::postprocess() {
|
||||
|
||||
TERN_(ENABLE_LEVELING_FADE_HEIGHT, set_z_fade_height(new_z_fade_height, false)); // false = no report
|
||||
|
||||
TERN_(AUTO_BED_LEVELING_BILINEAR, bbl.refresh_bed_level());
|
||||
TERN_(AUTO_BED_LEVELING_BILINEAR, bedlevel.refresh_bed_level());
|
||||
|
||||
TERN_(HAS_MOTOR_CURRENT_PWM, stepper.refresh_motor_power());
|
||||
|
||||
@ -825,7 +825,7 @@ void MarlinSettings::postprocess() {
|
||||
{
|
||||
#if ENABLED(MESH_BED_LEVELING)
|
||||
static_assert(
|
||||
sizeof(mbl.z_values) == (GRID_MAX_POINTS) * sizeof(mbl.z_values[0][0]),
|
||||
sizeof(bedlevel.z_values) == (GRID_MAX_POINTS) * sizeof(bedlevel.z_values[0][0]),
|
||||
"MBL Z array is the wrong size."
|
||||
);
|
||||
#else
|
||||
@ -835,12 +835,12 @@ void MarlinSettings::postprocess() {
|
||||
const uint8_t mesh_num_x = TERN(MESH_BED_LEVELING, GRID_MAX_POINTS_X, 3),
|
||||
mesh_num_y = TERN(MESH_BED_LEVELING, GRID_MAX_POINTS_Y, 3);
|
||||
|
||||
EEPROM_WRITE(TERN(MESH_BED_LEVELING, mbl.z_offset, dummyf));
|
||||
EEPROM_WRITE(TERN(MESH_BED_LEVELING, bedlevel.z_offset, dummyf));
|
||||
EEPROM_WRITE(mesh_num_x);
|
||||
EEPROM_WRITE(mesh_num_y);
|
||||
|
||||
#if ENABLED(MESH_BED_LEVELING)
|
||||
EEPROM_WRITE(mbl.z_values);
|
||||
EEPROM_WRITE(bedlevel.z_values);
|
||||
#else
|
||||
for (uint8_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_WRITE(dummyf);
|
||||
#endif
|
||||
@ -877,7 +877,7 @@ void MarlinSettings::postprocess() {
|
||||
{
|
||||
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
||||
static_assert(
|
||||
sizeof(Z_VALUES_ARR) == (GRID_MAX_POINTS) * sizeof(Z_VALUES_ARR[0][0]),
|
||||
sizeof(bedlevel.z_values) == (GRID_MAX_POINTS) * sizeof(bedlevel.z_values[0][0]),
|
||||
"Bilinear Z array is the wrong size."
|
||||
);
|
||||
#endif
|
||||
@ -887,16 +887,16 @@ void MarlinSettings::postprocess() {
|
||||
EEPROM_WRITE(grid_max_x);
|
||||
EEPROM_WRITE(grid_max_y);
|
||||
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
||||
EEPROM_WRITE(bbl.get_grid_spacing());
|
||||
EEPROM_WRITE(bbl.get_grid_start());
|
||||
EEPROM_WRITE(bedlevel.grid_spacing);
|
||||
EEPROM_WRITE(bedlevel.grid_start);
|
||||
#else
|
||||
const xy_pos_t bilinear_start{0}, bilinear_grid_spacing{0};
|
||||
const xy_pos_t bilinear_grid_spacing{0}, bilinear_start{0};
|
||||
EEPROM_WRITE(bilinear_grid_spacing);
|
||||
EEPROM_WRITE(bilinear_start);
|
||||
#endif
|
||||
|
||||
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
||||
EEPROM_WRITE(Z_VALUES_ARR); // 9-256 floats
|
||||
EEPROM_WRITE(bedlevel.z_values); // 9-256 floats
|
||||
#else
|
||||
dummyf = 0;
|
||||
for (uint16_t q = grid_max_x * grid_max_y; q--;) EEPROM_WRITE(dummyf);
|
||||
@ -919,7 +919,7 @@ void MarlinSettings::postprocess() {
|
||||
{
|
||||
_FIELD_TEST(planner_leveling_active);
|
||||
const bool ubl_active = TERN(AUTO_BED_LEVELING_UBL, planner.leveling_active, false);
|
||||
const int8_t storage_slot = TERN(AUTO_BED_LEVELING_UBL, ubl.storage_slot, -1);
|
||||
const int8_t storage_slot = TERN(AUTO_BED_LEVELING_UBL, bedlevel.storage_slot, -1);
|
||||
EEPROM_WRITE(ubl_active);
|
||||
EEPROM_WRITE(storage_slot);
|
||||
}
|
||||
@ -1591,8 +1591,8 @@ void MarlinSettings::postprocess() {
|
||||
// UBL Mesh
|
||||
//
|
||||
#if ENABLED(UBL_SAVE_ACTIVE_ON_M500)
|
||||
if (ubl.storage_slot >= 0)
|
||||
store_mesh(ubl.storage_slot);
|
||||
if (bedlevel.storage_slot >= 0)
|
||||
store_mesh(bedlevel.storage_slot);
|
||||
#endif
|
||||
|
||||
if (!eeprom_error) {
|
||||
@ -1749,20 +1749,20 @@ void MarlinSettings::postprocess() {
|
||||
EEPROM_READ_ALWAYS(mesh_num_y);
|
||||
|
||||
#if ENABLED(MESH_BED_LEVELING)
|
||||
if (!validating) mbl.z_offset = dummyf;
|
||||
if (!validating) bedlevel.z_offset = dummyf;
|
||||
if (mesh_num_x == (GRID_MAX_POINTS_X) && mesh_num_y == (GRID_MAX_POINTS_Y)) {
|
||||
// EEPROM data fits the current mesh
|
||||
EEPROM_READ(mbl.z_values);
|
||||
EEPROM_READ(bedlevel.z_values);
|
||||
}
|
||||
else {
|
||||
// EEPROM data is stale
|
||||
if (!validating) mbl.reset();
|
||||
if (!validating) bedlevel.reset();
|
||||
for (uint16_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_READ(dummyf);
|
||||
}
|
||||
#else
|
||||
// MBL is disabled - skip the stored data
|
||||
for (uint16_t q = mesh_num_x * mesh_num_y; q--;) EEPROM_READ(dummyf);
|
||||
#endif // MESH_BED_LEVELING
|
||||
#endif
|
||||
}
|
||||
|
||||
//
|
||||
@ -1802,8 +1802,8 @@ void MarlinSettings::postprocess() {
|
||||
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
||||
if (grid_max_x == (GRID_MAX_POINTS_X) && grid_max_y == (GRID_MAX_POINTS_Y)) {
|
||||
if (!validating) set_bed_leveling_enabled(false);
|
||||
bbl.set_grid(spacing, start);
|
||||
EEPROM_READ(Z_VALUES_ARR); // 9 to 256 floats
|
||||
bedlevel.set_grid(spacing, start);
|
||||
EEPROM_READ(bedlevel.z_values); // 9 to 256 floats
|
||||
}
|
||||
else // EEPROM data is stale
|
||||
#endif // AUTO_BED_LEVELING_BILINEAR
|
||||
@ -1830,7 +1830,7 @@ void MarlinSettings::postprocess() {
|
||||
_FIELD_TEST(planner_leveling_active);
|
||||
#if ENABLED(AUTO_BED_LEVELING_UBL)
|
||||
const bool &planner_leveling_active = planner.leveling_active;
|
||||
const int8_t &ubl_storage_slot = ubl.storage_slot;
|
||||
const int8_t &ubl_storage_slot = bedlevel.storage_slot;
|
||||
#else
|
||||
bool planner_leveling_active;
|
||||
int8_t ubl_storage_slot;
|
||||
@ -2540,11 +2540,11 @@ void MarlinSettings::postprocess() {
|
||||
|
||||
#if ENABLED(AUTO_BED_LEVELING_UBL)
|
||||
if (!validating) {
|
||||
ubl.report_state();
|
||||
bedlevel.report_state();
|
||||
|
||||
if (!ubl.sanity_check()) {
|
||||
if (!bedlevel.sanity_check()) {
|
||||
#if BOTH(EEPROM_CHITCHAT, DEBUG_LEVELING_FEATURE)
|
||||
ubl.echo_name();
|
||||
bedlevel.echo_name();
|
||||
DEBUG_ECHOLNPGM(" initialized.\n");
|
||||
#endif
|
||||
}
|
||||
@ -2552,18 +2552,18 @@ void MarlinSettings::postprocess() {
|
||||
eeprom_error = true;
|
||||
#if BOTH(EEPROM_CHITCHAT, DEBUG_LEVELING_FEATURE)
|
||||
DEBUG_ECHOPGM("?Can't enable ");
|
||||
ubl.echo_name();
|
||||
bedlevel.echo_name();
|
||||
DEBUG_ECHOLNPGM(".");
|
||||
#endif
|
||||
ubl.reset();
|
||||
bedlevel.reset();
|
||||
}
|
||||
|
||||
if (ubl.storage_slot >= 0) {
|
||||
load_mesh(ubl.storage_slot);
|
||||
DEBUG_ECHOLNPGM("Mesh ", ubl.storage_slot, " loaded from storage.");
|
||||
if (bedlevel.storage_slot >= 0) {
|
||||
load_mesh(bedlevel.storage_slot);
|
||||
DEBUG_ECHOLNPGM("Mesh ", bedlevel.storage_slot, " loaded from storage.");
|
||||
}
|
||||
else {
|
||||
ubl.reset();
|
||||
bedlevel.reset();
|
||||
DEBUG_ECHOLNPGM("UBL reset");
|
||||
}
|
||||
}
|
||||
@ -2631,7 +2631,7 @@ void MarlinSettings::postprocess() {
|
||||
return (datasize() + EEPROM_OFFSET + 32) & 0xFFF8;
|
||||
}
|
||||
|
||||
#define MESH_STORE_SIZE sizeof(TERN(OPTIMIZED_MESH_STORAGE, mesh_store_t, ubl.z_values))
|
||||
#define MESH_STORE_SIZE sizeof(TERN(OPTIMIZED_MESH_STORAGE, mesh_store_t, bedlevel.z_values))
|
||||
|
||||
uint16_t MarlinSettings::calc_num_meshes() {
|
||||
return (meshes_end - meshes_start_index()) / MESH_STORE_SIZE;
|
||||
@ -2657,10 +2657,10 @@ void MarlinSettings::postprocess() {
|
||||
|
||||
#if ENABLED(OPTIMIZED_MESH_STORAGE)
|
||||
int16_t z_mesh_store[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
|
||||
ubl.set_store_from_mesh(ubl.z_values, z_mesh_store);
|
||||
bedlevel.set_store_from_mesh(bedlevel.z_values, z_mesh_store);
|
||||
uint8_t * const src = (uint8_t*)&z_mesh_store;
|
||||
#else
|
||||
uint8_t * const src = (uint8_t*)&ubl.z_values;
|
||||
uint8_t * const src = (uint8_t*)&bedlevel.z_values;
|
||||
#endif
|
||||
|
||||
// Write crc to MAT along with other data, or just tack on to the beginning or end
|
||||
@ -2695,7 +2695,7 @@ void MarlinSettings::postprocess() {
|
||||
int16_t z_mesh_store[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
|
||||
uint8_t * const dest = (uint8_t*)&z_mesh_store;
|
||||
#else
|
||||
uint8_t * const dest = into ? (uint8_t*)into : (uint8_t*)&ubl.z_values;
|
||||
uint8_t * const dest = into ? (uint8_t*)into : (uint8_t*)&bedlevel.z_values;
|
||||
#endif
|
||||
|
||||
persistentStore.access_start();
|
||||
@ -2705,11 +2705,11 @@ void MarlinSettings::postprocess() {
|
||||
#if ENABLED(OPTIMIZED_MESH_STORAGE)
|
||||
if (into) {
|
||||
float z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
|
||||
ubl.set_mesh_from_store(z_mesh_store, z_values);
|
||||
bedlevel.set_mesh_from_store(z_mesh_store, z_values);
|
||||
memcpy(into, z_values, sizeof(z_values));
|
||||
}
|
||||
else
|
||||
ubl.set_mesh_from_store(z_mesh_store, ubl.z_values);
|
||||
bedlevel.set_mesh_from_store(z_mesh_store, bedlevel.z_values);
|
||||
#endif
|
||||
|
||||
if (status) SERIAL_ECHOLNPGM("?Unable to load mesh data.");
|
||||
@ -3320,24 +3320,25 @@ void MarlinSettings::reset() {
|
||||
LOOP_L_N(px, GRID_MAX_POINTS_X) {
|
||||
CONFIG_ECHO_START();
|
||||
SERIAL_ECHOPGM(" G29 S3 I", px, " J", py);
|
||||
SERIAL_ECHOLNPAIR_F_P(SP_Z_STR, LINEAR_UNIT(mbl.z_values[px][py]), 5);
|
||||
SERIAL_ECHOLNPAIR_F_P(SP_Z_STR, LINEAR_UNIT(bedlevel.z_values[px][py]), 5);
|
||||
}
|
||||
}
|
||||
CONFIG_ECHO_START();
|
||||
SERIAL_ECHOLNPAIR_F(" G29 S4 Z", LINEAR_UNIT(mbl.z_offset), 5);
|
||||
SERIAL_ECHOLNPAIR_F(" G29 S4 Z", LINEAR_UNIT(bedlevel.z_offset), 5);
|
||||
}
|
||||
|
||||
#elif ENABLED(AUTO_BED_LEVELING_UBL)
|
||||
|
||||
if (!forReplay) {
|
||||
SERIAL_EOL();
|
||||
ubl.report_state();
|
||||
SERIAL_ECHO_MSG("Active Mesh Slot ", ubl.storage_slot);
|
||||
bedlevel.report_state();
|
||||
SERIAL_ECHO_MSG("Active Mesh Slot ", bedlevel.storage_slot);
|
||||
SERIAL_ECHO_MSG("EEPROM can hold ", calc_num_meshes(), " meshes.\n");
|
||||
}
|
||||
|
||||
//ubl.report_current_mesh(); // This is too verbose for large meshes. A better (more terse)
|
||||
// solution needs to be found.
|
||||
//bedlevel.report_current_mesh(); // This is too verbose for large meshes. A better (more terse)
|
||||
// solution needs to be found.
|
||||
|
||||
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
|
||||
|
||||
if (leveling_is_valid()) {
|
||||
@ -3345,7 +3346,7 @@ void MarlinSettings::reset() {
|
||||
LOOP_L_N(px, GRID_MAX_POINTS_X) {
|
||||
CONFIG_ECHO_START();
|
||||
SERIAL_ECHOPGM(" G29 W I", px, " J", py);
|
||||
SERIAL_ECHOLNPAIR_F_P(SP_Z_STR, LINEAR_UNIT(Z_VALUES_ARR[px][py]), 5);
|
||||
SERIAL_ECHOLNPAIR_F_P(SP_Z_STR, LINEAR_UNIT(bedlevel.z_values[px][py]), 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user