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.

G35.cpp 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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 <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "../../inc/MarlinConfig.h"
  23. #if ENABLED(ASSISTED_TRAMMING)
  24. #include "../gcode.h"
  25. #include "../../module/planner.h"
  26. #include "../../module/probe.h"
  27. #include "../../feature/bedlevel/bedlevel.h"
  28. #define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE)
  29. #include "../../core/debug_out.h"
  30. constexpr xy_pos_t screws_tilt_adjust_pos[] = TRAMMING_POINT_XY;
  31. static PGMSTR(point_name_1, TRAMMING_POINT_NAME_1);
  32. static PGMSTR(point_name_2, TRAMMING_POINT_NAME_2);
  33. static PGMSTR(point_name_3, TRAMMING_POINT_NAME_3);
  34. #ifdef TRAMMING_POINT_NAME_4
  35. static PGMSTR(point_name_4, TRAMMING_POINT_NAME_4);
  36. #ifdef TRAMMING_POINT_NAME_5
  37. static PGMSTR(point_name_5, TRAMMING_POINT_NAME_5);
  38. #endif
  39. #endif
  40. static PGM_P const tramming_point_name[] PROGMEM = {
  41. point_name_1, point_name_2, point_name_3
  42. #ifdef TRAMMING_POINT_NAME_4
  43. , point_name_4
  44. #ifdef TRAMMING_POINT_NAME_5
  45. , point_name_5
  46. #endif
  47. #endif
  48. };
  49. #define G35_PROBE_COUNT COUNT(screws_tilt_adjust_pos)
  50. #if !WITHIN(TRAMMING_SCREW_THREAD, 30, 51) || TRAMMING_SCREW_THREAD % 10 > 1
  51. #error "TRAMMING_SCREW_THREAD must be equal to 30, 31, 40, 41, 50, or 51."
  52. #endif
  53. static_assert(G35_PROBE_COUNT > 2, "TRAMMING_POINT_XY requires at least 3 XY positions.");
  54. /**
  55. * G35: Read bed corners to help adjust bed screws
  56. *
  57. * S<screw_thread>
  58. *
  59. * Screw thread: 30 - Clockwise M3
  60. * 31 - Counter-Clockwise M3
  61. * 40 - Clockwise M4
  62. * 41 - Counter-Clockwise M4
  63. * 50 - Clockwise M5
  64. * 51 - Counter-Clockwise M5
  65. **/
  66. void GcodeSuite::G35() {
  67. if (DEBUGGING(LEVELING)) {
  68. DEBUG_ECHOLNPGM(">>> G35");
  69. log_machine_info();
  70. }
  71. float z_measured[G35_PROBE_COUNT] = { 0 };
  72. const uint8_t screw_thread = parser.byteval('S', TRAMMING_SCREW_THREAD);
  73. if (!WITHIN(screw_thread, 30, 51) || screw_thread % 10 > 1) {
  74. SERIAL_ECHOLNPGM("?(S)crew thread must be 30, 31, 40, 41, 50, or 51.");
  75. return;
  76. }
  77. // Wait for planner moves to finish!
  78. planner.synchronize();
  79. // Disable the leveling matrix before auto-aligning
  80. #if HAS_LEVELING
  81. TERN_(RESTORE_LEVELING_AFTER_G35, const bool leveling_was_active = planner.leveling_active);
  82. set_bed_leveling_enabled(false);
  83. #endif
  84. #if ENABLED(CNC_WORKSPACE_PLANES)
  85. workspace_plane = PLANE_XY;
  86. #endif
  87. // Always home with tool 0 active
  88. #if HAS_MULTI_HOTEND
  89. const uint8_t old_tool_index = active_extruder;
  90. tool_change(0, true);
  91. #endif
  92. #if HAS_DUPLICATION_MODE
  93. extruder_duplication_enabled = false;
  94. #endif
  95. // Home all before this procedure
  96. home_all_axes();
  97. bool err_break = false;
  98. // Probe all positions
  99. LOOP_L_N(i, G35_PROBE_COUNT) {
  100. // In BLTOUCH HS mode, the probe travels in a deployed state.
  101. // Users of G35 might have a badly misaligned bed, so raise Z by the
  102. // length of the deployed pin (BLTOUCH stroke < 7mm)
  103. current_position.z = (Z_CLEARANCE_BETWEEN_PROBES) + (7 * ENABLED(BLTOUCH_HS_MODE));
  104. const float z_probed_height = probe.probe_at_point(screws_tilt_adjust_pos[i], PROBE_PT_RAISE, 0, true);
  105. if (isnan(z_probed_height)) {
  106. SERIAL_ECHOLNPAIR("G35 failed at point ", int(i), " (", tramming_point_name[i], ")"
  107. " X", screws_tilt_adjust_pos[i].x,
  108. " Y", screws_tilt_adjust_pos[i].y);
  109. err_break = true;
  110. break;
  111. }
  112. if (DEBUGGING(LEVELING))
  113. DEBUG_ECHOLNPAIR("Probing point ", int(i), " (", tramming_point_name[i], ")"
  114. " X", screws_tilt_adjust_pos[i].x,
  115. " Y", screws_tilt_adjust_pos[i].y,
  116. " Z", z_probed_height);
  117. z_measured[i] = z_probed_height;
  118. }
  119. if (!err_break) {
  120. const float threads_factor[] = { 0.5, 0.7, 0.8 };
  121. // Calculate adjusts
  122. LOOP_S_L_N(i, 1, G35_PROBE_COUNT) {
  123. const float diff = z_measured[0] - z_measured[i],
  124. adjust = abs(diff) < 0.001f ? 0 : diff / threads_factor[(screw_thread - 30) / 10];
  125. const int full_turns = trunc(adjust);
  126. const float decimal_part = adjust - float(full_turns);
  127. const int minutes = trunc(decimal_part * 60.0f);
  128. SERIAL_ECHOPAIR("Turn ", tramming_point_name[i],
  129. " ", (screw_thread & 1) == (adjust > 0) ? "Counter-Clockwise" : "Clockwise",
  130. "by ", abs(full_turns), " turns");
  131. if (minutes) SERIAL_ECHOPAIR(" and ", abs(minutes), " minutes");
  132. SERIAL_EOL();
  133. }
  134. }
  135. else
  136. SERIAL_ECHOLNPGM("G35 aborted.");
  137. // Restore the active tool after homing
  138. #if HAS_MULTI_HOTEND
  139. tool_change(old_tool_index, DISABLED(PARKING_EXTRUDER)); // Fetch previous toolhead if not PARKING_EXTRUDER
  140. #endif
  141. #if BOTH(HAS_LEVELING, RESTORE_LEVELING_AFTER_G35)
  142. set_bed_leveling_enabled(leveling_was_active);
  143. #endif
  144. // Stow the probe, as the last call to probe.probe_at_point(...) left
  145. // the probe deployed if it was successful.
  146. probe.stow();
  147. // After this operation the Z position needs correction
  148. set_axis_not_trusted(Z_AXIS);
  149. // Home Z after the alignment procedure
  150. process_subcommands_now_P(PSTR("G28Z"));
  151. if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< G35");
  152. }
  153. #endif // ASSISTED_TRAMMING