Marlin_Firmware/Marlin/src/gcode/probe/G38.cpp

134 lines
3.5 KiB
C++
Raw Normal View History

/**
* Marlin 3D Printer Firmware
2020-02-03 08:00:57 -06:00
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
2019-06-27 23:57:50 -05:00
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
2017-09-15 23:44:29 -05:00
#include "../../inc/MarlinConfig.h"
#if ENABLED(G38_PROBE_TARGET)
#include "../gcode.h"
2017-09-15 23:44:29 -05:00
#include "../../module/endstops.h"
#include "../../module/motion.h"
#include "../../module/stepper.h"
#include "../../module/probe.h"
2019-03-10 17:22:09 -05:00
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;
2017-12-07 16:33:51 -06:00
#if MULTIPLE_PROBING > 1
// Get direction of move and retract
2019-09-29 04:25:39 -05:00
xyz_float_t retract_mm;
LOOP_XYZ(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
2019-03-10 17:22:09 -05:00
// Move flag value
#if ENABLED(G38_PROBE_AWAY)
const uint8_t move_value = parser.subcode;
#else
constexpr uint8_t move_value = 1;
#endif
2019-03-10 17:22:09 -05:00
G38_did_trigger = false;
2019-03-10 17:22:09 -05:00
// Move until destination reached or target hit
G38_single_probe(move_value);
if (G38_did_trigger) {
G38_pass_fail = true;
2017-12-07 16:33:51 -06:00
#if MULTIPLE_PROBING > 1
// Move away by the retract distance
2019-09-29 04:25:39 -05:00
destination = current_position + retract_mm;
endstops.enable(false);
prepare_move_to_destination();
planner.synchronize();
2019-03-10 17:22:09 -05:00
REMEMBER(fr, feedrate_mm_s, feedrate_mm_s * 0.25);
// Bump the target more slowly
2019-09-29 04:25:39 -05:00
destination -= retract_mm * 2;
2019-03-10 17:22:09 -05:00
G38_single_probe(move_value);
#endif
}
endstops.not_homing();
return G38_pass_fail;
}
/**
2019-03-10 17:22:09 -05:00
* G38 Probe Target
*
* G38.2 - Probe toward workpiece, stop on contact, signal error if failure
* G38.3 - Probe toward workpiece, stop on contact
*
2019-03-10 17:22:09 -05:00
* 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
*/
2019-03-10 17:22:09 -05:00
void GcodeSuite::G38(const int8_t subcode) {
// Get X Y Z E F
2017-09-15 23:44:29 -05:00
get_destination_from_command();
remember_feedrate_scaling_off();
2019-03-10 17:22:09 -05:00
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
2019-03-10 17:22:09 -05:00
if (!G38_run_probe() && error_on_fail) SERIAL_ERROR_MSG("Failed to reach target");
break;
}
restore_feedrate_and_scaling();
}
2017-09-15 23:44:29 -05:00
#endif // G38_PROBE_TARGET