Skip to content

Commit

Permalink
🚸 Support Bed Leveling Mesh > 16x16
Browse files Browse the repository at this point in the history
Co-Authored-By: raTmole <ratmole@users.noreply.github.com>
  • Loading branch information
thinkyhead and ratmole committed May 16, 2023
1 parent df078ca commit 060ddf5
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 25 deletions.
3 changes: 3 additions & 0 deletions Marlin/src/core/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ typedef float celsius_float_t;
typedef const_float_t const_feedRate_t;
typedef const_float_t const_celsius_float_t;

// Type large enough to count leveling grid points
typedef IF<TERN0(ABL_USES_GRID, (GRID_MAX_POINTS > 255)), uint16_t, uint8_t>::type grid_count_t;

// Conversion macros
#define MMM_TO_MMS(MM_M) feedRate_t(static_cast<float>(MM_M) / 60.0f)
#define MMS_TO_MMM(MM_S) (static_cast<float>(MM_S) * 60.0f)
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/feature/bedlevel/ubl/ubl.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ struct mesh_index_pair;
typedef struct {
bool C_seen;
int8_t KLS_storage_slot;
uint8_t R_repetition,
V_verbosity,
grid_count_t R_repetition;
uint8_t V_verbosity,
P_phase,
T_map_type;
float B_shim_thickness,
Expand Down
8 changes: 4 additions & 4 deletions Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ void unified_bed_leveling::G29() {

// Invalidate one or more nearby mesh points, possibly all.
if (parser.seen('I')) {
uint8_t count = parser.has_value() ? parser.value_byte() : 1;
grid_count_t count = parser.has_value() ? parser.value_ushort() : 1;
bool invalidate_all = count >= GRID_MAX_POINTS;
if (!invalidate_all) {
while (count--) {
Expand Down Expand Up @@ -760,14 +760,14 @@ void unified_bed_leveling::shift_mesh_height() {
TERN_(DWIN_LCD_PROUI, DWIN_LevelingStart());

save_ubl_active_state_and_disable(); // No bed level correction so only raw data is obtained
uint8_t count = GRID_MAX_POINTS;
grid_count_t count = GRID_MAX_POINTS;

mesh_index_pair best;
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(best.pos, ExtUI::G29_START));
do {
if (do_ubl_mesh_map) display_map(param.T_map_type);

const uint8_t point_num = (GRID_MAX_POINTS - count) + 1;
const grid_count_t point_num = (GRID_MAX_POINTS - count) + 1;
SERIAL_ECHOLNPGM("Probing mesh point ", point_num, "/", GRID_MAX_POINTS, ".");
TERN_(HAS_STATUS_MESSAGE, ui.status_printf(0, F(S_FMT " %i/%i"), GET_TEXT(MSG_PROBING_POINT), point_num, int(GRID_MAX_POINTS)));

Expand Down Expand Up @@ -1135,7 +1135,7 @@ bool unified_bed_leveling::G29_parse_parameters() {
param.R_repetition = 0;

if (parser.seen('R')) {
param.R_repetition = parser.has_value() ? parser.value_byte() : GRID_MAX_POINTS;
param.R_repetition = parser.has_value() ? parser.value_ushort() : GRID_MAX_POINTS;
NOMORE(param.R_repetition, GRID_MAX_POINTS);
if (param.R_repetition < 1) {
SERIAL_ECHOLNPGM("?(R)epetition count invalid (1+).\n");
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/bedlevel/G26.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ void GcodeSuite::G26() {
}

// Get repeat from 'R', otherwise do one full circuit
int16_t g26_repeats;
grid_count_t g26_repeats;
#if HAS_MARLINUI_MENU
g26_repeats = parser.intval('R', GRID_MAX_POINTS + 1);
#else
Expand Down
14 changes: 7 additions & 7 deletions Marlin/src/gcode/bedlevel/abl/G29.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ class G29_State {
#endif

#if ENABLED(AUTO_BED_LEVELING_LINEAR)
int abl_points;
grid_count_t abl_points;
#elif ENABLED(AUTO_BED_LEVELING_3POINT)
static constexpr int abl_points = 3;
static constexpr grid_count_t abl_points = 3;
#elif ABL_USES_GRID
static constexpr int abl_points = GRID_MAX_POINTS;
static constexpr grid_count_t abl_points = GRID_MAX_POINTS;
#endif

#if ABL_USES_GRID
Expand All @@ -132,16 +132,16 @@ class G29_State {

#if ENABLED(AUTO_BED_LEVELING_LINEAR)
int indexIntoAB[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
float eqnAMatrix[(GRID_MAX_POINTS) * 3], // "A" matrix of the linear system of equations
eqnBVector[GRID_MAX_POINTS], // "B" vector of Z points
float eqnAMatrix[GRID_MAX_POINTS * 3], // "A" matrix of the linear system of equations
eqnBVector[GRID_MAX_POINTS], // "B" vector of Z points
mean;
#endif
#endif
};

#if ABL_USES_GRID && EITHER(AUTO_BED_LEVELING_3POINT, AUTO_BED_LEVELING_BILINEAR)
constexpr xy_uint8_t G29_State::grid_points;
constexpr int G29_State::abl_points;
constexpr grid_count_t G29_State::abl_points;
#endif

/**
Expand Down Expand Up @@ -677,7 +677,7 @@ G29_TYPE GcodeSuite::G29() {
zig ^= true; // zag

// An index to print current state
uint8_t pt_index = (PR_OUTER_VAR) * (PR_INNER_SIZE) + 1;
grid_count_t pt_index = (PR_OUTER_VAR) * (PR_INNER_SIZE) + 1;

// Inner loop is Y with PROBE_Y_FIRST enabled
// Inner loop is X with PROBE_Y_FIRST disabled
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/bedlevel/mbl/G29.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void GcodeSuite::G29() {
SET_SOFT_ENDSTOP_LOOSE(false);
}
// If there's another point to sample, move there with optional lift.
if (mbl_probe_index < (GRID_MAX_POINTS)) {
if (mbl_probe_index < GRID_MAX_POINTS) {
// 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);
Expand Down
6 changes: 4 additions & 2 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -1498,8 +1498,8 @@ static_assert(COUNT(arm) == LOGICAL_AXES, "AXIS_RELATIVE_MODES must contain " _L
#error "AUTO_BED_LEVELING_UBL does not yet support POLAR printers."
#elif DISABLED(EEPROM_SETTINGS)
#error "AUTO_BED_LEVELING_UBL requires EEPROM_SETTINGS."
#elif !WITHIN(GRID_MAX_POINTS_X, 3, 15) || !WITHIN(GRID_MAX_POINTS_Y, 3, 15)
#error "GRID_MAX_POINTS_[XY] must be a whole number between 3 and 15."
#elif !WITHIN(GRID_MAX_POINTS_X, 3, 255) || !WITHIN(GRID_MAX_POINTS_Y, 3, 255)
#error "GRID_MAX_POINTS_[XY] must be between 3 and 255."
#endif

#elif HAS_ABL_NOT_UBL
Expand All @@ -1513,6 +1513,8 @@ static_assert(COUNT(arm) == LOGICAL_AXES, "AXIS_RELATIVE_MODES must contain " _L
*/
#if IS_SCARA && DISABLED(AUTO_BED_LEVELING_BILINEAR)
#error "SCARA machines can only use the AUTO_BED_LEVELING_BILINEAR leveling option."
#elif ABL_USES_GRID && !(WITHIN(GRID_MAX_POINTS_X, 3, 255) && WITHIN(GRID_MAX_POINTS_Y, 3, 255))
#error "GRID_MAX_POINTS_[XY] must be between 3 and 255."
#endif

#elif ENABLED(MESH_BED_LEVELING)
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/e3v2/jyersui/dwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ bool livemove = false;
bool liveadjust = false;
uint8_t preheatmode = 0;
float zoffsetvalue = 0;
uint8_t gridpoint;
grid_count_t gridpoint;
float corner_avg;
float corner_pos;

Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/lcd/extui/anycubic_vyper/dgus_tft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ namespace Anycubic {
bool msg_matched = false;

#if HAS_LEVELING
static uint8_t probe_cnt = 0;
static grid_count_t probe_cnt = 0;
#endif

// The only way to get printer status is to parse messages
Expand All @@ -564,7 +564,7 @@ namespace Anycubic {
// If probing completes ok save the mesh and park
// Ignore the custom machine name
if (strcmp_P(msg + strlen(MACHINE_NAME), MARLIN_msg_ready) == 0) {
if (probe_cnt == GRID_MAX_POINTS_X * GRID_MAX_POINTS_Y) {
if (probe_cnt == GRID_MAX_POINTS) {
probe_cnt = 0;
injectCommands(F("M500")); // G27 park nozzle
//ChangePageOfTFT(PAGE_PreLEVEL);
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/extui/dgus/mks/DGUSScreenHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ void DGUSScreenHandlerMKS::LanguageChange(DGUS_VP_Variable &var, void *val_ptr)
}

#if ENABLED(MESH_BED_LEVELING)
uint8_t mesh_point_count = GRID_MAX_POINTS;
grid_count_t mesh_point_count = GRID_MAX_POINTS;
#endif

void DGUSScreenHandlerMKS::Level_Ctrl(DGUS_VP_Variable &var, void *val_ptr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

struct BedMeshViewScreenData {
FSTR_P message;
uint8_t count;
grid_count_t count;
xy_uint8_t highlight;
};

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/menu/menu_bed_leveling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
//

// LCD probed points are from defaults
constexpr uint8_t total_probe_points = TERN(AUTO_BED_LEVELING_3POINT, 3, GRID_MAX_POINTS);
constexpr grid_count_t total_probe_points = TERN(AUTO_BED_LEVELING_3POINT, 3, GRID_MAX_POINTS);

//
// Bed leveling is done. Wait for G29 to complete.
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/module/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ void MarlinSettings::postprocess() {
{
#if ENABLED(MESH_BED_LEVELING)
static_assert(
sizeof(bedlevel.z_values) == (GRID_MAX_POINTS) * sizeof(bedlevel.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
Expand Down Expand Up @@ -955,7 +955,7 @@ void MarlinSettings::postprocess() {
{
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
static_assert(
sizeof(bedlevel.z_values) == (GRID_MAX_POINTS) * sizeof(bedlevel.z_values[0][0]),
sizeof(bedlevel.z_values) == GRID_MAX_POINTS * sizeof(bedlevel.z_values[0][0]),
"Bilinear Z array is the wrong size."
);
#endif
Expand Down

2 comments on commit 060ddf5

@marciot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thinkyhead: This commit modifies SanityCheck.h to prohibit GRID_MAX_POINTS_[XY] from being 2, whereas before it could take on that value. This was used by my Drunken Octopus firmware for enabling UBL on LulzBot printers that had four-point bed corner leveling. I believe this should still be allowed.

@thisiskeithb
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marciot: Can you open a bug report so this can be tracked/fixed?

Please sign in to comment.