♻️ Common Bed Leveling object name, accessors (#24214)

This commit is contained in:
Scott Lahteine
2022-05-19 06:05:52 -05:00
committed by Scott Lahteine
parent 06c4a9acdb
commit b72f9277e9
47 changed files with 390 additions and 434 deletions

View File

@ -293,10 +293,10 @@ typedef struct {
if (circle_flags.marked(p1.x, p1.y) && circle_flags.marked(p2.x, p2.y)) {
xyz_pos_t s, e;
s.x = _GET_MESH_X(p1.x) + (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)) * dx;
e.x = _GET_MESH_X(p2.x) - (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)) * dx;
s.y = _GET_MESH_Y(p1.y) + (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)) * dy;
e.y = _GET_MESH_Y(p2.y) - (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)) * dy;
s.x = bedlevel.get_mesh_x(p1.x) + (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)) * dx;
e.x = bedlevel.get_mesh_x(p2.x) - (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)) * dx;
s.y = bedlevel.get_mesh_y(p1.y) + (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)) * dy;
e.y = bedlevel.get_mesh_y(p2.y) - (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)) * dy;
s.z = e.z = layer_height;
#if HAS_ENDSTOPS
@ -448,7 +448,7 @@ typedef struct {
GRID_LOOP(i, j) {
if (!circle_flags.marked(i, j)) {
// We found a circle that needs to be printed
const xy_pos_t m = { _GET_MESH_X(i), _GET_MESH_Y(j) };
const xy_pos_t m = { bedlevel.get_mesh_x(i), bedlevel.get_mesh_y(j) };
// Get the distance to this intersection
float f = (pos - m).magnitude();
@ -729,7 +729,7 @@ void GcodeSuite::G26() {
if (location.valid()) {
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(location.pos, ExtUI::G26_POINT_START));
const xy_pos_t circle = _GET_MESH_POS(location.pos);
const xy_pos_t circle = { bedlevel.get_mesh_x(location.pos.a), bedlevel.get_mesh_y(location.pos.b) };
// If this mesh location is outside the printable radius, skip it.
if (!position_is_reachable(circle)) continue;
@ -738,8 +738,8 @@ void GcodeSuite::G26() {
// which is always drawn counter-clockwise.
const xy_int8_t st = location;
const bool f = st.y == 0,
r = st.x >= GRID_MAX_POINTS_X - 1,
b = st.y >= GRID_MAX_POINTS_Y - 1;
r = st.x >= (GRID_MAX_POINTS_X) - 1,
b = st.y >= (GRID_MAX_POINTS_Y) - 1;
#if ENABLED(ARC_SUPPORT)

View File

@ -48,8 +48,8 @@ void GcodeSuite::G42() {
// Move to current_position, as modified by I, J, P parameters
destination = current_position;
if (hasI) destination.x = _GET_MESH_X(ix);
if (hasJ) destination.y = _GET_MESH_Y(iy);
if (hasI) destination.x = bedlevel.get_mesh_x(ix);
if (hasJ) destination.y = bedlevel.get_mesh_y(iy);
#if HAS_PROBE_XY_OFFSET
if (parser.boolval('P')) {

View File

@ -71,13 +71,13 @@ void GcodeSuite::M420() {
start.set(x_min, y_min);
spacing.set((x_max - x_min) / (GRID_MAX_CELLS_X),
(y_max - y_min) / (GRID_MAX_CELLS_Y));
bbl.set_grid(spacing, start);
bedlevel.set_grid(spacing, start);
#endif
GRID_LOOP(x, y) {
Z_VALUES(x, y) = 0.001 * random(-200, 200);
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, Z_VALUES(x, y)));
bedlevel.z_values[x][y] = 0.001 * random(-200, 200);
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, bedlevel.z_values[x][y]));
}
TERN_(AUTO_BED_LEVELING_BILINEAR, bbl.refresh_bed_level());
TERN_(AUTO_BED_LEVELING_BILINEAR, bedlevel.refresh_bed_level());
SERIAL_ECHOPGM("Simulated " STRINGIFY(GRID_MAX_POINTS_X) "x" STRINGIFY(GRID_MAX_POINTS_Y) " mesh ");
SERIAL_ECHOPGM(" (", x_min);
SERIAL_CHAR(','); SERIAL_ECHO(y_min);
@ -101,7 +101,7 @@ void GcodeSuite::M420() {
set_bed_leveling_enabled(false);
#if ENABLED(EEPROM_SETTINGS)
const int8_t storage_slot = parser.has_value() ? parser.value_int() : ubl.storage_slot;
const int8_t storage_slot = parser.has_value() ? parser.value_int() : bedlevel.storage_slot;
const int16_t a = settings.calc_num_meshes();
if (!a) {
@ -116,7 +116,7 @@ void GcodeSuite::M420() {
}
settings.load_mesh(storage_slot);
ubl.storage_slot = storage_slot;
bedlevel.storage_slot = storage_slot;
#else
@ -128,10 +128,10 @@ void GcodeSuite::M420() {
// L or V display the map info
if (parser.seen("LV")) {
ubl.display_map(parser.byteval('T'));
bedlevel.display_map(parser.byteval('T'));
SERIAL_ECHOPGM("Mesh is ");
if (!ubl.mesh_is_valid()) SERIAL_ECHOPGM("in");
SERIAL_ECHOLNPGM("valid\nStorage slot: ", ubl.storage_slot);
if (!bedlevel.mesh_is_valid()) SERIAL_ECHOPGM("in");
SERIAL_ECHOLNPGM("valid\nStorage slot: ", bedlevel.storage_slot);
}
#endif // AUTO_BED_LEVELING_UBL
@ -148,7 +148,7 @@ void GcodeSuite::M420() {
#if ENABLED(AUTO_BED_LEVELING_UBL)
set_bed_leveling_enabled(false);
ubl.adjust_mesh_to_mean(true, cval);
bedlevel.adjust_mesh_to_mean(true, cval);
#else
@ -156,7 +156,7 @@ void GcodeSuite::M420() {
// Get the sum and average of all mesh values
float mesh_sum = 0;
GRID_LOOP(x, y) mesh_sum += Z_VALUES(x, y);
GRID_LOOP(x, y) mesh_sum += bedlevel.z_values[x][y];
const float zmean = mesh_sum / float(GRID_MAX_POINTS);
#else // midrange
@ -164,7 +164,7 @@ void GcodeSuite::M420() {
// Find the low and high mesh values.
float lo_val = 100, hi_val = -100;
GRID_LOOP(x, y) {
const float z = Z_VALUES(x, y);
const float z = bedlevel.z_values[x][y];
NOMORE(lo_val, z);
NOLESS(hi_val, z);
}
@ -178,10 +178,10 @@ void GcodeSuite::M420() {
set_bed_leveling_enabled(false);
// Subtract the mean from all values
GRID_LOOP(x, y) {
Z_VALUES(x, y) -= zmean;
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, Z_VALUES(x, y)));
bedlevel.z_values[x][y] -= zmean;
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, bedlevel.z_values[x][y]));
}
TERN_(AUTO_BED_LEVELING_BILINEAR, bbl.refresh_bed_level());
TERN_(AUTO_BED_LEVELING_BILINEAR, bedlevel.refresh_bed_level());
}
#endif
@ -202,10 +202,10 @@ void GcodeSuite::M420() {
#else
if (leveling_is_valid()) {
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
bbl.print_leveling_grid();
bedlevel.print_leveling_grid();
#elif ENABLED(MESH_BED_LEVELING)
SERIAL_ECHOLNPGM("Mesh Bed Level data:");
mbl.report_mesh();
bedlevel.report_mesh();
#endif
}
#endif

View File

@ -313,8 +313,8 @@ G29_TYPE GcodeSuite::G29() {
if (!isnan(rx) && !isnan(ry)) {
// Get nearest i / j from rx / ry
i = (rx - bbl.get_grid_start().x) / bbl.get_grid_spacing().x + 0.5f;
j = (ry - bbl.get_grid_start().y) / bbl.get_grid_spacing().y + 0.5f;
i = (rx - bedlevel.grid_start.x) / bedlevel.grid_spacing.x + 0.5f;
j = (ry - bedlevel.grid_start.y) / bedlevel.grid_spacing.y + 0.5f;
LIMIT(i, 0, (GRID_MAX_POINTS_X) - 1);
LIMIT(j, 0, (GRID_MAX_POINTS_Y) - 1);
}
@ -323,8 +323,8 @@ G29_TYPE GcodeSuite::G29() {
if (WITHIN(i, 0, (GRID_MAX_POINTS_X) - 1) && WITHIN(j, 0, (GRID_MAX_POINTS_Y) - 1)) {
set_bed_leveling_enabled(false);
Z_VALUES_ARR[i][j] = rz;
bbl.refresh_bed_level();
bedlevel.z_values[i][j] = rz;
bedlevel.refresh_bed_level();
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(i, j, rz));
set_bed_leveling_enabled(abl.reenable);
if (abl.reenable) report_current_position();
@ -463,7 +463,7 @@ G29_TYPE GcodeSuite::G29() {
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
if (!abl.dryrun
&& (abl.gridSpacing != bbl.get_grid_spacing() || abl.probe_position_lf != bbl.get_grid_start())
&& (abl.gridSpacing != bedlevel.grid_spacing || abl.probe_position_lf != bedlevel.grid_start)
) {
// Reset grid to 0.0 or "not probed". (Also disables ABL)
reset_bed_level();
@ -473,7 +473,7 @@ G29_TYPE GcodeSuite::G29() {
}
// Pre-populate local Z values from the stored mesh
TERN_(IS_KINEMATIC, COPY(abl.z_values, Z_VALUES_ARR));
TERN_(IS_KINEMATIC, COPY(abl.z_values, bedlevel.z_values));
#endif // AUTO_BED_LEVELING_BILINEAR
@ -760,14 +760,14 @@ G29_TYPE GcodeSuite::G29() {
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
if (abl.dryrun)
bbl.print_leveling_grid(&abl.z_values);
bedlevel.print_leveling_grid(&abl.z_values);
else {
bbl.set_grid(abl.gridSpacing, abl.probe_position_lf);
COPY(Z_VALUES_ARR, abl.z_values);
TERN_(IS_KINEMATIC, bbl.extrapolate_unprobed_bed_level());
bbl.refresh_bed_level();
bedlevel.set_grid(abl.gridSpacing, abl.probe_position_lf);
COPY(bedlevel.z_values, abl.z_values);
TERN_(IS_KINEMATIC, bedlevel.extrapolate_unprobed_bed_level());
bedlevel.refresh_bed_level();
bbl.print_leveling_grid();
bedlevel.print_leveling_grid();
}
#elif ENABLED(AUTO_BED_LEVELING_LINEAR)
@ -887,8 +887,8 @@ G29_TYPE GcodeSuite::G29() {
// Unapply the offset because it is going to be immediately applied
// and cause compensation movement in Z
const float fade_scaling_factor = TERN(ENABLE_LEVELING_FADE_HEIGHT, planner.fade_scaling_factor_for_z(current_position.z), 1);
current_position.z -= fade_scaling_factor * bbl.get_z_correction(current_position);
current_position.z -= bedlevel.get_z_correction(current_position)
TERN_(ENABLE_LEVELING_FADE_HEIGHT, * planner.fade_scaling_factor_for_z(current_position.z));
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM(" corrected Z:", current_position.z);
}

View File

@ -58,11 +58,11 @@ void GcodeSuite::M421() {
sy = iy >= 0 ? iy : 0, ey = iy >= 0 ? iy : GRID_MAX_POINTS_Y - 1;
LOOP_S_LE_N(x, sx, ex) {
LOOP_S_LE_N(y, sy, ey) {
Z_VALUES_ARR[x][y] = zval + (hasQ ? Z_VALUES_ARR[x][y] : 0);
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, Z_VALUES_ARR[x][y]));
bedlevel.z_values[x][y] = zval + (hasQ ? bedlevel.z_values[x][y] : 0);
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, bedlevel.z_values[x][y]));
}
}
bbl.refresh_bed_level();
bedlevel.refresh_bed_level();
}
else
SERIAL_ERROR_MSG(STR_ERR_MESH_XY);

View File

@ -93,14 +93,14 @@ void GcodeSuite::G29() {
SERIAL_ECHOPGM("Mesh Bed Leveling ");
if (leveling_is_valid()) {
serialprintln_onoff(planner.leveling_active);
mbl.report_mesh();
bedlevel.report_mesh();
}
else
SERIAL_ECHOLNPGM("has no data.");
break;
case MeshStart:
mbl.reset();
bedlevel.reset();
mbl_probe_index = 0;
if (!ui.wait_for_move) {
queue.inject(parser.seen_test('N') ? F("G28" TERN(CAN_SET_LEVELING_AFTER_G28, "L0", "") "\nG29S2") : F("G29S2"));
@ -128,7 +128,7 @@ void GcodeSuite::G29() {
}
else {
// Save Z for the previous mesh position
mbl.set_zigzag_z(mbl_probe_index - 1, current_position.z);
bedlevel.set_zigzag_z(mbl_probe_index - 1, current_position.z);
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(ix, iy, current_position.z));
TERN_(DWIN_LCD_PROUI, DWIN_MeshUpdate(_MIN(mbl_probe_index, GRID_MAX_POINTS), int(GRID_MAX_POINTS), current_position.z));
SET_SOFT_ENDSTOP_LOOSE(false);
@ -138,8 +138,8 @@ void GcodeSuite::G29() {
// Disable software endstops to allow manual adjustment
// If G29 is left hanging without completion they won't be re-enabled!
SET_SOFT_ENDSTOP_LOOSE(true);
mbl.zigzag(mbl_probe_index++, ix, iy);
_manual_goto_xy({ mbl.index_to_xpos[ix], mbl.index_to_ypos[iy] });
bedlevel.zigzag(mbl_probe_index++, ix, iy);
_manual_goto_xy({ bedlevel.index_to_xpos[ix], bedlevel.index_to_ypos[iy] });
}
else {
// Move to the after probing position
@ -195,9 +195,9 @@ void GcodeSuite::G29() {
return echo_not_entered('J');
if (parser.seenval('Z')) {
mbl.z_values[ix][iy] = parser.value_linear_units();
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(ix, iy, mbl.z_values[ix][iy]));
TERN_(DWIN_LCD_PROUI, DWIN_MeshUpdate(ix, iy, mbl.z_values[ix][iy]));
bedlevel.z_values[ix][iy] = parser.value_linear_units();
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(ix, iy, bedlevel.z_values[ix][iy]));
TERN_(DWIN_LCD_PROUI, DWIN_MeshUpdate(ix, iy, bedlevel.z_values[ix][iy]));
}
else
return echo_not_entered('Z');
@ -205,7 +205,7 @@ void GcodeSuite::G29() {
case MeshSetZOffset:
if (parser.seenval('Z'))
mbl.z_offset = parser.value_linear_units();
bedlevel.z_offset = parser.value_linear_units();
else
return echo_not_entered('Z');
break;

View File

@ -43,9 +43,9 @@
*/
void GcodeSuite::M421() {
const bool hasX = parser.seen('X'), hasI = parser.seen('I');
const int8_t ix = hasI ? parser.value_int() : hasX ? mbl.probe_index_x(RAW_X_POSITION(parser.value_linear_units())) : -1;
const int8_t ix = hasI ? parser.value_int() : hasX ? bedlevel.probe_index_x(RAW_X_POSITION(parser.value_linear_units())) : -1;
const bool hasY = parser.seen('Y'), hasJ = parser.seen('J');
const int8_t iy = hasJ ? parser.value_int() : hasY ? mbl.probe_index_y(RAW_Y_POSITION(parser.value_linear_units())) : -1;
const int8_t iy = hasJ ? parser.value_int() : hasY ? bedlevel.probe_index_y(RAW_Y_POSITION(parser.value_linear_units())) : -1;
const bool hasZ = parser.seen('Z'), hasQ = !hasZ && parser.seen('Q');
if (int(hasI && hasJ) + int(hasX && hasY) != 1 || !(hasZ || hasQ))
@ -53,7 +53,7 @@ void GcodeSuite::M421() {
else if (ix < 0 || iy < 0)
SERIAL_ERROR_MSG(STR_ERR_MESH_XY);
else
mbl.set_z(ix, iy, parser.value_linear_units() + (hasQ ? mbl.z_values[ix][iy] : 0));
bedlevel.set_z(ix, iy, parser.value_linear_units() + (hasQ ? bedlevel.z_values[ix][iy] : 0));
}
#endif // MESH_BED_LEVELING

View File

@ -39,7 +39,7 @@ void GcodeSuite::G29() {
TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_PROBE));
ubl.G29();
bedlevel.G29();
TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_IDLE));
}

View File

@ -56,7 +56,7 @@ void GcodeSuite::M421() {
hasZ = parser.seen('Z'),
hasQ = !hasZ && parser.seen('Q');
if (hasC) ij = ubl.find_closest_mesh_point_of_type(CLOSEST, current_position);
if (hasC) ij = bedlevel.find_closest_mesh_point_of_type(CLOSEST, current_position);
// Test for bad parameter combinations
if (int(hasC) + int(hasI && hasJ) != 1 || !(hasZ || hasQ || hasN))
@ -66,7 +66,7 @@ void GcodeSuite::M421() {
else if (!WITHIN(ij.x, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(ij.y, 0, GRID_MAX_POINTS_Y - 1))
SERIAL_ERROR_MSG(STR_ERR_MESH_XY);
else {
float &zval = ubl.z_values[ij.x][ij.y]; // Altering this Mesh Point
float &zval = bedlevel.z_values[ij.x][ij.y]; // Altering this Mesh Point
zval = hasN ? NAN : parser.value_linear_units() + (hasQ ? zval : 0); // N=NAN, Z=NEWVAL, or Q=ADDVAL
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(ij.x, ij.y, zval)); // Ping ExtUI in case it's showing the mesh
TERN_(DWIN_LCD_PROUI, DWIN_MeshUpdate(ij.x, ij.y, zval));

View File

@ -242,6 +242,6 @@ void GcodeSuite::M18_M84() {
else
planner.finish_and_disable();
TERN_(AUTO_BED_LEVELING_UBL, ubl.steppers_were_disabled());
TERN_(AUTO_BED_LEVELING_UBL, bedlevel.steppers_were_disabled());
}
}

View File

@ -111,7 +111,7 @@ void GcodeSuite::M290() {
#endif
#if ENABLED(MESH_BED_LEVELING)
SERIAL_ECHOLNPGM("MBL Adjust Z", mbl.z_offset);
SERIAL_ECHOLNPGM("MBL Adjust Z", bedlevel.z_offset);
#endif
#if ENABLED(BABYSTEP_DISPLAY_TOTAL)