Skip to content

Commit

Permalink
ADD Z_PROBE_OFFSET_XRANGE_MIN, Z_PROBE_OFFSET_XRANGE_MAX, Z_PROBE_OFF…
Browse files Browse the repository at this point in the history
…SET_YRANGE_MIN, Z_PROBE_OFFSET_YRANGE_MAX to make UIs nicer, and limit M851 XY offsets

M851 would respect the limits, so the system would be safer.

Fixes #26263
  • Loading branch information
vlsi committed Sep 11, 2023
1 parent 11f98ad commit c867de5
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 8 deletions.
18 changes: 18 additions & 0 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -1630,6 +1630,24 @@

#define Z_PROBE_LOW_POINT -2 // Farthest distance below the trigger-point to go before stopping

// For M851 give a range for adjusting the X probe offset
#ifndef Z_PROBE_OFFSET_XRANGE_MIN
#define Z_PROBE_OFFSET_XRANGE_MIN -50
#endif

#ifndef Z_PROBE_OFFSET_XRANGE_MAX
#define Z_PROBE_OFFSET_XRANGE_MAX 50
#endif

// For M851 give a range for adjusting the Y probe offset
#ifndef Z_PROBE_OFFSET_YRANGE_MIN
#define Z_PROBE_OFFSET_YRANGE_MIN -50
#endif

#ifndef Z_PROBE_OFFSET_YRANGE_MAX
#define Z_PROBE_OFFSET_YRANGE_MAX 50
#endif

// For M851 give a range for adjusting the Z probe offset
#define Z_PROBE_OFFSET_RANGE_MIN -20
#define Z_PROBE_OFFSET_RANGE_MAX 20
Expand Down
8 changes: 4 additions & 4 deletions Marlin/src/gcode/probe/M851.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ void GcodeSuite::M851() {
if (parser.seenval('X')) {
const float x = parser.value_float();
#if HAS_PROBE_XY_OFFSET
if (WITHIN(x, -(X_BED_SIZE), X_BED_SIZE))
if (WITHIN(x, Z_PROBE_OFFSET_XRANGE_MIN, Z_PROBE_OFFSET_XRANGE_MAX))
offs.x = x;
else {
SERIAL_ECHOLNPGM("?X out of range (-", X_BED_SIZE, " to ", X_BED_SIZE, ")");
SERIAL_ECHOLNPGM("?X out of range (", Z_PROBE_OFFSET_XRANGE_MIN, " to ", Z_PROBE_OFFSET_XRANGE_MAX, ")");
ok = false;
}
#else
Expand All @@ -58,10 +58,10 @@ void GcodeSuite::M851() {
if (parser.seenval('Y')) {
const float y = parser.value_float();
#if HAS_PROBE_XY_OFFSET
if (WITHIN(y, -(Y_BED_SIZE), Y_BED_SIZE))
if (WITHIN(y, Z_PROBE_OFFSET_YRANGE_MIN, Z_PROBE_OFFSET_YRANGE_MAX))
offs.y = y;
else {
SERIAL_ECHOLNPGM("?Y out of range (-", Y_BED_SIZE, " to ", Y_BED_SIZE, ")");
SERIAL_ECHOLNPGM("?Y out of range (", Z_PROBE_OFFSET_YRANGE_MIN, " to ", Z_PROBE_OFFSET_YRANGE_MAX, ")");
ok = false;
}
#else
Expand Down
13 changes: 13 additions & 0 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -1419,6 +1419,19 @@ static_assert(COUNT(arm) == LOGICAL_AXES, "AXIS_RELATIVE_MODES must contain " _L
static_assert(PROBING_MARGIN_RIGHT >= 0, "PROBING_MARGIN_RIGHT must be >= 0.");
#endif

#define static_assert_within(varname, x, min, max) static_assert(WITHIN(x, min, max), #varname " must be within " #min " and " #max)

static_assert_within("Z_PROBE_OFFSET_XRANGE_MIN", Z_PROBE_OFFSET_XRANGE_MIN, -(X_BED_SIZE), X_BED_SIZE);
static_assert_within("Z_PROBE_OFFSET_XRANGE_MAX", Z_PROBE_OFFSET_XRANGE_MAX, -(X_BED_SIZE), X_BED_SIZE);
static_assert_within("Z_PROBE_OFFSET_YRANGE_MIN", Z_PROBE_OFFSET_YRANGE_MIN, -(Y_BED_SIZE), Y_BED_SIZE);
static_assert_within("Z_PROBE_OFFSET_YRANGE_MAX", Z_PROBE_OFFSET_YRANGE_MAX, -(Y_BED_SIZE), Y_BED_SIZE);
static_assert_within("Z_PROBE_OFFSET_RANGE_MIN", Z_PROBE_OFFSET_RANGE_MIN, -(Z_MAX_POS), Z_MAX_POS);
static_assert_within("Z_PROBE_OFFSET_RANGE_MAX", Z_PROBE_OFFSET_RANGE_MAX, -(Z_MAX_POS), Z_MAX_POS);

static_assert_within("NOZZLE_TO_PROBE_OFFSET.x", sanity_nozzle_to_probe_offset.x, Z_PROBE_OFFSET_XRANGE_MIN, Z_PROBE_OFFSET_XRANGE_MAX);
static_assert_within("NOZZLE_TO_PROBE_OFFSET.y", sanity_nozzle_to_probe_offset.y, Z_PROBE_OFFSET_YRANGE_MIN, Z_PROBE_OFFSET_YRANGE_MAX);
static_assert_within("NOZZLE_TO_PROBE_OFFSET.z", sanity_nozzle_to_probe_offset.z, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX);

#define _MARGIN(A) TERN(IS_KINEMATIC, PRINTABLE_RADIUS, ((A##_BED_SIZE) / 2))
static_assert(PROBING_MARGIN < _MARGIN(X), "PROBING_MARGIN is too large.");
static_assert(PROBING_MARGIN_BACK < _MARGIN(Y), "PROBING_MARGIN_BACK is too large.");
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/lcd/extui/mks_ui/draw_number_key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,14 +358,14 @@ static void set_value_confirm() {
case x_offset: {
#if HAS_PROBE_XY_OFFSET
const float x = atof(key_value);
if (WITHIN(x, -(X_BED_SIZE), X_BED_SIZE))
if (WITHIN(x, Z_PROBE_OFFSET_XRANGE_MIN, Z_PROBE_OFFSET_XRANGE_MAX))
probe.offset.x = x;
#endif
} break;
case y_offset: {
#if HAS_PROBE_XY_OFFSET
const float y = atof(key_value);
if (WITHIN(y, -(Y_BED_SIZE), Y_BED_SIZE))
if (WITHIN(y, Z_PROBE_OFFSET_YRANGE_MIN, Z_PROBE_OFFSET_YRANGE_MAX))
probe.offset.y = y;
#endif
} break;
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/lcd/menu/menu_advanced.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,8 +628,8 @@ void menu_backlash();
START_MENU();
BACK_ITEM(MSG_ADVANCED_SETTINGS);
#if HAS_PROBE_XY_OFFSET
EDIT_ITEM(float31sign, MSG_ZPROBE_XOFFSET, &probe.offset.x, -(X_BED_SIZE), X_BED_SIZE);
EDIT_ITEM(float31sign, MSG_ZPROBE_YOFFSET, &probe.offset.y, -(Y_BED_SIZE), Y_BED_SIZE);
EDIT_ITEM(float31sign, MSG_ZPROBE_XOFFSET, &probe.offset.x, Z_PROBE_OFFSET_XRANGE_MIN, Z_PROBE_OFFSET_XRANGE_MAX);
EDIT_ITEM(float31sign, MSG_ZPROBE_YOFFSET, &probe.offset.y, Z_PROBE_OFFSET_YRANGE_MIN, Z_PROBE_OFFSET_YRANGE_MAX);
#endif
EDIT_ITEM(LCD_Z_OFFSET_TYPE, MSG_ZPROBE_ZOFFSET, &probe.offset.z, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX);

Expand Down

0 comments on commit c867de5

Please sign in to comment.