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.

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