Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bed mesh algorithm for 3 point bicubic algorightm #5296

Merged

Conversation

igiannakas
Copy link
Contributor

Description

Fixes #4875, #4694

Checks the below conditions for Klipper firmware:

  1. If the total number of mesh points is 6 -> use Lagrange interpolation
  2. If the total number of mesh points is greater than 6, use Bicubic
  3. If bicubic is used, ensure that at least 4 points are present in both X and Y.

This appears consistent with the Klipper documentation below and the KAMP implementation.

algorithm: lagrange
Default Value: lagrange
The algorithm used to interpolate the mesh. May be lagrange or bicubic. Lagrange interpolation is capped at 6 probed points as oscillation tends to occur with a larger number of samples. Bicubic interpolation requires a minimum of 4 probed points along each axis, if less than 4 points are specified then lagrange sampling is forced. If mesh_pps is set to 0 then this value is ignored as no mesh interpolation is done.

src/libslic3r/GCode.cpp Outdated Show resolved Hide resolved
@igiannakas
Copy link
Contributor Author

So I've been checking out how KAMP does it

    {% if (([points_x, points_y]|max) > 6) %}                                                                                       # 
        {% set algorithm = "bicubic" %}                                                                                             # 
        {% set min_points = 4 %}                                                                                                    # 
    {% else %}                                                                                                                      # Calculate if algorithm should be bicubic or lagrange
        {% set algorithm = "lagrange" %}                                                                                            # 
        {% set min_points = 3 %}                                                                                                    # 
    {% endif %}  

So they take the max of points X and points Y and if either is >6 -> use Bicubic. So for Orca should this snippet be?

        auto bed_mesh_algo = "bicubic";
        int min_points = 4; // bicubic needs 4 probe points per axis
        if (std::max(probe_count_x, probe_count_y) <= 6) { // lagrange needs up to a total of 6 mesh points
            bed_mesh_algo = "lagrange";
            min_points = 3;
        }

@SoftFever
Copy link
Owner

SoftFever commented May 8, 2024

So I've been checking out how KAMP does it

    {% if (([points_x, points_y]|max) > 6) %}                                                                                       # 
        {% set algorithm = "bicubic" %}                                                                                             # 
        {% set min_points = 4 %}                                                                                                    # 
    {% else %}                                                                                                                      # Calculate if algorithm should be bicubic or lagrange
        {% set algorithm = "lagrange" %}                                                                                            # 
        {% set min_points = 3 %}                                                                                                    # 
    {% endif %}  

So they take the max of points X and points Y and if either is >6 -> use Bicubic. So for Orca should this snippet be?

        auto bed_mesh_algo = "bicubic";
        int min_points = 4; // bicubic needs 4 probe points per axis
        if (std::max(probe_count_x, probe_count_y) <= 6) { // lagrange needs up to a total of 6 mesh points
            bed_mesh_algo = "lagrange";
            min_points = 3;
        }

According to Klipper doc, this is also wrong.

I think the previous probe_count_x * probe_count_y <= 6 logic is correct.

Just that the min points check need to be changed.
Something like following?

        auto bed_mesh_algo = "bicubic";
        if (probe_count_x * probe_count_y <= 6) { // lagrange needs up to a total of 6 mesh points
            bed_mesh_algo = "lagrange";
        }
        else {
          if(print.config().gcode_flavor == gcfKlipper){
              // bicubic needs 4 probe points per axis
              probe_count_x = std::max(probe_count_x,4);
              probe_count_y = std::max(probe_count_y,4);
            }
          //no-op
          }

@igiannakas
Copy link
Contributor Author

OK I think it's done (?). Git has been a bit slow and difficult this evening for some reason

Copy link
Owner

@SoftFever SoftFever left a comment

Choose a reason for hiding this comment

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

LGTM

@SoftFever SoftFever merged commit de5c1c8 into SoftFever:main May 9, 2024
12 checks passed
@igiannakas igiannakas deleted the Bed-mesh-fixes-for-lagrange-interpolation branch May 9, 2024 14:18
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.

Adaptive bed mesh generates unusable probe count on large machines
2 participants