Skip to content

Commit

Permalink
Add G38.4 and G38.5 (#13348)
Browse files Browse the repository at this point in the history
  • Loading branch information
michielbaird authored and thinkyhead committed Mar 10, 2019
1 parent e4d080e commit b824a51
Show file tree
Hide file tree
Showing 80 changed files with 732 additions and 264 deletions.
12 changes: 9 additions & 3 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1068,11 +1068,17 @@
// Support for G5 with XYZE destination and IJPQ offsets. Requires ~2666 bytes.
//#define BEZIER_CURVE_SUPPORT

// G38.2 and G38.3 Probe Target
// Set MULTIPLE_PROBING if you want G38 to double touch
/**
* G38 Probe Target
*
* This option adds G38.2 and G38.3 (probe towards target)
* and optionally G38.4 and G38.5 (probe away from target).
* Set MULTIPLE_PROBING for G38 to probe more than once.
*/
//#define G38_PROBE_TARGET
#if ENABLED(G38_PROBE_TARGET)
#define G38_MINIMUM_MOVE 0.0275 // minimum distance in mm that will produce a move (determined using the print statement in check_move)
//#define G38_PROBE_AWAY // Include G38.4 and G38.5 to probe away from target
#define G38_MINIMUM_MOVE 0.0275 // (mm) Minimum distance that will produce a move.
#endif

// Moves (or segments) with fewer steps than this will be joined with the next move
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/Marlin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@
#endif

#if ENABLED(G38_PROBE_TARGET)
bool G38_move = false,
G38_endstop_hit = false;
uint8_t G38_move; // = 0
bool G38_did_trigger; // = false
#endif

#if ENABLED(DELTA)
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/Marlin.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ void manage_inactivity(const bool ignore_stepper_queue=false);
#endif

#if ENABLED(G38_PROBE_TARGET)
extern bool G38_move, // flag to tell the interrupt handler that a G38 command is being run
G38_endstop_hit; // flag from the interrupt handler to indicate if the endstop went active
extern uint8_t G38_move; // Flag to tell the ISR that G38 is in progress, and the type
extern bool G38_did_trigger; // Flag from the ISR to indicate the endstop changed
#endif

/**
Expand Down
11 changes: 8 additions & 3 deletions Marlin/src/gcode/gcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,14 @@ void GcodeSuite::process_parsed_command(
#endif

#if ENABLED(G38_PROBE_TARGET)
case 38: // G38.2 & G38.3: Probe towards target
if (parser.subcode == 2 || parser.subcode == 3)
G38(parser.subcode == 2);
case 38: // G38.2, G38.3: Probe towards target
if (WITHIN(parser.subcode, 2,
#if ENABLED(G38_PROBE_AWAY)
5
#else
3
#endif
)) G38(parser.subcode); // G38.4, G38.5: Probe away from target
break;
#endif

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/gcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ class GcodeSuite {
#endif

#if ENABLED(G38_PROBE_TARGET)
static void G38(const bool is_38_2);
static void G38(const int8_t subcode);
#endif

#if HAS_MESH
Expand Down
70 changes: 43 additions & 27 deletions Marlin/src/gcode/probe/G38.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,18 @@
#include "../../module/stepper.h"
#include "../../module/probe.h"

static bool G38_run_probe() {
inline void G38_single_probe(const uint8_t move_value) {
endstops.enable(true);
G38_move = move_value;
prepare_move_to_destination();
planner.synchronize();
G38_move = 0;
endstops.hit_on_purpose();
set_current_from_steppers_for_axis(ALL_AXES);
sync_plan_position();
}

inline bool G38_run_probe() {

bool G38_pass_fail = false;

Expand All @@ -46,19 +57,19 @@ static bool G38_run_probe() {

planner.synchronize(); // wait until the machine is idle

// Move until destination reached or target hit
endstops.enable(true);
G38_move = true;
G38_endstop_hit = false;
prepare_move_to_destination();
planner.synchronize();
G38_move = false;
// Move flag value
#if ENABLED(G38_PROBE_AWAY)
const uint8_t move_value = parser.subcode;
#else
constexpr uint8_t move_value = 1;
#endif

endstops.hit_on_purpose();
set_current_from_steppers_for_axis(ALL_AXES);
sync_plan_position();
G38_did_trigger = false;

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

if (G38_did_trigger) {

G38_pass_fail = true;

Expand All @@ -70,45 +81,50 @@ static bool G38_run_probe() {
prepare_move_to_destination();
planner.synchronize();

feedrate_mm_s /= 4;
REMEMBER(fr, feedrate_mm_s, feedrate_mm_s * 0.25);

// Bump the target more slowly
LOOP_XYZ(i) destination[i] -= retract_mm[i] * 2;

endstops.enable(true);
G38_move = true;
prepare_move_to_destination();
planner.synchronize();
G38_move = false;

set_current_from_steppers_for_axis(ALL_AXES);
sync_plan_position();
G38_single_probe(move_value);
#endif
}

endstops.hit_on_purpose();
endstops.not_homing();
return G38_pass_fail;
}

/**
* G38.2 - probe toward workpiece, stop on contact, signal error if failure
* G38.3 - probe toward workpiece, stop on contact
* G38 Probe Target
*
* G38.2 - Probe toward workpiece, stop on contact, signal error if failure
* G38.3 - Probe toward workpiece, stop on contact
*
* Like G28 except uses Z min probe for all axes
* With G38_PROBE_AWAY:
*
* G38.4 - Probe away from workpiece, stop on contact break, signal error if failure
* G38.5 - Probe away from workpiece, stop on contact break
*/
void GcodeSuite::G38(const bool is_38_2) {
void GcodeSuite::G38(const int8_t subcode) {
// Get X Y Z E F
get_destination_from_command();

setup_for_endstop_or_probe_move();

const bool error_on_fail =
#if ENABLED(G38_PROBE_AWAY)
!TEST(subcode, 0)
#else
(subcode == 2)
#endif
;

// If any axis has enough movement, do the move
LOOP_XYZ(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() && is_38_2) SERIAL_ERROR_MSG("Failed to reach target");
if (!G38_run_probe() && error_on_fail) SERIAL_ERROR_MSG("Failed to reach target");
break;
}

Expand Down
17 changes: 10 additions & 7 deletions Marlin/src/module/endstops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,14 +672,17 @@ void Endstops::update() {
}while(0)

#if ENABLED(G38_PROBE_TARGET) && PIN_EXISTS(Z_MIN_PROBE) && !(CORE_IS_XY || CORE_IS_XZ)
#if ENABLED(G38_PROBE_AWAY)
#define _G38_OPEN_STATE (G38_move >= 4)
#else
#define _G38_OPEN_STATE LOW
#endif
// If G38 command is active check Z_MIN_PROBE for ALL movement
if (G38_move) {
if (TEST_ENDSTOP(_ENDSTOP(Z, MIN_PROBE))) {
if (stepper.axis_is_moving(X_AXIS)) { _ENDSTOP_HIT(X, MIN); planner.endstop_triggered(X_AXIS); }
else if (stepper.axis_is_moving(Y_AXIS)) { _ENDSTOP_HIT(Y, MIN); planner.endstop_triggered(Y_AXIS); }
else if (stepper.axis_is_moving(Z_AXIS)) { _ENDSTOP_HIT(Z, MIN); planner.endstop_triggered(Z_AXIS); }
G38_endstop_hit = true;
}
if (G38_move && TEST_ENDSTOP(_ENDSTOP(Z, MIN_PROBE)) != _G38_OPEN_STATE) {
if (stepper.axis_is_moving(X_AXIS)) { _ENDSTOP_HIT(X, MIN); planner.endstop_triggered(X_AXIS); }
else if (stepper.axis_is_moving(Y_AXIS)) { _ENDSTOP_HIT(Y, MIN); planner.endstop_triggered(Y_AXIS); }
else if (stepper.axis_is_moving(Z_AXIS)) { _ENDSTOP_HIT(Z, MIN); planner.endstop_triggered(Z_AXIS); }
G38_did_trigger = true;
}
#endif

Expand Down
12 changes: 9 additions & 3 deletions config/default/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1068,11 +1068,17 @@
// Support for G5 with XYZE destination and IJPQ offsets. Requires ~2666 bytes.
//#define BEZIER_CURVE_SUPPORT

// G38.2 and G38.3 Probe Target
// Set MULTIPLE_PROBING if you want G38 to double touch
/**
* G38 Probe Target
*
* This option adds G38.2 and G38.3 (probe towards target)
* and optionally G38.4 and G38.5 (probe away from target).
* Set MULTIPLE_PROBING for G38 to probe more than once.
*/
//#define G38_PROBE_TARGET
#if ENABLED(G38_PROBE_TARGET)
#define G38_MINIMUM_MOVE 0.0275 // minimum distance in mm that will produce a move (determined using the print statement in check_move)
//#define G38_PROBE_AWAY // Include G38.4 and G38.5 to probe away from target
#define G38_MINIMUM_MOVE 0.0275 // (mm) Minimum distance that will produce a move.
#endif

// Moves (or segments) with fewer steps than this will be joined with the next move
Expand Down
12 changes: 9 additions & 3 deletions config/examples/3DFabXYZ/Migbot/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1068,11 +1068,17 @@
// Support for G5 with XYZE destination and IJPQ offsets. Requires ~2666 bytes.
//#define BEZIER_CURVE_SUPPORT

// G38.2 and G38.3 Probe Target
// Set MULTIPLE_PROBING if you want G38 to double touch
/**
* G38 Probe Target
*
* This option adds G38.2 and G38.3 (probe towards target)
* and optionally G38.4 and G38.5 (probe away from target).
* Set MULTIPLE_PROBING for G38 to probe more than once.
*/
//#define G38_PROBE_TARGET
#if ENABLED(G38_PROBE_TARGET)
#define G38_MINIMUM_MOVE 0.0275 // minimum distance in mm that will produce a move (determined using the print statement in check_move)
//#define G38_PROBE_AWAY // Include G38.4 and G38.5 to probe away from target
#define G38_MINIMUM_MOVE 0.0275 // (mm) Minimum distance that will produce a move.
#endif

// Moves (or segments) with fewer steps than this will be joined with the next move
Expand Down
12 changes: 9 additions & 3 deletions config/examples/AlephObjects/TAZ4/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1068,11 +1068,17 @@
// Support for G5 with XYZE destination and IJPQ offsets. Requires ~2666 bytes.
//#define BEZIER_CURVE_SUPPORT

// G38.2 and G38.3 Probe Target
// Set MULTIPLE_PROBING if you want G38 to double touch
/**
* G38 Probe Target
*
* This option adds G38.2 and G38.3 (probe towards target)
* and optionally G38.4 and G38.5 (probe away from target).
* Set MULTIPLE_PROBING for G38 to probe more than once.
*/
//#define G38_PROBE_TARGET
#if ENABLED(G38_PROBE_TARGET)
#define G38_MINIMUM_MOVE 0.0275 // minimum distance in mm that will produce a move (determined using the print statement in check_move)
//#define G38_PROBE_AWAY // Include G38.4 and G38.5 to probe away from target
#define G38_MINIMUM_MOVE 0.0275 // (mm) Minimum distance that will produce a move.
#endif

// Moves (or segments) with fewer steps than this will be joined with the next move
Expand Down
12 changes: 9 additions & 3 deletions config/examples/AliExpress/UM2pExt/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1068,11 +1068,17 @@
// Support for G5 with XYZE destination and IJPQ offsets. Requires ~2666 bytes.
//#define BEZIER_CURVE_SUPPORT

// G38.2 and G38.3 Probe Target
// Set MULTIPLE_PROBING if you want G38 to double touch
/**
* G38 Probe Target
*
* This option adds G38.2 and G38.3 (probe towards target)
* and optionally G38.4 and G38.5 (probe away from target).
* Set MULTIPLE_PROBING for G38 to probe more than once.
*/
//#define G38_PROBE_TARGET
#if ENABLED(G38_PROBE_TARGET)
#define G38_MINIMUM_MOVE 0.0275 // minimum distance in mm that will produce a move (determined using the print statement in check_move)
//#define G38_PROBE_AWAY // Include G38.4 and G38.5 to probe away from target
#define G38_MINIMUM_MOVE 0.0275 // (mm) Minimum distance that will produce a move.
#endif

// Moves (or segments) with fewer steps than this will be joined with the next move
Expand Down
12 changes: 9 additions & 3 deletions config/examples/Anet/A2/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1068,11 +1068,17 @@
// Support for G5 with XYZE destination and IJPQ offsets. Requires ~2666 bytes.
//#define BEZIER_CURVE_SUPPORT

// G38.2 and G38.3 Probe Target
// Set MULTIPLE_PROBING if you want G38 to double touch
/**
* G38 Probe Target
*
* This option adds G38.2 and G38.3 (probe towards target)
* and optionally G38.4 and G38.5 (probe away from target).
* Set MULTIPLE_PROBING for G38 to probe more than once.
*/
//#define G38_PROBE_TARGET
#if ENABLED(G38_PROBE_TARGET)
#define G38_MINIMUM_MOVE 0.0275 // minimum distance in mm that will produce a move (determined using the print statement in check_move)
//#define G38_PROBE_AWAY // Include G38.4 and G38.5 to probe away from target
#define G38_MINIMUM_MOVE 0.0275 // (mm) Minimum distance that will produce a move.
#endif

// Moves (or segments) with fewer steps than this will be joined with the next move
Expand Down
12 changes: 9 additions & 3 deletions config/examples/Anet/A2plus/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1068,11 +1068,17 @@
// Support for G5 with XYZE destination and IJPQ offsets. Requires ~2666 bytes.
//#define BEZIER_CURVE_SUPPORT

// G38.2 and G38.3 Probe Target
// Set MULTIPLE_PROBING if you want G38 to double touch
/**
* G38 Probe Target
*
* This option adds G38.2 and G38.3 (probe towards target)
* and optionally G38.4 and G38.5 (probe away from target).
* Set MULTIPLE_PROBING for G38 to probe more than once.
*/
//#define G38_PROBE_TARGET
#if ENABLED(G38_PROBE_TARGET)
#define G38_MINIMUM_MOVE 0.0275 // minimum distance in mm that will produce a move (determined using the print statement in check_move)
//#define G38_PROBE_AWAY // Include G38.4 and G38.5 to probe away from target
#define G38_MINIMUM_MOVE 0.0275 // (mm) Minimum distance that will produce a move.
#endif

// Moves (or segments) with fewer steps than this will be joined with the next move
Expand Down
12 changes: 9 additions & 3 deletions config/examples/Anet/A6/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1067,11 +1067,17 @@
// Support for G5 with XYZE destination and IJPQ offsets. Requires ~2666 bytes.
//#define BEZIER_CURVE_SUPPORT

// G38.2 and G38.3 Probe Target
// Set MULTIPLE_PROBING if you want G38 to double touch
/**
* G38 Probe Target
*
* This option adds G38.2 and G38.3 (probe towards target)
* and optionally G38.4 and G38.5 (probe away from target).
* Set MULTIPLE_PROBING for G38 to probe more than once.
*/
//#define G38_PROBE_TARGET
#if ENABLED(G38_PROBE_TARGET)
#define G38_MINIMUM_MOVE 0.0275 // minimum distance in mm that will produce a move (determined using the print statement in check_move)
//#define G38_PROBE_AWAY // Include G38.4 and G38.5 to probe away from target
#define G38_MINIMUM_MOVE 0.0275 // (mm) Minimum distance that will produce a move.
#endif

// Moves (or segments) with fewer steps than this will be joined with the next move
Expand Down
12 changes: 9 additions & 3 deletions config/examples/Anet/A8/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1068,11 +1068,17 @@
// Support for G5 with XYZE destination and IJPQ offsets. Requires ~2666 bytes.
//#define BEZIER_CURVE_SUPPORT

// G38.2 and G38.3 Probe Target
// Set MULTIPLE_PROBING if you want G38 to double touch
/**
* G38 Probe Target
*
* This option adds G38.2 and G38.3 (probe towards target)
* and optionally G38.4 and G38.5 (probe away from target).
* Set MULTIPLE_PROBING for G38 to probe more than once.
*/
//#define G38_PROBE_TARGET
#if ENABLED(G38_PROBE_TARGET)
#define G38_MINIMUM_MOVE 0.0275 // minimum distance in mm that will produce a move (determined using the print statement in check_move)
//#define G38_PROBE_AWAY // Include G38.4 and G38.5 to probe away from target
#define G38_MINIMUM_MOVE 0.0275 // (mm) Minimum distance that will produce a move.
#endif

// Moves (or segments) with fewer steps than this will be joined with the next move
Expand Down
Loading

0 comments on commit b824a51

Please sign in to comment.