My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

M423.cpp 2.9KB

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