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.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. NUM_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. case U_AXIS: return AXIS_CAN_CALIBRATE(U),
  54. case V_AXIS: return AXIS_CAN_CALIBRATE(V),
  55. case W_AXIS: return AXIS_CAN_CALIBRATE(W)
  56. );
  57. }
  58. };
  59. LOOP_NUM_AXES(a) {
  60. if (axis_can_calibrate(a) && parser.seen(AXIS_CHAR(a))) {
  61. planner.synchronize();
  62. backlash.set_distance_mm(AxisEnum(a), parser.has_value() ? parser.value_axis_units(AxisEnum(a)) : backlash.get_measurement(AxisEnum(a)));
  63. noArgs = false;
  64. }
  65. }
  66. if (parser.seen('F')) {
  67. planner.synchronize();
  68. backlash.set_correction(parser.value_float());
  69. noArgs = false;
  70. }
  71. #ifdef BACKLASH_SMOOTHING_MM
  72. if (parser.seen('S')) {
  73. planner.synchronize();
  74. backlash.set_smoothing_mm(parser.value_linear_units());
  75. noArgs = false;
  76. }
  77. #endif
  78. if (noArgs) {
  79. SERIAL_ECHOPGM("Backlash Correction ");
  80. if (!backlash.get_correction_uint8()) SERIAL_ECHOPGM("in");
  81. SERIAL_ECHOLNPGM("active:");
  82. SERIAL_ECHOLNPGM(" Correction Amount/Fade-out: F", backlash.get_correction(), " (F1.0 = full, F0.0 = none)");
  83. SERIAL_ECHOPGM(" Backlash Distance (mm): ");
  84. LOOP_NUM_AXES(a) if (axis_can_calibrate(a)) {
  85. SERIAL_CHAR(' ', AXIS_CHAR(a));
  86. SERIAL_ECHO(backlash.get_distance_mm(AxisEnum(a)));
  87. SERIAL_EOL();
  88. }
  89. #ifdef BACKLASH_SMOOTHING_MM
  90. SERIAL_ECHOLNPGM(" Smoothing (mm): S", backlash.get_smoothing_mm());
  91. #endif
  92. #if ENABLED(MEASURE_BACKLASH_WHEN_PROBING)
  93. SERIAL_ECHOPGM(" Average measured backlash (mm):");
  94. if (backlash.has_any_measurement()) {
  95. LOOP_NUM_AXES(a) if (axis_can_calibrate(a) && backlash.has_measurement(AxisEnum(a))) {
  96. SERIAL_CHAR(' ', AXIS_CHAR(a));
  97. SERIAL_ECHO(backlash.get_measurement(AxisEnum(a)));
  98. }
  99. }
  100. else
  101. SERIAL_ECHOPGM(" (Not yet measured)");
  102. SERIAL_EOL();
  103. #endif
  104. }
  105. }
  106. void GcodeSuite::M425_report(const bool forReplay/*=true*/) {
  107. report_heading_etc(forReplay, F(STR_BACKLASH_COMPENSATION));
  108. SERIAL_ECHOLNPGM_P(
  109. PSTR(" M425 F"), backlash.get_correction()
  110. #ifdef BACKLASH_SMOOTHING_MM
  111. , PSTR(" S"), LINEAR_UNIT(backlash.get_smoothing_mm())
  112. #endif
  113. , LIST_N(DOUBLE(NUM_AXES),
  114. SP_X_STR, LINEAR_UNIT(backlash.get_distance_mm(X_AXIS)),
  115. SP_Y_STR, LINEAR_UNIT(backlash.get_distance_mm(Y_AXIS)),
  116. SP_Z_STR, LINEAR_UNIT(backlash.get_distance_mm(Z_AXIS)),
  117. SP_I_STR, I_AXIS_UNIT(backlash.get_distance_mm(I_AXIS)),
  118. SP_J_STR, J_AXIS_UNIT(backlash.get_distance_mm(J_AXIS)),
  119. SP_K_STR, K_AXIS_UNIT(backlash.get_distance_mm(K_AXIS)),
  120. SP_U_STR, U_AXIS_UNIT(backlash.get_distance_mm(U_AXIS)),
  121. SP_V_STR, V_AXIS_UNIT(backlash.get_distance_mm(V_AXIS)),
  122. SP_W_STR, W_AXIS_UNIT(backlash.get_distance_mm(W_AXIS))
  123. )
  124. );
  125. }
  126. #endif // BACKLASH_GCODE