Skip to content

Commit

Permalink
Apply home offsets to probing, Z Safe Homing (MarlinFirmware#19423)
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
  • Loading branch information
2 people authored and chrisjenda committed Apr 11, 2021
1 parent 365f893 commit 49b9fad
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 57 deletions.
26 changes: 9 additions & 17 deletions Marlin/src/gcode/bedlevel/abl/G29.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,32 +361,24 @@ G29_TYPE GcodeSuite::G29() {

if (parser.seen('H')) {
const int16_t size = (int16_t)parser.value_linear_units();
probe_position_lf.set(
_MAX(X_CENTER - size / 2, x_min),
_MAX(Y_CENTER - size / 2, y_min)
);
probe_position_rb.set(
_MIN(probe_position_lf.x + size, x_max),
_MIN(probe_position_lf.y + size, y_max)
);
probe_position_lf.set(_MAX((X_CENTER) - size / 2, x_min), _MAX((Y_CENTER) - size / 2, y_min));
probe_position_rb.set(_MIN(probe_position_lf.x + size, x_max), _MIN(probe_position_lf.y + size, y_max));
}
else {
probe_position_lf.set(
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') ? RAW_X_POSITION(parser.value_linear_units()) : x_max,
parser.seenval('B') ? RAW_Y_POSITION(parser.value_linear_units()) : y_max
);
probe_position_lf.set(parser.linearval('L', x_min), parser.linearval('F', y_min));
probe_position_rb.set(parser.linearval('R', x_max), parser.linearval('B', y_max));
}

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

// probe at the points of a lattice grid
// Probe at the points of a lattice grid
gridSpacing.set((probe_position_rb.x - probe_position_lf.x) / (abl_grid_points.x - 1),
(probe_position_rb.y - probe_position_lf.y) / (abl_grid_points.y - 1));

Expand Down
10 changes: 9 additions & 1 deletion Marlin/src/gcode/calibrate/G28.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,15 @@
* Move the Z probe (or just the nozzle) to the safe homing point
* (Z is already at the right height)
*/
destination.set(safe_homing_xy, current_position.z);
constexpr xy_float_t safe_homing_xy = { Z_SAFE_HOMING_X_POINT, Z_SAFE_HOMING_Y_POINT };
#if HAS_HOME_OFFSET
xy_float_t okay_homing_xy = safe_homing_xy;
okay_homing_xy -= home_offset;
#else
constexpr xy_float_t okay_homing_xy = safe_homing_xy;
#endif

destination.set(okay_homing_xy, current_position.z);

TERN_(HOMING_Z_WITH_PROBE, destination -= probe.offset_xy);

Expand Down
12 changes: 11 additions & 1 deletion Marlin/src/gcode/geometry/M206_M428.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
#include "../../module/motion.h"
#include "../../lcd/ultralcd.h"
#include "../../libs/buzzer.h"
#include "../../MarlinCore.h"

extern const char SP_Y_STR[], SP_Z_STR[];

void m206_report() {
SERIAL_ECHOLNPAIR_P(PSTR("M206 X"), home_offset.x, SP_Y_STR, home_offset.y, SP_Z_STR, home_offset.z);
}

/**
* M206: Set Additional Homing Offset (X Y Z). SCARA aliases T=X, P=Y
Expand All @@ -46,7 +53,10 @@ void GcodeSuite::M206() {
if (parser.seen('P')) set_home_offset(B_AXIS, parser.value_float()); // Psi
#endif

report_current_position();
if (!parser.seen("XYZ"))
m206_report();
else
report_current_position();
}

/**
Expand Down
4 changes: 0 additions & 4 deletions Marlin/src/module/motion.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ extern xyz_pos_t cartes;
#define XY_PROBE_FEEDRATE_MM_S PLANNER_XY_FEEDRATE()
#endif

#if ENABLED(Z_SAFE_HOMING)
constexpr xy_float_t safe_homing_xy = { Z_SAFE_HOMING_X_POINT, Z_SAFE_HOMING_Y_POINT };
#endif

/**
* Feed rates are often configured with mm/m
* but the planner and stepper like mm/s units.
Expand Down
52 changes: 18 additions & 34 deletions Marlin/src/module/probe.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,53 +133,37 @@ class Probe {
#if HAS_BED_PROBE || HAS_LEVELING
#if IS_KINEMATIC
static constexpr float printable_radius = (
#if ENABLED(DELTA)
DELTA_PRINTABLE_RADIUS
#elif IS_SCARA
SCARA_PRINTABLE_RADIUS
#endif
TERN_(DELTA, DELTA_PRINTABLE_RADIUS)
TERN_(IS_SCARA, SCARA_PRINTABLE_RADIUS)
);

static inline float probe_radius() {
return printable_radius - _MAX(PROBING_MARGIN, HYPOT(offset_xy.x, offset_xy.y));
}
#endif

static inline float min_x() {
return (
#if IS_KINEMATIC
(X_CENTER) - probe_radius()
#else
_MAX((X_MIN_BED) + (PROBING_MARGIN_LEFT), (X_MIN_POS) + offset_xy.x)
#endif
);
return TERN(IS_KINEMATIC,
(X_CENTER) - probe_radius(),
_MAX((X_MIN_BED) + (PROBING_MARGIN_LEFT), (X_MIN_POS) + offset_xy.x)
) - TERN0(NOZZLE_AS_PROBE, home_offset.x);
}
static inline float max_x() {
return (
#if IS_KINEMATIC
(X_CENTER) + probe_radius()
#else
_MIN((X_MAX_BED) - (PROBING_MARGIN_RIGHT), (X_MAX_POS) + offset_xy.x)
#endif
);
return TERN(IS_KINEMATIC,
(X_CENTER) + probe_radius(),
_MIN((X_MAX_BED) - (PROBING_MARGIN_RIGHT), (X_MAX_POS) + offset_xy.x)
) - TERN0(NOZZLE_AS_PROBE, home_offset.x);
}
static inline float min_y() {
return (
#if IS_KINEMATIC
(Y_CENTER) - probe_radius()
#else
_MAX((Y_MIN_BED) + (PROBING_MARGIN_FRONT), (Y_MIN_POS) + offset_xy.y)
#endif
);
return TERN(IS_KINEMATIC,
(Y_CENTER) - probe_radius(),
_MAX((Y_MIN_BED) + (PROBING_MARGIN_FRONT), (Y_MIN_POS) + offset_xy.y)
) - TERN0(NOZZLE_AS_PROBE, home_offset.y);
}
static inline float max_y() {
return (
#if IS_KINEMATIC
(Y_CENTER) + probe_radius()
#else
_MIN((Y_MAX_BED) - (PROBING_MARGIN_BACK), (Y_MAX_POS) + offset_xy.y)
#endif
);
return TERN(IS_KINEMATIC,
(Y_CENTER) + probe_radius(),
_MIN((Y_MAX_BED) - (PROBING_MARGIN_BACK), (Y_MAX_POS) + offset_xy.y)
) - TERN0(NOZZLE_AS_PROBE, home_offset.y);
}

#if NEEDS_THREE_PROBE_POINTS
Expand Down

0 comments on commit 49b9fad

Please sign in to comment.