|
| 1 | +/** |
| 2 | + * Marlin 3D Printer Firmware |
| 3 | + * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] |
| 4 | + * |
| 5 | + * Based on Sprinter and grbl. |
| 6 | + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm |
| 7 | + * |
| 8 | + * This program is free software: you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU General Public License as published by |
| 10 | + * the Free Software Foundation, either version 3 of the License, or |
| 11 | + * (at your option) any later version. |
| 12 | + * |
| 13 | + * This program is distributed in the hope that it will be useful, |
| 14 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | + * GNU General Public License for more details. |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU General Public License |
| 19 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | + * |
| 21 | + */ |
| 22 | + |
| 23 | +#include "../../../inc/MarlinConfig.h" |
| 24 | + |
| 25 | +#if SAVED_POSITIONS |
| 26 | + |
| 27 | +#include "../../../core/language.h" |
| 28 | +#include "../../module/planner.h" |
| 29 | +#include "../../gcode.h" |
| 30 | +#include "../../../module/motion.h" |
| 31 | + |
| 32 | +/** |
| 33 | + * G61: Return to saved position |
| 34 | + * |
| 35 | + * F<rate> - Feedrate (optional) for the move back. |
| 36 | + * S<slot> - Slot # (0-based) to restore from (default 0). |
| 37 | + * X Y Z - Axes to restore. At least one is required. |
| 38 | + */ |
| 39 | +void GcodeSuite::G61(void) { |
| 40 | + |
| 41 | + const uint8_t slot = parser.byteval('S'); |
| 42 | + |
| 43 | + #if SAVED_POSITIONS < 256 |
| 44 | + if (slot >= SAVED_POSITIONS) { |
| 45 | + SERIAL_ERROR_MSG(MSG_INVALID_POS_SLOT STRINGIFY(SAVED_POSITIONS)); |
| 46 | + return; |
| 47 | + } |
| 48 | + #endif |
| 49 | + |
| 50 | + // No saved position? No axes being restored? |
| 51 | + if (!TEST(saved_slots, slot) || !parser.seen("XYZ")) return; |
| 52 | + |
| 53 | + // Apply any given feedrate over 0.0 |
| 54 | + const float fr = parser.linearval('F'); |
| 55 | + if (fr > 0.0) feedrate_mm_s = MMM_TO_MMS(fr); |
| 56 | + |
| 57 | + SERIAL_ECHOPAIR(MSG_RESTORING_POS " S", int(slot)); |
| 58 | + LOOP_XYZ(i) { |
| 59 | + destination[i] = parser.seen(axis_codes[i]) |
| 60 | + ? stored_position[slot][i] + parser.value_axis_units((AxisEnum)i) |
| 61 | + : current_position[i]; |
| 62 | + SERIAL_CHAR(' ', axis_codes[i]); |
| 63 | + SERIAL_ECHO_F(destination[i]); |
| 64 | + } |
| 65 | + SERIAL_EOL(); |
| 66 | + |
| 67 | + // Move to the saved position |
| 68 | + prepare_move_to_destination(); |
| 69 | +} |
| 70 | + |
| 71 | +#endif // SAVED_POSITIONS |
0 commit comments