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.

M425.cpp 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 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. #include "../../inc/MarlinConfig.h"
  23. #if ENABLED(BACKLASH_GCODE)
  24. #include "../../feature/backlash.h"
  25. #include "../../module/planner.h"
  26. #include "../gcode.h"
  27. /**
  28. * M425: Enable and tune backlash correction.
  29. *
  30. * F<fraction> Enable/disable/fade-out backlash correction (0.0 to 1.0)
  31. * S<smoothing_mm> Distance over which backlash correction is spread
  32. * X<distance_mm> Set the backlash distance on X (0 to disable)
  33. * Y<distance_mm> ... on Y
  34. * Z<distance_mm> ... on Z
  35. * X If a backlash measurement was done on X, copy that value
  36. * Y ... on Y
  37. * Z ... on Z
  38. *
  39. * Type M425 without any arguments to show active values.
  40. */
  41. void GcodeSuite::M425() {
  42. bool noArgs = true;
  43. auto axis_can_calibrate = [](const uint8_t a) {
  44. switch (a) {
  45. default: return false;
  46. LINEAR_AXIS_CODE(
  47. case X_AXIS: return AXIS_CAN_CALIBRATE(X),
  48. case Y_AXIS: return AXIS_CAN_CALIBRATE(Y),
  49. case Z_AXIS: return AXIS_CAN_CALIBRATE(Z),
  50. case I_AXIS: return AXIS_CAN_CALIBRATE(I),
  51. case J_AXIS: return AXIS_CAN_CALIBRATE(J),
  52. case K_AXIS: return AXIS_CAN_CALIBRATE(K),
  53. );
  54. }
  55. };
  56. LOOP_LINEAR_AXES(a) {
  57. if (axis_can_calibrate(a) && parser.seen(AXIS_CHAR(a))) {
  58. planner.synchronize();
  59. backlash.distance_mm[a] = parser.has_value() ? parser.value_linear_units() : backlash.get_measurement(AxisEnum(a));
  60. noArgs = false;
  61. }
  62. }
  63. if (parser.seen('F')) {
  64. planner.synchronize();
  65. backlash.set_correction(parser.value_float());
  66. noArgs = false;
  67. }
  68. #ifdef BACKLASH_SMOOTHING_MM
  69. if (parser.seen('S')) {
  70. planner.synchronize();
  71. backlash.smoothing_mm = parser.value_linear_units();
  72. noArgs = false;
  73. }
  74. #endif
  75. if (noArgs) {
  76. SERIAL_ECHOPGM("Backlash Correction ");
  77. if (!backlash.correction) SERIAL_ECHOPGM("in");
  78. SERIAL_ECHOLNPGM("active:");
  79. SERIAL_ECHOLNPGM(" Correction Amount/Fade-out: F", backlash.get_correction(), " (F1.0 = full, F0.0 = none)");
  80. SERIAL_ECHOPGM(" Backlash Distance (mm): ");
  81. LOOP_LINEAR_AXES(a) if (axis_can_calibrate(a)) {
  82. SERIAL_CHAR(' ', AXIS_CHAR(a));
  83. SERIAL_ECHO(backlash.distance_mm[a]);
  84. SERIAL_EOL();
  85. }
  86. #ifdef BACKLASH_SMOOTHING_MM
  87. SERIAL_ECHOLNPGM(" Smoothing (mm): S", backlash.smoothing_mm);
  88. #endif
  89. #if ENABLED(MEASURE_BACKLASH_WHEN_PROBING)
  90. SERIAL_ECHOPGM(" Average measured backlash (mm):");
  91. if (backlash.has_any_measurement()) {
  92. LOOP_LINEAR_AXES(a) if (axis_can_calibrate(a) && backlash.has_measurement(AxisEnum(a))) {
  93. SERIAL_CHAR(' ', AXIS_CHAR(a));
  94. SERIAL_ECHO(backlash.get_measurement(AxisEnum(a)));
  95. }
  96. }
  97. else
  98. SERIAL_ECHOPGM(" (Not yet measured)");
  99. SERIAL_EOL();
  100. #endif
  101. }
  102. }
  103. void GcodeSuite::M425_report(const bool forReplay/*=true*/) {
  104. report_heading_etc(forReplay, PSTR(STR_BACKLASH_COMPENSATION));
  105. SERIAL_ECHOLNPGM_P(
  106. PSTR(" M425 F"), backlash.get_correction()
  107. #ifdef BACKLASH_SMOOTHING_MM
  108. , PSTR(" S"), LINEAR_UNIT(backlash.smoothing_mm)
  109. #endif
  110. , LIST_N(DOUBLE(LINEAR_AXES),
  111. SP_X_STR, LINEAR_UNIT(backlash.distance_mm.x),
  112. SP_Y_STR, LINEAR_UNIT(backlash.distance_mm.y),
  113. SP_Z_STR, LINEAR_UNIT(backlash.distance_mm.z),
  114. SP_I_STR, LINEAR_UNIT(backlash.distance_mm.i),
  115. SP_J_STR, LINEAR_UNIT(backlash.distance_mm.j),
  116. SP_K_STR, LINEAR_UNIT(backlash.distance_mm.k)
  117. )
  118. );
  119. }
  120. #endif // BACKLASH_GCODE