Skip to content

Commit

Permalink
⚡️ G30 optimize and comment
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Sep 3, 2024
1 parent 7aaba66 commit 7901eb9
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions Marlin/src/gcode/probe/G30.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@
*/
void GcodeSuite::G30() {

xy_pos_t old_pos = current_position,
probepos = current_position;
xy_pos_t probepos = current_position;

const bool seenX = parser.seenval('X');
if (seenX) probepos.x = RAW_X_POSITION(parser.value_linear_units());
Expand All @@ -62,21 +61,28 @@ void GcodeSuite::G30() {

if (probe.can_reach(probepos)) {

if (seenX) old_pos.x = probepos.x;
if (seenY) old_pos.y = probepos.y;

// Disable leveling so the planner won't mess with us
TERN_(HAS_LEVELING, set_bed_leveling_enabled(false));

// Disable feedrate scaling so movement speeds are correct
remember_feedrate_scaling_off();

// With VERBOSE_SINGLE_PROBE home only if needed
TERN_(VERBOSE_SINGLE_PROBE, process_subcommands_now(F("G28O")));

// Raise after based on the 'E' parameter
const ProbePtRaise raise_after = parser.boolval('E', true) ? PROBE_PT_STOW : PROBE_PT_NONE;

// Use 'C' to set Probe Temperature Compensation ON/OFF (on by default)
TERN_(HAS_PTC, ptc.set_enabled(parser.boolval('C', true)));

// Probe the bed, optionally raise, and return the measured height
const float measured_z = probe.probe_at_point(probepos, raise_after);

// After probing always re-enable Probe Temperature Compensation
TERN_(HAS_PTC, ptc.set_enabled(true));

// Report a good probe result to the host and LCD
if (!isnan(measured_z)) {
const xy_pos_t lpos = probepos.asLogical();
SString<30> msg(
Expand All @@ -88,9 +94,11 @@ void GcodeSuite::G30() {
TERN_(VERBOSE_SINGLE_PROBE, ui.set_status(msg));
}

// Restore feedrate scaling
restore_feedrate_and_scaling();

do_blocking_move_to(old_pos);
// Move the nozzle to the position of the probe
do_blocking_move_to(probepos);

if (raise_after == PROBE_PT_STOW)
probe.move_z_after_probing();
Expand Down

0 comments on commit 7901eb9

Please sign in to comment.