My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

G29.cpp 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 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. /**
  23. * G29.cpp - Mesh Bed Leveling
  24. */
  25. #include "../../../inc/MarlinConfig.h"
  26. #if ENABLED(MESH_BED_LEVELING)
  27. #include "../../../feature/bedlevel/bedlevel.h"
  28. #include "../../gcode.h"
  29. #include "../../queue.h"
  30. #include "../../../libs/buzzer.h"
  31. #include "../../../lcd/ultralcd.h"
  32. #include "../../../module/motion.h"
  33. #include "../../../module/stepper.h"
  34. // Save 130 bytes with non-duplication of PSTR
  35. void echo_not_entered() { SERIAL_PROTOCOLLNPGM(" not entered."); }
  36. void mesh_probing_done() {
  37. mbl.has_mesh = true;
  38. gcode.home_all_axes();
  39. set_bed_leveling_enabled(true);
  40. #if ENABLED(MESH_G28_REST_ORIGIN)
  41. current_position[Z_AXIS] = Z_MIN_POS;
  42. set_destination_from_current();
  43. buffer_line_to_destination(homing_feedrate(Z_AXIS));
  44. stepper.synchronize();
  45. #endif
  46. }
  47. /**
  48. * G29: Mesh-based Z probe, probes a grid and produces a
  49. * mesh to compensate for variable bed height
  50. *
  51. * Parameters With MESH_BED_LEVELING:
  52. *
  53. * S0 Produce a mesh report
  54. * S1 Start probing mesh points
  55. * S2 Probe the next mesh point
  56. * S3 Xn Yn Zn.nn Manually modify a single point
  57. * S4 Zn.nn Set z offset. Positive away from bed, negative closer to bed.
  58. * S5 Reset and disable mesh
  59. *
  60. * The S0 report the points as below
  61. *
  62. * +----> X-axis 1-n
  63. * |
  64. * |
  65. * v Y-axis 1-n
  66. *
  67. */
  68. void GcodeSuite::G29() {
  69. static int mbl_probe_index = -1;
  70. #if HAS_SOFTWARE_ENDSTOPS
  71. static bool enable_soft_endstops;
  72. #endif
  73. const MeshLevelingState state = (MeshLevelingState)parser.byteval('S', (int8_t)MeshReport);
  74. if (!WITHIN(state, 0, 5)) {
  75. SERIAL_PROTOCOLLNPGM("S out of range (0-5).");
  76. return;
  77. }
  78. int8_t px, py;
  79. switch (state) {
  80. case MeshReport:
  81. if (leveling_is_valid()) {
  82. SERIAL_PROTOCOLLNPAIR("State: ", planner.leveling_active ? MSG_ON : MSG_OFF);
  83. mbl_mesh_report();
  84. }
  85. else
  86. SERIAL_PROTOCOLLNPGM("Mesh bed leveling has no data.");
  87. break;
  88. case MeshStart:
  89. mbl.reset();
  90. mbl_probe_index = 0;
  91. enqueue_and_echo_commands_P(PSTR("G28\nG29 S2"));
  92. break;
  93. case MeshNext:
  94. if (mbl_probe_index < 0) {
  95. SERIAL_PROTOCOLLNPGM("Start mesh probing with \"G29 S1\" first.");
  96. return;
  97. }
  98. // For each G29 S2...
  99. if (mbl_probe_index == 0) {
  100. #if HAS_SOFTWARE_ENDSTOPS
  101. // For the initial G29 S2 save software endstop state
  102. enable_soft_endstops = soft_endstops_enabled;
  103. #endif
  104. }
  105. else {
  106. // For G29 S2 after adjusting Z.
  107. mbl.set_zigzag_z(mbl_probe_index - 1, current_position[Z_AXIS]);
  108. #if HAS_SOFTWARE_ENDSTOPS
  109. soft_endstops_enabled = enable_soft_endstops;
  110. #endif
  111. }
  112. // If there's another point to sample, move there with optional lift.
  113. if (mbl_probe_index < GRID_MAX_POINTS) {
  114. mbl.zigzag(mbl_probe_index, px, py);
  115. _manual_goto_xy(mbl.index_to_xpos[px], mbl.index_to_ypos[py]);
  116. #if HAS_SOFTWARE_ENDSTOPS
  117. // Disable software endstops to allow manual adjustment
  118. // If G29 is not completed, they will not be re-enabled
  119. soft_endstops_enabled = false;
  120. #endif
  121. mbl_probe_index++;
  122. }
  123. else {
  124. // One last "return to the bed" (as originally coded) at completion
  125. current_position[Z_AXIS] = Z_MIN_POS + MANUAL_PROBE_HEIGHT;
  126. line_to_current_position();
  127. stepper.synchronize();
  128. // After recording the last point, activate home and activate
  129. mbl_probe_index = -1;
  130. SERIAL_PROTOCOLLNPGM("Mesh probing done.");
  131. BUZZ(100, 659);
  132. BUZZ(100, 698);
  133. mesh_probing_done();
  134. }
  135. break;
  136. case MeshSet:
  137. if (parser.seenval('X')) {
  138. px = parser.value_int() - 1;
  139. if (!WITHIN(px, 0, GRID_MAX_POINTS_X - 1)) {
  140. SERIAL_PROTOCOLLNPGM("X out of range (1-" STRINGIFY(GRID_MAX_POINTS_X) ").");
  141. return;
  142. }
  143. }
  144. else {
  145. SERIAL_CHAR('X'); echo_not_entered();
  146. return;
  147. }
  148. if (parser.seenval('Y')) {
  149. py = parser.value_int() - 1;
  150. if (!WITHIN(py, 0, GRID_MAX_POINTS_Y - 1)) {
  151. SERIAL_PROTOCOLLNPGM("Y out of range (1-" STRINGIFY(GRID_MAX_POINTS_Y) ").");
  152. return;
  153. }
  154. }
  155. else {
  156. SERIAL_CHAR('Y'); echo_not_entered();
  157. return;
  158. }
  159. if (parser.seenval('Z')) {
  160. mbl.z_values[px][py] = parser.value_linear_units();
  161. }
  162. else {
  163. SERIAL_CHAR('Z'); echo_not_entered();
  164. return;
  165. }
  166. break;
  167. case MeshSetZOffset:
  168. if (parser.seenval('Z')) {
  169. mbl.z_offset = parser.value_linear_units();
  170. }
  171. else {
  172. SERIAL_CHAR('Z'); echo_not_entered();
  173. return;
  174. }
  175. break;
  176. case MeshReset:
  177. reset_bed_level();
  178. break;
  179. } // switch(state)
  180. report_current_position();
  181. }
  182. #endif // MESH_BED_LEVELING