Skip to content

Conversation

@vehystrix
Copy link
Contributor

Description

When flashing new firmware, the bed leveling mesh is lost in most cases. When you have the mesh saved somewhere (eg from the output of M503) in the form of a bunch of G29 W commands, it is not possible to directly restore the mesh. First you need to home XYZ and then you need to do a full G29 run.

With this PR, I added the new option G29 P<value> to allow you to initialize the mesh to the specified value, after which you can use G29 W commands to fill the mesh.

I also removed the requirement to home XYZ before using G29 W

Just like with G29 W, any values outside the -10 to 10 range are rejected

Old way to restore the mesh:

G28  ; takes a while depending on the print head position
G29  ; takes even longer
M104 S0  ; reset temperature after bed leveling
M140 S0  ; reset temperature after bed leveling
G29 W I0 J0 Z0.01
...
G29 W I6 J6 Z-0.02
M500

New way to restore the mesh

G29 P0
G29 W I0 J0 Z0.01
...
G29 W I6 J6 Z-0.02
M500

Requirements

AUTO_BED_LEVELING_BILINEAR

Example

Example
Send: M420 V
Recv: echo:Invalid mesh.
Recv: echo:Bed Leveling OFF
Recv: echo:Fade Height 10.00
Recv: ok

Send: G29 W I0 J0 Z0.01
Recv: Error:No bilinear grid
Recv: ok

Send: G29 P0
Recv: Bilinear Leveling Grid:
Recv:       0      1      2      3      4      5      6
Recv:  0 +0.000 +0.000 +0.000 +0.000 +0.000 +0.000 +0.000
Recv:  1 +0.000 +0.000 +0.000 +0.000 +0.000 +0.000 +0.000
Recv:  2 +0.000 +0.000 +0.000 +0.000 +0.000 +0.000 +0.000
Recv:  3 +0.000 +0.000 +0.000 +0.000 +0.000 +0.000 +0.000
Recv:  4 +0.000 +0.000 +0.000 +0.000 +0.000 +0.000 +0.000
Recv:  5 +0.000 +0.000 +0.000 +0.000 +0.000 +0.000 +0.000
Recv:  6 +0.000 +0.000 +0.000 +0.000 +0.000 +0.000 +0.000
Recv: 
Recv: ok

Send: G29 W I0 J0 Z0.01
Recv: X:-10.30 Y:0.00 Z:10.00 E:0.00 Count X:-819 Y:0 Z:4000
Recv: ok

Send: M420 V
Recv: Bilinear Leveling Grid:
Recv:       0      1      2      3      4      5      6
Recv:  0 +0.010 +0.000 +0.000 +0.000 +0.000 +0.000 +0.000
Recv:  1 +0.000 +0.000 +0.000 +0.000 +0.000 +0.000 +0.000
Recv:  2 +0.000 +0.000 +0.000 +0.000 +0.000 +0.000 +0.000
Recv:  3 +0.000 +0.000 +0.000 +0.000 +0.000 +0.000 +0.000
Recv:  4 +0.000 +0.000 +0.000 +0.000 +0.000 +0.000 +0.000
Recv:  5 +0.000 +0.000 +0.000 +0.000 +0.000 +0.000 +0.000
Recv:  6 +0.000 +0.000 +0.000 +0.000 +0.000 +0.000 +0.000
Recv: 
Recv: echo:Bed Leveling ON
Recv: echo:Fade Height 10.00
Recv: ok

Send: G29 P100
Recv: Error:Bad initialization value
Recv: ok

Send: G29 P0.5
Recv: Bilinear Leveling Grid:
Recv:       0      1      2      3      4      5      6
Recv:  0 +0.500 +0.500 +0.500 +0.500 +0.500 +0.500 +0.500
Recv:  1 +0.500 +0.500 +0.500 +0.500 +0.500 +0.500 +0.500
Recv:  2 +0.500 +0.500 +0.500 +0.500 +0.500 +0.500 +0.500
Recv:  3 +0.500 +0.500 +0.500 +0.500 +0.500 +0.500 +0.500
Recv:  4 +0.500 +0.500 +0.500 +0.500 +0.500 +0.500 +0.500
Recv:  5 +0.500 +0.500 +0.500 +0.500 +0.500 +0.500 +0.500
Recv:  6 +0.500 +0.500 +0.500 +0.500 +0.500 +0.500 +0.500
Recv: 
Recv: ok

@thinkyhead thinkyhead force-pushed the G29_ABL_BILINEAR_INIT0 branch 2 times, most recently from 502376b to bd1eeac Compare September 15, 2025 01:02
@thinkyhead thinkyhead force-pushed the G29_ABL_BILINEAR_INIT0 branch from bd1eeac to 0369ceb Compare September 15, 2025 01:04
@vehystrix
Copy link
Contributor Author

So I took a look at the changes you made here, and I don't think it'll work properly (I may have missed something and didn't actually built and tested it yet)

  • G29 P doesn't seem to exit early so a full bed level is still done
  • The mesh validity is determined by bedlevel.grid_spacing.x and this is no longer set
    static bool has_mesh() { return !!grid_spacing.x; }
  • bedlevel.grid_start is similarly not set anymore

I guess replacing line 274 with the following would fix it, but this also kind of smells

      const float x_min = probe.min_x(), x_max = probe.max_x(),
                  y_min = probe.min_y(), y_max = probe.max_y();
      if (parser.seen('H')) {
        const int16_t size = (int16_t)parser.value_linear_units();
        abl.probe_position_lf.set(_MAX((X_CENTER) - size / 2, x_min), _MAX((Y_CENTER) - size / 2, y_min));
        abl.probe_position_rb.set(_MIN(abl.probe_position_lf.x + size, x_max), _MIN(abl.probe_position_lf.y + size, y_max));
      }
      else {
        abl.probe_position_lf.set(parser.linearval('L', x_min), parser.linearval('F', y_min));
        abl.probe_position_rb.set(parser.linearval('R', x_max), parser.linearval('B', y_max));
      }

      if (!probe.good_bounds(abl.probe_position_lf, abl.probe_position_rb)) {
        if (DEBUGGING(LEVELING)) {
          DEBUG_ECHOLNPGM("G29 L", abl.probe_position_lf.x, " R", abl.probe_position_rb.x,
                             " F", abl.probe_position_lf.y, " B", abl.probe_position_rb.y);
        }
        SERIAL_ECHOLNPGM(GCODE_ERR_MSG(" (L,R,F,B) out of bounds."));
        G29_RETURN(false, false);
      }

      // Probe at the points of a lattice grid
      abl.gridSpacing.set((abl.probe_position_rb.x - abl.probe_position_lf.x) / (abl.grid_points.x - 1),
                          (abl.probe_position_rb.y - abl.probe_position_lf.y) / (abl.grid_points.y - 1));
      
      bedlevel.fill(init_val);
      bedlevel.set_grid(abl.gridSpacing, abl.probe_position_lf);

      G29_RETURN(false, false);

@thinkyhead thinkyhead force-pushed the bugfix-2.1.x branch 3 times, most recently from 52532da to 06c6c47 Compare November 20, 2025 04:01

void LevelingBilinear::set_grid(const xy_pos_t& _grid_spacing, const xy_pos_t& _grid_start) {
grid_spacing = _grid_spacing;
grid_start = _grid_start;
Copy link
Contributor

Choose a reason for hiding this comment

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

I use

  grid_start.x = MESH_MIN_X;
  grid_start.y = MESH_MIN_Y;
  grid_spacing.x = MESH_X_DIST;
  grid_spacing.y = MESH_Y_DIST; 

if that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants