Skip to content

Commit

Permalink
Fix MIN_PROBE_EDGE bug in default ABL G29 (#16367)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjasonsmith authored and thinkyhead committed Jan 3, 2020
1 parent d7aee3b commit 3cade62
Show file tree
Hide file tree
Showing 17 changed files with 175 additions and 110 deletions.
65 changes: 37 additions & 28 deletions Marlin/src/core/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,40 +81,49 @@ void safe_delay(millis_t ms) {
);

#if HAS_BED_PROBE
SERIAL_ECHOPAIR_P(PSTR("Probe Offset X"), probe_offset.x, SP_Y_STR, probe_offset.y, SP_Z_STR, probe_offset.z);
if (probe_offset.x > 0)
SERIAL_ECHOPGM(" (Right");
else if (probe_offset.x < 0)
SERIAL_ECHOPGM(" (Left");
else if (probe_offset.y != 0)
SERIAL_ECHOPGM(" (Middle");
else
SERIAL_ECHOPGM(" (Aligned With");

if (probe_offset.y > 0) {
#if IS_SCARA
SERIAL_ECHOPGM("-Distal");
#else
SERIAL_ECHOPGM("-Back");
#endif
}
else if (probe_offset.y < 0) {
#if IS_SCARA
SERIAL_ECHOPGM("-Proximal");
#else
SERIAL_ECHOPGM("-Front");
#endif
}
else if (probe_offset.x != 0)
SERIAL_ECHOPGM("-Center");
#if !HAS_PROBE_XY_OFFSET
SERIAL_ECHOPAIR("Probe Offset X0 Y0 Z", probe_offset.z, " (");
#else
SERIAL_ECHOPAIR_P(PSTR("Probe Offset X"), probe_offset.x, SP_Y_STR, probe_offset.y, SP_Z_STR, probe_offset.z);
if (probe_offset.x > 0)
SERIAL_ECHOPGM(" (Right");
else if (probe_offset.x < 0)
SERIAL_ECHOPGM(" (Left");
else if (probe_offset.y != 0)
SERIAL_ECHOPGM(" (Middle");
else
SERIAL_ECHOPGM(" (Aligned With");

if (probe_offset.y > 0) {
#if IS_SCARA
SERIAL_ECHOPGM("-Distal");
#else
SERIAL_ECHOPGM("-Back");
#endif
}
else if (probe_offset.y < 0) {
#if IS_SCARA
SERIAL_ECHOPGM("-Proximal");
#else
SERIAL_ECHOPGM("-Front");
#endif
}
else if (probe_offset.x != 0)
SERIAL_ECHOPGM("-Center");

SERIAL_ECHOPGM(" & ");

#endif

if (probe_offset.z < 0)
SERIAL_ECHOPGM(" & Below");
SERIAL_ECHOPGM("Below");
else if (probe_offset.z > 0)
SERIAL_ECHOPGM(" & Above");
SERIAL_ECHOPGM("Above");
else
SERIAL_ECHOPGM(" & Same Z as");
SERIAL_ECHOPGM("Same Z as");
SERIAL_ECHOLNPGM(" Nozzle)");

#endif

#if HAS_ABL_OR_UBL
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/feature/bedlevel/ubl/ubl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
// Add XY probe offset from extruder because probe_at_point() subtracts them when
// moving to the XY position to be measured. This ensures better agreement between
// the current Z position after G28 and the mesh values.
const xy_int8_t curr = closest_indexes(xy_pos_t(current_position) + xy_pos_t(probe_offset));
const xy_int8_t curr = closest_indexes(xy_pos_t(current_position) + probe_offset_xy);

if (!lcd) SERIAL_EOL();
for (int8_t j = GRID_MAX_POINTS_Y - 1; j >= 0; j--) {
Expand Down
13 changes: 7 additions & 6 deletions Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@
SERIAL_ECHO(g29_pos.y);
SERIAL_ECHOLNPGM(").\n");
}
const xy_pos_t near = g29_pos + probe_offset;
const xy_pos_t near = g29_pos + probe_offset_xy;
probe_entire_mesh(near, parser.seen('T'), parser.seen('E'), parser.seen('U'));

report_current_position();
Expand All @@ -468,6 +468,7 @@
do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);

