diff options
Diffstat (limited to 'Marlin/src/gcode/probe')
-rw-r--r-- | Marlin/src/gcode/probe/G30.cpp | 66 | ||||
-rw-r--r-- | Marlin/src/gcode/probe/G31_G32.cpp | 40 | ||||
-rw-r--r-- | Marlin/src/gcode/probe/G38.cpp | 133 | ||||
-rw-r--r-- | Marlin/src/gcode/probe/M401_M402.cpp | 49 | ||||
-rw-r--r-- | Marlin/src/gcode/probe/M851.cpp | 97 | ||||
-rw-r--r-- | Marlin/src/gcode/probe/M951.cpp | 71 |
6 files changed, 456 insertions, 0 deletions
diff --git a/Marlin/src/gcode/probe/G30.cpp b/Marlin/src/gcode/probe/G30.cpp new file mode 100644 index 0000000..4347f55 --- /dev/null +++ b/Marlin/src/gcode/probe/G30.cpp @@ -0,0 +1,66 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * 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 <https://www.gnu.org/licenses/>. + * + */ + +#include "../../inc/MarlinConfig.h" + +#if HAS_BED_PROBE + +#include "../gcode.h" +#include "../../module/motion.h" +#include "../../module/probe.h" +#include "../../feature/bedlevel/bedlevel.h" + +/** + * G30: Do a single Z probe at the current XY + * + * Parameters: + * + * X Probe X position (default current X) + * Y Probe Y position (default current Y) + * E Engage the probe for each probe (default 1) + */ +void GcodeSuite::G30() { + + const xy_pos_t pos = { parser.linearval('X', current_position.x + probe.offset_xy.x), + parser.linearval('Y', current_position.y + probe.offset_xy.y) }; + + if (!probe.can_reach(pos)) return; + + // Disable leveling so the planner won't mess with us + TERN_(HAS_LEVELING, set_bed_leveling_enabled(false)); + + remember_feedrate_scaling_off(); + + const ProbePtRaise raise_after = parser.boolval('E', true) ? PROBE_PT_STOW : PROBE_PT_NONE; + const float measured_z = probe.probe_at_point(pos, raise_after, 1); + if (!isnan(measured_z)) + SERIAL_ECHOLNPAIR("Bed X: ", pos.x, " Y: ", pos.y, " Z: ", measured_z); + + restore_feedrate_and_scaling(); + + if (raise_after == PROBE_PT_STOW) + probe.move_z_after_probing(); + + report_current_position(); +} + +#endif // HAS_BED_PROBE diff --git a/Marlin/src/gcode/probe/G31_G32.cpp b/Marlin/src/gcode/probe/G31_G32.cpp new file mode 100644 index 0000000..af44257 --- /dev/null +++ b/Marlin/src/gcode/probe/G31_G32.cpp @@ -0,0 +1,40 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * 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 <https://www.gnu.org/licenses/>. + * + */ + +#include "../../inc/MarlinConfig.h" + +#if ENABLED(Z_PROBE_SLED) + +#include "../gcode.h" +#include "../../module/probe.h" + +/** + * G31: Deploy the Z probe + */ +void GcodeSuite::G31() { probe.deploy(); } + +/** + * G32: Stow the Z probe + */ +void GcodeSuite::G32() { probe.stow(); } + +#endif // Z_PROBE_SLED diff --git a/Marlin/src/gcode/probe/G38.cpp b/Marlin/src/gcode/probe/G38.cpp new file mode 100644 index 0000000..b06cd47 --- /dev/null +++ b/Marlin/src/gcode/probe/G38.cpp @@ -0,0 +1,133 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * 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 <https://www.gnu.org/licenses/>. + * + */ + +#include "../../inc/MarlinConfig.h" + +#if ENABLED(G38_PROBE_TARGET) + +#include "../gcode.h" + +#include "../../module/endstops.h" +#include "../../module/motion.h" +#include "../../module/stepper.h" +#include "../../module/probe.h" + +inline void G38_single_probe(const uint8_t move_value) { + endstops.enable(true); + G38_move = move_value; + prepare_line_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; + + #if MULTIPLE_PROBING > 1 + // Get direction of move and retract + 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 + + // Move flag value + #if ENABLED(G38_PROBE_AWAY) + const uint8_t move_value = parser.subcode; + #else + constexpr uint8_t move_value = 1; + #endif + + G38_did_trigger = false; + + // Move until destination reached or target hit + G38_single_probe(move_value); + + if (G38_did_trigger) { + + 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; + + G38_single_probe(move_value); + #endif + } + + endstops.not_homing(); + return G38_pass_fail; +} + +/** + * G38 Probe Target + * + * G38.2 - Probe toward workpiece, stop on contact, signal error if failure + * G38.3 - Probe toward workpiece, stop on contact + * + * 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 int8_t subcode) { + // Get X Y Z E F + get_destination_from_command(); + + remember_feedrate_scaling_off(); + + 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() && error_on_fail) SERIAL_ERROR_MSG("Failed to reach target"); + break; + } + + restore_feedrate_and_scaling(); +} + +#endif // G38_PROBE_TARGET diff --git a/Marlin/src/gcode/probe/M401_M402.cpp b/Marlin/src/gcode/probe/M401_M402.cpp new file mode 100644 index 0000000..bd9bb44 --- /dev/null +++ b/Marlin/src/gcode/probe/M401_M402.cpp @@ -0,0 +1,49 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * 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 <https://www.gnu.org/licenses/>. + * + */ + +#include "../../inc/MarlinConfig.h" + +#if HAS_BED_PROBE + +#include "../gcode.h" +#include "../../module/motion.h" +#include "../../module/probe.h" + +/** + * M401: Deploy and activate the Z probe + */ +void GcodeSuite::M401() { + probe.deploy(); + TERN_(PROBE_TARE, probe.tare()); + report_current_position(); +} + +/** + * M402: Deactivate and stow the Z probe + */ +void GcodeSuite::M402() { + probe.stow(); + probe.move_z_after_probing(); + report_current_position(); +} + +#endif // HAS_BED_PROBE diff --git a/Marlin/src/gcode/probe/M851.cpp b/Marlin/src/gcode/probe/M851.cpp new file mode 100644 index 0000000..04b293d --- /dev/null +++ b/Marlin/src/gcode/probe/M851.cpp @@ -0,0 +1,97 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * 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 <https://www.gnu.org/licenses/>. + * + */ + +#include "../../inc/MarlinConfig.h" + +#if HAS_BED_PROBE + +#include "../gcode.h" +#include "../../feature/bedlevel/bedlevel.h" +#include "../../module/probe.h" + +/** + * M851: Set the nozzle-to-probe offsets in current units + */ +void GcodeSuite::M851() { + + // Show usage with no parameters + if (!parser.seen("XYZ")) { + SERIAL_ECHOLNPAIR_P( + #if HAS_PROBE_XY_OFFSET + PSTR(STR_PROBE_OFFSET " X"), probe.offset_xy.x, SP_Y_STR, probe.offset_xy.y, SP_Z_STR + #else + PSTR(STR_PROBE_OFFSET " X0 Y0 Z") + #endif + , probe.offset.z + ); + return; + } + + // Start with current offsets and modify + xyz_pos_t offs = probe.offset; + + // Assume no errors + bool ok = true; + + if (parser.seenval('X')) { + const float x = parser.value_float(); + #if HAS_PROBE_XY_OFFSET + if (WITHIN(x, -(X_BED_SIZE), X_BED_SIZE)) + offs.x = x; + else { + SERIAL_ECHOLNPAIR("?X out of range (-", int(X_BED_SIZE), " to ", int(X_BED_SIZE), ")"); + ok = false; + } + #else + if (x) SERIAL_ECHOLNPAIR("?X must be 0 (NOZZLE_AS_PROBE)."); // ...but let 'ok' stay true + #endif + } + + if (parser.seenval('Y')) { + const float y = parser.value_float(); + #if HAS_PROBE_XY_OFFSET + if (WITHIN(y, -(Y_BED_SIZE), Y_BED_SIZE)) + offs.y = y; + else { + SERIAL_ECHOLNPAIR("?Y out of range (-", int(Y_BED_SIZE), " to ", int(Y_BED_SIZE), ")"); + ok = false; + } + #else + if (y) SERIAL_ECHOLNPAIR("?Y must be 0 (NOZZLE_AS_PROBE)."); // ...but let 'ok' stay true + #endif + } + + if (parser.seenval('Z')) { + const float z = parser.value_float(); + if (WITHIN(z, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) + offs.z = z; + else { + SERIAL_ECHOLNPAIR("?Z out of range (", int(Z_PROBE_OFFSET_RANGE_MIN), " to ", int(Z_PROBE_OFFSET_RANGE_MAX), ")"); + ok = false; + } + } + + // Save the new offsets + if (ok) probe.offset = offs; +} + +#endif // HAS_BED_PROBE diff --git a/Marlin/src/gcode/probe/M951.cpp b/Marlin/src/gcode/probe/M951.cpp new file mode 100644 index 0000000..f461fc2 --- /dev/null +++ b/Marlin/src/gcode/probe/M951.cpp @@ -0,0 +1,71 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * 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 <https://www.gnu.org/licenses/>. + * + */ + +#include "../../inc/MarlinConfigPre.h" + +#if ENABLED(MAGNETIC_PARKING_EXTRUDER) + +#include "../gcode.h" +#include "../../module/tool_change.h" +#include "../../module/motion.h" + +mpe_settings_t mpe_settings; + +inline void mpe_settings_report() { + SERIAL_ECHO_MSG("Magnetic Parking Extruder"); + SERIAL_ECHO_START(); SERIAL_ECHOLNPAIR("L: Left parking :", mpe_settings.parking_xpos[0]); + SERIAL_ECHO_START(); SERIAL_ECHOLNPAIR("R: Right parking :", mpe_settings.parking_xpos[1]); + SERIAL_ECHO_START(); SERIAL_ECHOLNPAIR("I: Grab Offset :", mpe_settings.grab_distance); + SERIAL_ECHO_START(); SERIAL_ECHOLNPAIR("J: Normal speed :", long(MMS_TO_MMM(mpe_settings.slow_feedrate))); + SERIAL_ECHO_START(); SERIAL_ECHOLNPAIR("H: High speed :", long(MMS_TO_MMM(mpe_settings.fast_feedrate))); + SERIAL_ECHO_START(); SERIAL_ECHOLNPAIR("D: Distance trav.:", mpe_settings.travel_distance); + SERIAL_ECHO_START(); SERIAL_ECHOLNPAIR("C: Compenstion :", mpe_settings.compensation_factor); +} + +void mpe_settings_init() { + constexpr float pex[2] = PARKING_EXTRUDER_PARKING_X; + mpe_settings.parking_xpos[0] = pex[0]; // M951 L + mpe_settings.parking_xpos[1] = pex[1]; // M951 R + mpe_settings.grab_distance = PARKING_EXTRUDER_GRAB_DISTANCE; // M951 I + TERN_(HAS_HOME_OFFSET, set_home_offset(X_AXIS, mpe_settings.grab_distance * -1)); + mpe_settings.slow_feedrate = MMM_TO_MMS(MPE_SLOW_SPEED); // M951 J + mpe_settings.fast_feedrate = MMM_TO_MMS(MPE_FAST_SPEED); // M951 H + mpe_settings.travel_distance = MPE_TRAVEL_DISTANCE; // M951 D + mpe_settings.compensation_factor = MPE_COMPENSATION; // M951 C + mpe_settings_report(); +} + +void GcodeSuite::M951() { + if (parser.seenval('L')) mpe_settings.parking_xpos[0] = parser.value_linear_units(); + if (parser.seenval('R')) mpe_settings.parking_xpos[1] = parser.value_linear_units(); + if (parser.seenval('I')) { + mpe_settings.grab_distance = parser.value_linear_units(); + TERN_(HAS_HOME_OFFSET, set_home_offset(X_AXIS, mpe_settings.grab_distance * -1)); + } + if (parser.seenval('J')) mpe_settings.slow_feedrate = MMM_TO_MMS(parser.value_linear_units()); + if (parser.seenval('H')) mpe_settings.fast_feedrate = MMM_TO_MMS(parser.value_linear_units()); + if (parser.seenval('D')) mpe_settings.travel_distance = parser.value_linear_units(); + if (parser.seenval('C')) mpe_settings.compensation_factor = parser.value_float(); + if (!parser.seen("CDHIJLR")) mpe_settings_report(); +} + +#endif // MAGNETIC_PARKING_EXTRUDER |