Skip to content

Commit

Permalink
G30 select relative or absolute positions
Browse files Browse the repository at this point in the history
Absolute is where to move the print head (nozzle), relative will move
the probe to that bed location using the probe offset.  Without X or Y
this will now use absolute so it will probe straight down  instead of
first moving the probe to that location.  This is useful when jogging
the probe to a model you want to measure, or just repeating the
measurement at the current location compared to always using relative
tool head would move over with each measurement.  From the G30
documentation "By default probe in the current position."  Which I
take to be straight down, otherwise it requires
  • Loading branch information
dfries committed Apr 9, 2023
1 parent 6ee487e commit e4244fc
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions Marlin/src/gcode/probe/G30.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@
/**
* G30: Do a single Z probe at the current XY
*
* If either X or Y are given, the probe is moved to that location.
* that will be the probe location.
* the probe will be moved to
* it will move the probe to that position relative
* to the nozzle, by default it probes the position the probe is at.
*
* Parameters:
*
* X Probe X position (default current X)
Expand All @@ -56,10 +62,18 @@ void GcodeSuite::G30() {
probe.use_probing_tool();

// Convert the given logical position to native position
const xy_pos_t pos = {
parser.seenval('X') ? RAW_X_POSITION(parser.value_linear_units()) : current_position.x,
parser.seenval('Y') ? RAW_Y_POSITION(parser.value_linear_units()) : current_position.y
};
xy_pos_t pos;
const bool seenX = parser.seenval('X');
pos.x = seenX ? RAW_X_POSITION(parser.value_linear_units()) :
current_position.x;
const bool seenY = parser.seenval('Y');
pos.y = seenY ? RAW_Y_POSITION(parser.value_linear_units()) :
current_position.y;
// If X or Y was given, then probe that bed location, which means moving
// the probe over that point, which is accomplished by indicating the point
// is a relative (probe to nozzle) location. False is absolute and no
// movement since it is already at the current location.
const bool probe_relative = seenX || seenY;

if (probe.can_reach(pos)) {
// Disable leveling so the planner won't mess with us
Expand All @@ -74,7 +88,8 @@ void GcodeSuite::G30() {
const ProbePtRaise raise_after = parser.boolval('E', true) ? PROBE_PT_STOW : PROBE_PT_NONE;

TERN_(HAS_PTC, ptc.set_enabled(!parser.seen('C') || parser.value_bool()));
const float measured_z = probe.probe_at_point(pos, raise_after, 1);
const float measured_z = probe.probe_at_point(pos, raise_after, 1,
probe_relative);
TERN_(HAS_PTC, ptc.set_enabled(true));
if (!isnan(measured_z)) {
SERIAL_ECHOLNPGM("Bed X: ", pos.asLogical().x, " Y: ", pos.asLogical().y, " Z: ", measured_z);
Expand Down

0 comments on commit e4244fc

Please sign in to comment.