if (parser.seen('C') && !xy_seen) {

/**
* Use a good default location for the path.
* The flipped > and < operators in these comparisons is intentional.
Expand All @@ -479,8 +480,8 @@
#if IS_KINEMATIC
X_HOME_POS, Y_HOME_POS
#else
probe_offset.x > 0 ? X_BED_SIZE : 0,
probe_offset.y < 0 ? Y_BED_SIZE : 0
probe_offset_xy.x > 0 ? X_BED_SIZE : 0,
probe_offset_xy.y < 0 ? Y_BED_SIZE : 0
#endif
);
}
Expand Down Expand Up @@ -805,8 +806,8 @@
restore_ubl_active_state_and_leave();

do_blocking_move_to_xy(
constrain(near.x - probe_offset.x, MESH_MIN_X, MESH_MAX_X),
constrain(near.y - probe_offset.y, MESH_MIN_Y, MESH_MAX_Y)
constrain(near.x - probe_offset_xy.x, MESH_MIN_X, MESH_MAX_X),
constrain(near.y - probe_offset_xy.y, MESH_MIN_Y, MESH_MAX_Y)
);
}

Expand Down Expand Up @@ -1293,7 +1294,7 @@
closest.distance = -99999.9f;

// Get the reference position, either nozzle or probe
const xy_pos_t ref = probe_relative ? pos + probe_offset : pos;
const xy_pos_t ref = probe_relative ? pos + probe_offset_xy : pos;

float best_so_far = 99999.99f;

Expand Down
9 changes: 5 additions & 4 deletions Marlin/src/gcode/bedlevel/G42.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,21 @@ void GcodeSuite::G42() {
return;
}

// Move to current_position, as modified by I, J, P parameters
destination = current_position;

if (hasI) destination.x = _GET_MESH_X(ix);
if (hasJ) destination.y = _GET_MESH_Y(iy);

#if HAS_BED_PROBE
#if HAS_PROBE_XY_OFFSET
if (parser.boolval('P')) {
if (hasI) destination.x -= probe_offset.x;
if (hasJ) destination.y -= probe_offset.y;
if (hasI) destination.x -= probe_offset_xy.x;
if (hasJ) destination.y -= probe_offset_xy.y;
}
#endif

const feedRate_t fval = parser.linearval('F'),
fr_mm_s = fval > 0 ? MMM_TO_MMS(fval) : 0.0f;
fr_mm_s = MMM_TO_MMS(fval > 0 ? fval : 0.0f);

// SCARA kinematic has "safe" XY raw moves
#if IS_SCARA
Expand Down
15 changes: 7 additions & 8 deletions Marlin/src/gcode/bedlevel/abl/G29.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ G29_TYPE GcodeSuite::G29() {
ABL_VAR xy_int8_t meshCount;
#endif

ABL_VAR xy_float_t probe_position_lf, probe_position_rb;
ABL_VAR xy_pos_t probe_position_lf, probe_position_rb;
ABL_VAR xy_float_t gridSpacing = { 0, 0 };

#if ENABLED(AUTO_BED_LEVELING_LINEAR)
Expand Down Expand Up @@ -403,14 +403,13 @@ G29_TYPE GcodeSuite::G29() {
}
else {
probe_position_lf.set(
parser.seenval('L') ? (int)RAW_X_POSITION(parser.value_linear_units()) : (_MAX(x_min, X_CENTER - (X_BED_SIZE) / 2) + MIN_PROBE_EDGE_LEFT),
parser.seenval('F') ? (int)RAW_Y_POSITION(parser.value_linear_units()) : (_MAX(y_min, Y_CENTER - (Y_BED_SIZE) / 2) + MIN_PROBE_EDGE_FRONT)
parser.seenval('L') ? RAW_X_POSITION(parser.value_linear_units()) : x_min,
parser.seenval('F') ? RAW_Y_POSITION(parser.value_linear_units()) : y_min
);
probe_position_rb.set(
parser.seenval('R') ? (int)RAW_X_POSITION(parser.value_linear_units()) : (_MIN(x_max, probe_position_lf.x + X_BED_SIZE) - MIN_PROBE_EDGE_RIGHT),
parser.seenval('B') ? (int)RAW_Y_POSITION(parser.value_linear_units()) : (_MIN(y_max, probe_position_lf.y + Y_BED_SIZE) - MIN_PROBE_EDGE_BACK)
parser.seenval('R') ? RAW_X_POSITION(parser.value_linear_units()) : x_max,
parser.seenval('B') ? RAW_Y_POSITION(parser.value_linear_units()) : y_max
);
SERIAL_ECHOLN("Set Trail 1");
}

if (
Expand Down Expand Up @@ -911,8 +910,8 @@ G29_TYPE GcodeSuite::G29() {
planner.force_unapply_leveling(converted); // use conversion machinery

// Use the last measured distance to the bed, if possible
if ( NEAR(current_position.x, probePos.x - probe_offset.x)
&& NEAR(current_position.y, probePos.y - probe_offset.y)
if ( NEAR(current_position.x, probePos.x - probe_offset_xy.x)
&& NEAR(current_position.y, probePos.y - probe_offset_xy.y)
) {
const float simple_z = current_position.z - measured_z;
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Probed Z", simple_z, " Matrix Z", converted.z, " Discrepancy ", simple_z - converted.z);
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/calibrate/G28.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
destination.set(safe_homing_xy, current_position.z);

#if HOMING_Z_WITH_PROBE
destination -= probe_offset;
destination -= probe_offset_xy;
#endif

if (position_is_reachable(destination)) {
Expand Down
9 changes: 5 additions & 4 deletions Marlin/src/gcode/calibrate/M48.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ void GcodeSuite::M48() {
xy_float_t next_pos = current_position;

const xy_pos_t probe_pos = {
parser.linearval('X', next_pos.x + probe_offset.x),
parser.linearval('Y', next_pos.y + probe_offset.y)
parser.linearval('X', next_pos.x + probe_offset_xy.x),
parser.linearval('Y', next_pos.y + probe_offset_xy.y)
};

if (!position_is_reachable_by_probe(probe_pos)) {
Expand Down Expand Up @@ -166,8 +166,9 @@ void GcodeSuite::M48() {
while (angle < 0.0) angle += 360.0; // outside of this range. It looks like they behave correctly with
// numbers outside of the range, but just to be safe we clamp them.

next_pos.set(probe_pos.x - probe_offset.x + cos(RADIANS(angle)) * radius,
probe_pos.y - probe_offset.y + sin(RADIANS(angle)) * radius);
const xy_pos_t noz_pos = probe_pos - probe_offset_xy;
next_pos.set(noz_pos.x + cos(RADIANS(angle)) * radius,
noz_pos.y + sin(RADIANS(angle)) * radius);

#if DISABLED(DELTA)
LIMIT(next_pos.x, X_MIN_POS, X_MAX_POS);
Expand Down
5 changes: 3 additions & 2 deletions Marlin/src/gcode/probe/G30.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@
* E Engage the probe for each probe (default 1)
*/
void GcodeSuite::G30() {
const xy_pos_t pos = { parser.linearval('X', current_position.x + probe_offset.x),
parser.linearval('Y', current_position.y + probe_offset.y) };

const xy_pos_t pos = { parser.linearval('X', current_position.x + probe_offset_xy.x),
parser.linearval('Y', current_position.y + probe_offset_xy.y) };

if (!position_is_reachable_by_probe(pos)) return;

Expand Down
43 changes: 30 additions & 13 deletions Marlin/src/gcode/probe/M851.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,49 @@ void GcodeSuite::M851() {

// Show usage with no parameters
if (!parser.seen("XYZ")) {
SERIAL_ECHOLNPAIR_P(PSTR(MSG_PROBE_OFFSET " X"), probe_offset.x, SP_Y_STR, probe_offset.y, SP_Z_STR, probe_offset.z);
SERIAL_ECHOLNPAIR_P(
#if HAS_PROBE_XY_OFFSET
PSTR(MSG_PROBE_OFFSET " X"), probe_offset.x, SP_Y_STR, probe_offset.y, SP_Z_STR
#else
PSTR(MSG_PROBE_OFFSET " X0 Y0 Z")
#endif
, probe_offset.z
);
return;
}

// Start with current offsets and modify
xyz_pos_t offs = probe_offset;

// Assume no errors
bool ok = true;

if (parser.seenval('X')) {
const float x = parser.value_float();
if (WITHIN(x, -(X_BED_SIZE), X_BED_SIZE))
offs.x = x;
else {
SERIAL_ECHOLNPAIR("?X out of range (-", int(X_BED_SIZE), " to ", int(X_BED_SIZE), ")");
ok = false;
}
#if HAS_PROBE_XY_OFFSET
if (WITHIN(x, -(X_BED_SIZE), X_BED_SIZE))
offs.x = x;
else {
SERIAL_ECHOLNPAIR("?X out of range (-", int(X_BED_SIZE), " to ", int(X_BED_SIZE), ")");
ok = false;
}
#else
if (x) SERIAL_ECHOLNPAIR("?X must be 0 (NOZZLE_AS_PROBE)."); // ...but let 'ok' stay true
#endif
}

if (parser.seenval('Y')) {
const float y = parser.value_float();
if (WITHIN(y, -(Y_BED_SIZE), Y_BED_SIZE))
offs.y = y;
else {
SERIAL_ECHOLNPAIR("?Y out of range (-", int(Y_BED_SIZE), " to ", int(Y_BED_SIZE), ")");
ok = false;
}
#if HAS_PROBE_XY_OFFSET
if (WITHIN(y, -(Y_BED_SIZE), Y_BED_SIZE))
offs.y = y;
else {
SERIAL_ECHOLNPAIR("?Y out of range (-", int(Y_BED_SIZE), " to ", int(Y_BED_SIZE), ")");
ok = false;
}
#else
if (y) SERIAL_ECHOLNPAIR("?Y must be 0 (NOZZLE_AS_PROBE)."); // ...but let 'ok' stay true
#endif
}

if (parser.seenval('Z')) {
Expand Down
1 change: 1 addition & 0 deletions Marlin/src/inc/Conditionals_LCD.h
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@
#define PROBE_SELECTED (HAS_BED_PROBE || EITHER(PROBE_MANUALLY, MESH_BED_LEVELING))

#if HAS_BED_PROBE
#define HAS_PROBE_XY_OFFSET DISABLED(NOZZLE_AS_PROBE)
#define HAS_CUSTOM_PROBE_PIN DISABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
#define HOMING_Z_WITH_PROBE (Z_HOME_DIR < 0 && !HAS_CUSTOM_PROBE_PIN)
#ifndef Z_PROBE_LOW_POINT
Expand Down
14 changes: 14 additions & 0 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,20 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
#error "Z_MIN_PROBE_PIN must be defined if Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN is not enabled."
#endif

#if ENABLED(NOZZLE_AS_PROBE)
constexpr float sanity_nozzle_to_probe_offset[] = NOZZLE_TO_PROBE_OFFSET;
static_assert(sanity_nozzle_to_probe_offset[0] == 0.0 && sanity_nozzle_to_probe_offset[1] == 0.0,
"NOZZLE_AS_PROBE requires the X,Y offsets in NOZZLE_TO_PROBE_OFFSET to be 0,0.");
#endif

#if DISABLED(NOZZLE_AS_PROBE)
static_assert(MIN_PROBE_EDGE >= 0, "MIN_PROBE_EDGE must be >= 0.");
static_assert(MIN_PROBE_EDGE_BACK >= 0, "MIN_PROBE_EDGE_BACK must be >= 0.");
static_assert(MIN_PROBE_EDGE_FRONT >= 0, "MIN_PROBE_EDGE_FRONT must be >= 0.");
static_assert(MIN_PROBE_EDGE_LEFT >= 0, "MIN_PROBE_EDGE_LEFT must be >= 0.");
static_assert(MIN_PROBE_EDGE_RIGHT >= 0, "MIN_PROBE_EDGE_RIGHT must be >= 0.");
#endif

/**
* Make sure Z raise values are set
*/
Expand Down
20 changes: 16 additions & 4 deletions Marlin/src/module/configuration_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2354,7 +2354,12 @@ void MarlinSettings::reset() {
#if HAS_BED_PROBE
constexpr float dpo[XYZ] = NOZZLE_TO_PROBE_OFFSET;
static_assert(COUNT(dpo) == 3, "NOZZLE_TO_PROBE_OFFSET must contain offsets for X, Y, and Z.");
LOOP_XYZ(a) probe_offset[a] = dpo[a];
#if HAS_PROBE_XY_OFFSET
LOOP_XYZ(a) probe_offset[a] = dpo[a];
#else
probe_offset.x = probe_offset.y = 0;
probe_offset.z = dpo[Z_AXIS];
#endif
#endif

//
Expand Down Expand Up @@ -3102,9 +3107,16 @@ void MarlinSettings::reset() {
say_units(true);
}
CONFIG_ECHO_START();
SERIAL_ECHOLNPAIR_P(PSTR(" M851 X"), LINEAR_UNIT(probe_offset.x),
SP_Y_STR, LINEAR_UNIT(probe_offset.y),
SP_Z_STR, LINEAR_UNIT(probe_offset.z));
SERIAL_ECHOLNPAIR_P(
#if HAS_PROBE_XY_OFFSET
PSTR(" M851 X"), LINEAR_UNIT(probe_offset_xy.x),
SP_Y_STR, LINEAR_UNIT(probe_offset_xy.y),
SP_Z_STR
#else
PSTR(" M851 X0 Y0 Z")
#endif
, LINEAR_UNIT(probe_offset.z)
);
#endif

/**
Expand Down
8 changes: 1 addition & 7 deletions Marlin/src/module/delta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,7 @@ void recalc_delta_settings() {
#endif

float delta_calibration_radius() {
return FLOOR((DELTA_PRINTABLE_RADIUS - (
#if HAS_BED_PROBE
_MAX(HYPOT(probe_offset.x, probe_offset.y), MIN_PROBE_EDGE)
#else
MIN_PROBE_EDGE
#endif
)) * calibration_radius_factor);
return FLOOR((DELTA_PRINTABLE_RADIUS - _MAX(HYPOT(probe_offset_xy.x, probe_offset_xy.y), MIN_PROBE_EDGE)) * calibration_radius_factor);
}

/**
Expand Down
Loading

0 comments on commit 3cade62

Please sign in to comment.