My Marlin configs for Fabrikator Mini and CTC i3 Pro B
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

G35.cpp 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. #if ENABLED(RESTORE_LEVELING_AFTER_G35)
  63. const bool leveling_was_active = planner.leveling_active;
  64. #endif
  65. set_bed_leveling_enabled(false);
  66. #endif
  67. #if ENABLED(CNC_WORKSPACE_PLANES)
  68. workspace_plane = PLANE_XY;
  69. #endif
  70. // Always home with tool 0 active
  71. #if HAS_MULTI_HOTEND
  72. const uint8_t old_tool_index = active_extruder;
  73. tool_change(0, true);
  74. #endif
  75. // Disable duplication mode on homing
  76. TERN_(HAS_DUPLICATION_MODE, set_duplication_enabled(false));
  77. // Home only Z axis when X and Y is trusted, otherwise all axes, if needed before this procedure
  78. if (!all_axes_trusted()) process_subcommands_now(F("G28Z"));
  79. bool err_break = false;
  80. // Probe all positions
  81. LOOP_L_N(i, G35_PROBE_COUNT) {
  82. // In BLTOUCH HS mode, the probe travels in a deployed state.
  83. // Users of G35 might have a badly misaligned bed, so raise Z by the
  84. // length of the deployed pin (BLTOUCH stroke < 7mm)
  85. do_blocking_move_to_z(SUM_TERN(BLTOUCH_HS_MODE, Z_CLEARANCE_BETWEEN_PROBES, 7));
  86. const float z_probed_height = probe.probe_at_point(tramming_points[i], PROBE_PT_RAISE, 0, true);
  87. if (isnan(z_probed_height)) {
  88. SERIAL_ECHOPGM("G35 failed at point ", i + 1, " (");
  89. SERIAL_ECHOPGM_P((char *)pgm_read_ptr(&tramming_point_name[i]));
  90. SERIAL_CHAR(')');
  91. SERIAL_ECHOLNPGM_P(SP_X_STR, tramming_points[i].x, SP_Y_STR, tramming_points[i].y);
  92. err_break = true;
  93. break;
  94. }
  95. if (DEBUGGING(LEVELING)) {
  96. DEBUG_ECHOPGM("Probing point ", i + 1, " (");
  97. DEBUG_ECHOF(FPSTR(pgm_read_ptr(&tramming_point_name[i])));
  98. DEBUG_CHAR(')');
  99. DEBUG_ECHOLNPGM_P(SP_X_STR, tramming_points[i].x, SP_Y_STR, tramming_points[i].y, SP_Z_STR, z_probed_height);
  100. }
  101. z_measured[i] = z_probed_height;
  102. }
  103. if (!err_break) {
  104. const float threads_factor[] = { 0.5, 0.7, 0.8 };
  105. // Calculate adjusts
  106. LOOP_S_L_N(i, 1, G35_PROBE_COUNT) {
  107. const float diff = z_measured[0] - z_measured[i],
  108. adjust = ABS(diff) < 0.001f ? 0 : diff / threads_factor[(screw_thread - 30) / 10];
  109. const int full_turns = trunc(adjust);
  110. const float decimal_part = adjust - float(full_turns);
  111. const int minutes = trunc(decimal_part * 60.0f);
  112. SERIAL_ECHOPGM("Turn ");
  113. SERIAL_ECHOPGM_P((char *)pgm_read_ptr(&tramming_point_name[i]));
  114. SERIAL_ECHOPGM(" ", (screw_thread & 1) == (adjust > 0) ? "CCW" : "CW", " by ", ABS(full_turns), " turns");
  115. if (minutes) SERIAL_ECHOPGM(" and ", ABS(minutes), " minutes");
  116. if (ENABLED(REPORT_TRAMMING_MM)) SERIAL_ECHOPGM(" (", -diff, "mm)");
  117. SERIAL_EOL();
  118. }
  119. }
  120. else
  121. SERIAL_ECHOLNPGM("G35 aborted.");
  122. // Restore the active tool after homing
  123. #if HAS_MULTI_HOTEND
  124. tool_change(old_tool_index, DISABLED(PARKING_EXTRUDER)); // Fetch previous toolhead if not PARKING_EXTRUDER
  125. #endif
  126. #if BOTH(HAS_LEVELING, RESTORE_LEVELING_AFTER_G35)
  127. set_bed_leveling_enabled(leveling_was_active);
  128. #endif
  129. // Stow the probe, as the last call to probe.probe_at_point(...) left
  130. // the probe deployed if it was successful.
  131. probe.stow();
  132. move_to_tramming_wait_pos();
  133. // After this operation the Z position needs correction
  134. set_axis_never_homed(Z_AXIS);
  135. }
  136. #endif // ASSISTED_TRAMMING