|
| 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 | +/** |
| 24 | + * M423.cpp - X-Axis Twist Compensation |
| 25 | + */ |
| 26 | + |
| 27 | +#include "../../inc/MarlinConfig.h" |
| 28 | + |
| 29 | +#if ENABLED(X_AXIS_TWIST_COMPENSATION) |
| 30 | + |
| 31 | +#include "../gcode.h" |
| 32 | +#include "../../feature/x_twist.h" |
| 33 | +#include "../../module/probe.h" |
| 34 | + |
| 35 | +/** |
| 36 | + * M423: Set a Z offset for X-Twist (added to the mesh on future G29). |
| 37 | + * M423 [R] [A<startx>] [I<interval>] [X<index> Z<offset>] |
| 38 | + * |
| 39 | + * R - Reset the twist compensation data |
| 40 | + * A<linear> - Set the X twist starting X position |
| 41 | + * E<linear> - Set the X twist ending X position |
| 42 | + * I<linear> - Set the X twist X-spacing directly |
| 43 | + * X<index> - Index of a Z value in the list |
| 44 | + * Z<linear> - A Z value to set |
| 45 | + */ |
| 46 | +void GcodeSuite::M423() { |
| 47 | + |
| 48 | + bool do_report = true; |
| 49 | + float new_spacing = 0; |
| 50 | + |
| 51 | + if (parser.seen_test('R')) { |
| 52 | + do_report = false; |
| 53 | + xatc.reset(); |
| 54 | + } |
| 55 | + if (parser.seenval('A')) { |
| 56 | + do_report = false; |
| 57 | + xatc.start = parser.value_float(); |
| 58 | + new_spacing = (probe.max_x() - xatc.start) / (XATC_MAX_POINTS - 1); |
| 59 | + } |
| 60 | + if (parser.seenval('E')) { |
| 61 | + do_report = false; |
| 62 | + new_spacing = (parser.value_float() - xatc.start) / (XATC_MAX_POINTS - 1); |
| 63 | + } |
| 64 | + else if (parser.seenval('I')) { |
| 65 | + do_report = false; |
| 66 | + new_spacing = parser.value_float(); |
| 67 | + } |
| 68 | + |
| 69 | + if (new_spacing) xatc.spacing = new_spacing; |
| 70 | + |
| 71 | + if (parser.seenval('X')) { |
| 72 | + do_report = false; |
| 73 | + const int8_t x = parser.value_int(); |
| 74 | + if (!WITHIN(x, 0, XATC_MAX_POINTS - 1)) |
| 75 | + SERIAL_ECHOLNPGM("?(X) out of range (0..", XATC_MAX_POINTS - 1, ")."); |
| 76 | + else { |
| 77 | + if (parser.seenval('Z')) |
| 78 | + xatc.z_offset[x] = parser.value_linear_units(); |
| 79 | + else |
| 80 | + SERIAL_ECHOLNPGM("?(Z) required."); |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + if (do_report) M423_report(); |
| 85 | + |
| 86 | +} |
| 87 | + |
| 88 | +void GcodeSuite::M423_report(const bool forReplay/*=true*/) { |
| 89 | + report_heading(forReplay, F("X-Twist Correction")); |
| 90 | + SERIAL_ECHOLNPGM(" M423 A", xatc.start, " I", xatc.spacing); |
| 91 | + LOOP_L_N(x, XATC_MAX_POINTS) { |
| 92 | + const float z = xatc.z_offset[x]; |
| 93 | + SERIAL_ECHOPGM(" M423 X", x, " Z"); |
| 94 | + serial_offset(isnan(z) ? 0 : z); |
| 95 | + SERIAL_EOL(); |
| 96 | + } |
| 97 | +} |
| 98 | + |
| 99 | +#endif // X_AXIS_TWIST_COMPENSATION |
0 commit comments