Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Marlin/src/gcode/calibrate/G34_M422.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
* I<int> Number of test iterations. If omitted, Z_STEPPER_ALIGN_ITERATIONS. (1-30)
* T<float> Target Accuracy factor. If omitted, Z_STEPPER_ALIGN_ACC. (0.01-1.0)
* A<float> Provide an Amplification value. If omitted, Z_STEPPER_ALIGN_AMP. (0.5-2.0)
* E<bool> Stow or raise the probe after probing. 0=raise (default), 1=stow.
* R Recalculate points based on current probe offsets
*
* Example:
Expand Down
8 changes: 5 additions & 3 deletions Marlin/src/gcode/probe/G30.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ void GcodeSuite::G30() {

if (probe.can_reach(probepos)) {

// Disable leveling so the planner won't mess with us
TERN_(HAS_LEVELING, set_bed_leveling_enabled(false));
#if HAS_LEVELING
// Temporarily disable leveling so the planner won't mess with us
TEMPORARY_BED_LEVELING_STATE(false);
#endif

// Disable feedrate scaling so movement speeds are correct
remember_feedrate_scaling_off();
Expand Down Expand Up @@ -117,7 +119,7 @@ void GcodeSuite::G30() {
LCD_MESSAGE(MSG_ZPROBE_OUT);
}

probe.use_probing_tool(false);
probe.use_probing_tool(false);
}

#endif // HAS_BED_PROBE
111 changes: 51 additions & 60 deletions Marlin/src/gcode/probe/G38.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,41 +30,11 @@
#include "../../module/motion.h"
#include "../../module/planner.h"
#include "../../module/probe.h"
#include "../../feature/bedlevel/bedlevel.h"
#include "../../lcd/marlinui.h"

probe_target_t G38_move{0};

inline void G38_single_probe(const uint8_t move_value) {
endstops.enable(true);
G38_move.type = move_value;
prepare_line_to_destination();
planner.synchronize();
G38_move.type = 0;
endstops.hit_on_purpose();
set_current_from_steppers_for_axis(ALL_AXES_ENUM);
sync_plan_position();
}

/**
* Handle G38.N where N is the sub-code for the type of probe:
* 2 - Probe toward workpiece, stop on contact, signal error if failure
* 3 - Probe toward workpiece, stop on contact
* 4 - Probe away from workpiece, stop on contact break, signal error if failure
* 5 - Probe away from workpiece, stop on contact break
*/
FORCE_INLINE bool G38_run_probe() {

bool G38_pass_fail = false;

#if MULTIPLE_PROBING > 1
// Get direction of move and retract
xyz_float_t retract_mm;
LOOP_NUM_AXES(i) {
const float dist = destination[i] - current_position[i];
retract_mm[i] = ABS(dist) < G38_MINIMUM_MOVE ? 0 : home_bump_mm((AxisEnum)i) * (dist > 0 ? -1 : 1);
}
#endif

planner.synchronize(); // Wait until the machine is idle
inline bool G38_run_probe(const ProbePtRaise raise_after) {

// Move flag value
#if ENABLED(G38_PROBE_AWAY)
Expand All @@ -73,33 +43,34 @@ FORCE_INLINE bool G38_run_probe() {
constexpr uint8_t move_value = 1;
#endif

G38_move.triggered = false;

// Move until destination reached or target hit
G38_single_probe(move_value);

if (G38_move.triggered) {

G38_pass_fail = true;

#if MULTIPLE_PROBING > 1
// Move away by the retract distance
destination = current_position + retract_mm;
endstops.enable(false);
prepare_line_to_destination();
planner.synchronize();

REMEMBER(fr, feedrate_mm_s, feedrate_mm_s * 0.25);

// Bump the target more slowly
destination -= retract_mm * 2;
const xyz_pos_t measured = probe.probe_safely(destination, raise_after, move_value, 0, true, true, Z_TWEEN_SAFE_CLEARANCE, true);

LOOP_NUM_AXES(a) {
if (isnan(measured[a])) return true;
}

G38_single_probe(move_value);
#endif
// Report a good probe result in machine coordinate system to the host and LCD
SString<30> msg(
F("Machine X:"), p_float_t(measured.x, 2),
F(" Y:"), p_float_t(measured.y, 2),
F(" Z:"), p_float_t(measured.z, 3)
);
msg.echoln();
TERN_(VERBOSE_SINGLE_PROBE, ui.set_status(msg));

// If the probe is stowed, move the nozzle to the position of the probe
const xyz_pos_t offs = DIFF_TERN(HAS_HOTEND_OFFSET, probe.offset, hotend_offset[active_extruder]);
if ((!endstops.z_probe_enabled) && (probe.offset.z >= TERN0(HAS_HOTEND_OFFSET, hotend_offset[active_extruder].z))) {
if ((!NEAR_ZERO(offs.x)) || (!NEAR_ZERO(offs.y)) || offs.z > 0.0f) {
do_z_clearance_by(Z_TWEEN_SAFE_CLEARANCE);
}
destination = measured;
do_blocking_move_to(destination);
planner.synchronize();
}

endstops.not_homing();
return G38_pass_fail;
report_current_position();
return false;
}

/**
Expand All @@ -112,26 +83,46 @@ FORCE_INLINE bool G38_run_probe() {
*
* G38.4 - Probe away from workpiece, stop on contact break, signal error if failure
* G38.5 - Probe away from workpiece, stop on contact break
*
* Parameters:
*
* X Probe X position (default current X)
* Y Probe Y position (default current Y)
* Z Probe Z position (default current Z)
* S Stow the probe after probing (default: 0)
*/
void GcodeSuite::G38(const int8_t subcode) {

// Get X Y Z E F
get_destination_from_command();

probe.use_probing_tool();

#if HAS_LEVELING
// Temporarily disable leveling so the planner won't mess with us
TEMPORARY_BED_LEVELING_STATE(false);
#endif

remember_feedrate_scaling_off();

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

const bool error_on_fail = TERN(G38_PROBE_AWAY, !TEST(subcode, 0), subcode == 2);

// If any axis has enough movement, do the move
LOOP_NUM_AXES(i)
LOOP_NUM_AXES(i) {
if (ABS(destination[i] - current_position[i]) >= G38_MINIMUM_MOVE) {
if (!parser.seenval('F')) feedrate_mm_s = homing_feedrate((AxisEnum)i);
// If G38.2 fails throw an error
if (!G38_run_probe() && error_on_fail) SERIAL_ERROR_MSG("Failed to reach target");
if (G38_run_probe(raise_after) && error_on_fail) {
SERIAL_ERROR_MSG("Failed to reach target");
}
break;
}

}
restore_feedrate_and_scaling();
probe.use_probing_tool(false);
}

#endif // G38_PROBE_TARGET
6 changes: 3 additions & 3 deletions Marlin/src/module/endstops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ void Endstops::update() {

#if ENABLED(G38_PROBE_TARGET)
// For G38 moves check the probe's pin for ALL movement
if (G38_move.type) UPDATE_LIVE_STATE(Z, TERN(USE_Z_MIN_PROBE, MIN_PROBE, MIN));
if (probe.G38_move.type) UPDATE_LIVE_STATE(Z, TERN(USE_Z_MIN_PROBE, MIN_PROBE, MIN));
#endif

#if ENABLED(CALIBRATION_GCODE)
Expand Down Expand Up @@ -666,8 +666,8 @@ void Endstops::update() {

#if ENABLED(G38_PROBE_TARGET)
// For G38 moves check the probe's pin for ALL movement
if (G38_move.type && TEST_ENDSTOP(Z_MIN_PROBE) == TERN1(G38_PROBE_AWAY, (G38_move.type < 4))) {
G38_move.triggered = true;
if (probe.G38_move.type && TEST_ENDSTOP(Z_MIN_PROBE) == TERN1(G38_PROBE_AWAY, (probe.G38_move.type < 4))) {
probe.G38_move.triggered = true;
#define _G38_SET(Q) | (AXIS_IS_MOVING(Q) << _AXIS(Q))
#define _G38_RESP(Q) if (moving[_AXIS(Q)]) { _ENDSTOP_HIT(Q, ENDSTOP); planner.endstop_triggered(_AXIS(Q)); }
const Flags<NUM_AXES> moving = { uvalue_t(NUM_AXES)(0 MAIN_AXIS_MAP(_G38_SET)) };
Expand Down
1 change: 0 additions & 1 deletion Marlin/src/module/endstops.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,5 +319,4 @@ class TemporaryGlobalEndstopsState {
uint8_t type; // Flag to tell the ISR the type of G38 in progress; 0 for NONE.
bool triggered; // Flag from the ISR to indicate the endstop changed
} probe_target_t;
extern probe_target_t G38_move;
#endif
Loading