|
| 1 | +/** |
| 2 | + * Marlin 3D Printer Firmware |
| 3 | + * Copyright (c) 2022 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 <https://www.gnu.org/licenses/>. |
| 20 | + * |
| 21 | + */ |
| 22 | + |
| 23 | +#include "../../../inc/MarlinConfig.h" |
| 24 | + |
| 25 | +#if ENABLED(INPUT_SHAPING) |
| 26 | + |
| 27 | +#include "../../gcode.h" |
| 28 | +#include "../../../module/stepper.h" |
| 29 | + |
| 30 | +void GcodeSuite::M593_report(const bool forReplay/*=true*/) { |
| 31 | + report_heading_etc(forReplay, F("Input Shaping")); |
| 32 | + #if HAS_SHAPING_X |
| 33 | + SERIAL_ECHO_MSG("M593 X" |
| 34 | + " F", stepper.get_shaping_frequency(X_AXIS), |
| 35 | + " D", stepper.get_shaping_damping_ratio(X_AXIS) |
| 36 | + ); |
| 37 | + #endif |
| 38 | + #if HAS_SHAPING_Y |
| 39 | + SERIAL_ECHO_MSG("M593 Y" |
| 40 | + " F", stepper.get_shaping_frequency(Y_AXIS), |
| 41 | + " D", stepper.get_shaping_damping_ratio(Y_AXIS) |
| 42 | + ); |
| 43 | + #endif |
| 44 | +} |
| 45 | + |
| 46 | +/** |
| 47 | + * M593: Get or Set Input Shaping Parameters |
| 48 | + * D<factor> Set the zeta/damping factor. If axes (X, Y, etc.) are not specified, set for all axes. |
| 49 | + * F<frequency> Set the frequency. If axes (X, Y, etc.) are not specified, set for all axes. |
| 50 | + * T[map] Input Shaping type, 0:ZV, 1:EI, 2:2H EI (not implemented yet) |
| 51 | + * X<1> Set the given parameters only for the X axis. |
| 52 | + * Y<1> Set the given parameters only for the Y axis. |
| 53 | + */ |
| 54 | +void GcodeSuite::M593() { |
| 55 | + if (!parser.seen_any()) return M593_report(); |
| 56 | + |
| 57 | + const bool seen_X = TERN0(HAS_SHAPING_X, parser.seen_test('X')), |
| 58 | + seen_Y = TERN0(HAS_SHAPING_Y, parser.seen_test('Y')), |
| 59 | + for_X = seen_X || TERN0(HAS_SHAPING_X, (!seen_X && !seen_Y)), |
| 60 | + for_Y = seen_Y || TERN0(HAS_SHAPING_Y, (!seen_X && !seen_Y)); |
| 61 | + |
| 62 | + if (parser.seen('D')) { |
| 63 | + const float zeta = parser.value_float(); |
| 64 | + if (WITHIN(zeta, 0, 1)) { |
| 65 | + if (for_X) stepper.set_shaping_damping_ratio(X_AXIS, zeta); |
| 66 | + if (for_Y) stepper.set_shaping_damping_ratio(Y_AXIS, zeta); |
| 67 | + } |
| 68 | + else |
| 69 | + SERIAL_ECHO_MSG("?Zeta (D) value out of range (0-1)"); |
| 70 | + } |
| 71 | + |
| 72 | + if (parser.seen('F')) { |
| 73 | + const float freq = parser.value_float(); |
| 74 | + if (freq > 0) { |
| 75 | + if (for_X) stepper.set_shaping_frequency(X_AXIS, freq); |
| 76 | + if (for_Y) stepper.set_shaping_frequency(Y_AXIS, freq); |
| 77 | + } |
| 78 | + else |
| 79 | + SERIAL_ECHO_MSG("?Frequency (F) must be greater than 0"); |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | +#endif |
0 commit comments