Skip to content

quad_gantry_level: max_adjust only guards the positive direction #951

Description

@yonkiman

This is a code-reading finding, not an observed failure — no log applies. The argument is that z_adjust sums to zero by construction, so max() alone cannot bound the negative extreme.

File: klippy/extras/

quad_gantry_level.py

, in probe_finalize()

Code:

z_ave = sum(z_height) / len(z_height)
z_adjust = []
for z in z_height:
    z_adjust.append(z_ave - z)

adjust_max = max(z_adjust)
if adjust_max > self.max_adjust:
    raise self.gcode.error("Aborting quad_gantry_level ...")

Problem:

z_adjust is computed as (z_ave - z_height) for each stepper, where z_ave is the mean of z_height. The four values therefore always sum to exactly zero.

The guard tests only max(z_adjust), so it constrains the largest POSITIVE adjustment and never examines the largest negative one.

Because the values sum to zero, for N=4 the most negative element is bounded by -3 * max(z_adjust). The guard therefore permits a negative adjustment of up to 3 * max_adjust.

Example (max_adjust = 10):

z_adjust = [-30.0, +10.0, +10.0, +10.0]
max(z_adjust) = 10.0  ->  not > 10.0  ->  passes
one gantry corner is then driven down 30 mm

Impact:

max_adjust is a safety limit intended to stop a bad probe result driving the gantry into the bed. In the negative direction it under-protects by 3x. It only bites when probing returns a wildly wrong value, which is exactly the condition the guard exists for.

Suggested fix:

adjust_max = max(abs(z) for z in z_adjust)

or test max() and min() separately so the error message can report which stepper and which direction.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions