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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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(ASSISTED_TRAMMING)
  24. #include "../gcode.h"
  25. #include "../../module/planner.h"
  26. #include "../../module/probe.h"
  27. #include "../../feature/bedlevel/bedlevel.h"
  28. #if HAS_MULTI_HOTEND
  29. #include "../../module/tool_change.h"
  30. #endif
  31. #if ENABLED(BLTOUCH)
  32. #include "../../feature/bltouch.h"
  33. #endif
  34. #define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE)
  35. #include "../../core/debug_out.h"
  36. //
  37. // Define tramming point names.
  38. //
  39. #include "../../feature/tramming.h"
  40. /**
  41. * G35: Read bed corners to help adjust bed screws
  42. *
  43. * S<screw_thread>
  44. *
  45. * Screw thread: 30 - Clockwise M3
  46. * 31 - Counter-Clockwise M3
  47. * 40 - Clockwise M4
  48. * 41 - Counter-Clockwise M4
  49. * 50 - Clockwise M5
  50. * 51 - Counter-Clockwise M5
  51. **/
  52. void GcodeSuite::G35() {
  53. DEBUG_SECTION(log_G35, "G35", DEBUGGING(LEVELING));
  54. if (DEBUGGING(LEVELING)) log_machine_info();
  55. float z_measured[G35_PROBE_COUNT] = { 0 };
  56. const uint8_t screw_thread = parser.byteval('S', TRAMMING_SCREW_THREAD);
  57. if (!WITHIN(screw_thread, 30, 51) || screw_thread % 10 > 1) {
  58. SERIAL_ECHOLNPGM("?(S)crew thread must be 30, 31, 40, 41, 50, or 51.");
  59. return;
  60. }
  61. // Wait for planner moves to finish!
  62. planner.synchronize();
  63. // Disable the leveling matrix before auto-aligning
  64. #if HAS_LEVELING
  65. #if ENABLED(RESTORE_LEVELING_AFTER_G35)
  66. const bool leveling_was_active = planner.leveling_active;
  67. #endif
  68. set_bed_leveling_enabled(false);
  69. #endif
  70. #if ENABLED(CNC_WORKSPACE_PLANES)
  71. workspace_plane = PLANE_XY;
  72. #endif
  73. // Always home with tool 0 active
  74. #if HAS_MULTI_HOTEND
  75. const uint8_t old_tool_index = active_extruder;
  76. tool_change(0, true);
  77. #endif
  78. // Disable duplication mode on homing
  79. TERN_(HAS_DUPLICATION_MODE, set_duplication_enabled(false));
  80. // Home only Z axis when X and Y is trusted, otherwise all axes, if needed before this procedure
  81. if (!all_axes_trusted()) process_subcommands_now(F("G28Z"));
  82. bool err_break = false;
  83. // Probe all positions
  84. LOOP_L_N(i, G35_PROBE_COUNT) {
  85. // In BLTOUCH HS mode, the probe travels in a deployed state.
  86. // Users of G35 might have a badly misaligned bed, so raise Z by the
  87. // length of the deployed pin (BLTOUCH stroke < 7mm)
  88. // Unsure if this is even required. The probe seems to lift correctly after probe done.
  89. do_blocking_move_to_z(SUM_TERN(BLTOUCH, Z_CLEARANCE_BETWEEN_PROBES, bltouch.z_extra_clearance()));
  90. const float z_probed_height = probe.probe_at_point(tramming_points[i], PROBE_PT_RAISE, 0, true);
  91. if (isnan(z_probed_height)) {
  92. SERIAL_ECHOPGM("G35 failed at point ", i + 1, " (");
  93. SERIAL_ECHOPGM_P((char *)pgm_read_ptr(&tramming_point_name[i]));
  94. SERIAL_CHAR(')');
  95. SERIAL_ECHOLNPGM_P(SP_X_STR, tramming_points[i].x, SP_Y_STR, tramming_points[i].y);
  96. err_break = true;
  97. break;
  98. }
  99. if (DEBUGGING(LEVELING)) {
  100. DEBUG_ECHOPGM("Probing point ", i + 1, " (");
  101. DEBUG_ECHOF(FPSTR(pgm_read_ptr(&tramming_point_name[i])));
  102. DEBUG_CHAR(')');
  103. DEBUG_ECHOLNPGM_P(SP_X_STR, tramming_points[i].x, SP_Y_STR, tramming_points[i].y, SP_Z_STR, z_probed_height);
  104. }
  105. z_measured[i] = z_probed_height;
  106. }
  107. if (!err_break) {
  108. const float threads_factor[] = { 0.5, 0.7, 0.8 };
  109. // Calculate adjusts
  110. LOOP_S_L_N(i, 1, G35_PROBE_COUNT) {
  111. const float diff = z_measured[0] - z_measured[i],
  112. adjust = ABS(diff) < 0.001f ? 0 : diff / threads_factor[(screw_thread - 30) / 10];
  113. const int full_turns = trunc(adjust);
  114. const float decimal_part = adjust - float(full_turns);
  115. const int minutes = trunc(decimal_part * 60.0f);
  116. SERIAL_ECHOPGM("Turn ");
  117. SERIAL_ECHOPGM_P((char *)pgm_read_ptr(&tramming_point_name[i]));
  118. SERIAL_ECHOPGM(" ", (screw_thread & 1) == (adjust > 0) ? "CCW" : "CW", " by ", ABS(full_turns), " turns");
  119. if (minutes) SERIAL_ECHOPGM(" and ", ABS(minutes), " minutes");
  120. if (ENABLED(REPORT_TRAMMING_MM)) SERIAL_ECHOPGM(" (", -diff, "mm)");
  121. SERIAL_EOL();
  122. }
  123. }
  124. else
  125. SERIAL_ECHOLNPGM("G35 aborted.");
  126. // Restore the active tool after homing
  127. #if HAS_MULTI_HOTEND
  128. tool_change(old_tool_index, DISABLED(PARKING_EXTRUDER)); // Fetch previous toolhead if not PARKING_EXTRUDER
  129. #endif
  130. #if BOTH(HAS_LEVELING, RESTORE_LEVELING_AFTER_G35)
  131. set_bed_leveling_enabled(leveling_was_active);
  132. #endif
  133. // Stow the probe, as the last call to probe.probe_at_point(...) left
  134. // the probe deployed if it was successful.
  135. probe.stow();
  136. move_to_tramming_wait_pos();
  137. // After this operation the Z position needs correction
  138. set_axis_never_homed(Z_AXIS);
  139. }
  140. #endif // ASSISTED_TRAMMING