My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. #include "../../inc/MarlinConfig.h"
  23. #if HAS_LEVELING
  24. #include "bedlevel.h"
  25. #include "../../module/planner.h"
  26. #if ENABLED(MESH_BED_LEVELING) || ENABLED(PROBE_MANUALLY)
  27. #include "../../module/motion.h"
  28. #endif
  29. #if ENABLED(PROBE_MANUALLY)
  30. bool g29_in_progress = false;
  31. #endif
  32. #if ENABLED(LCD_BED_LEVELING)
  33. #include "../../lcd/ultralcd.h"
  34. #endif
  35. #if ENABLED(G26_MESH_VALIDATION)
  36. bool g26_debug_flag; // = false
  37. #endif
  38. bool leveling_is_valid() {
  39. return
  40. #if ENABLED(MESH_BED_LEVELING)
  41. mbl.has_mesh()
  42. #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
  43. !!bilinear_grid_spacing[X_AXIS]
  44. #elif ENABLED(AUTO_BED_LEVELING_UBL)
  45. ubl.mesh_is_valid()
  46. #else // 3POINT, LINEAR
  47. true
  48. #endif
  49. ;
  50. }
  51. /**
  52. * Turn bed leveling on or off, fixing the current
  53. * position as-needed.
  54. *
  55. * Disable: Current position = physical position
  56. * Enable: Current position = "unleveled" physical position
  57. */
  58. void set_bed_leveling_enabled(const bool enable/*=true*/) {
  59. #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
  60. const bool can_change = (!enable || leveling_is_valid());
  61. #else
  62. constexpr bool can_change = true;
  63. #endif
  64. if (can_change && enable != planner.leveling_active) {
  65. planner.synchronize();
  66. #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
  67. // Force bilinear_z_offset to re-calculate next time
  68. const float reset[XYZ] = { -9999.999, -9999.999, 0 };
  69. (void)bilinear_z_offset(reset);
  70. #endif
  71. if (planner.leveling_active) { // leveling from on to off
  72. // change unleveled current_position to physical current_position without moving steppers.
  73. planner.apply_leveling(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS]);
  74. planner.leveling_active = false; // disable only AFTER calling apply_leveling
  75. }
  76. else { // leveling from off to on
  77. planner.leveling_active = true; // enable BEFORE calling unapply_leveling, otherwise ignored
  78. // change physical current_position to unleveled current_position without moving steppers.
  79. planner.unapply_leveling(current_position);
  80. }
  81. sync_plan_position();
  82. }
  83. }
  84. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  85. void set_z_fade_height(const float zfh, const bool do_report/*=true*/) {
  86. if (planner.z_fade_height == zfh) return;
  87. const bool leveling_was_active = planner.leveling_active;
  88. set_bed_leveling_enabled(false);
  89. planner.set_z_fade_height(zfh);
  90. if (leveling_was_active) {
  91. const float oldpos[] = { current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] };
  92. set_bed_leveling_enabled(true);
  93. if (do_report && memcmp(oldpos, current_position, sizeof(oldpos)))
  94. report_current_position();
  95. }
  96. }
  97. #endif // ENABLE_LEVELING_FADE_HEIGHT
  98. /**
  99. * Reset calibration results to zero.
  100. */
  101. void reset_bed_level() {
  102. #if ENABLED(DEBUG_LEVELING_FEATURE)
  103. if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("reset_bed_level");
  104. #endif
  105. set_bed_leveling_enabled(false);
  106. #if ENABLED(MESH_BED_LEVELING)
  107. mbl.reset();
  108. #elif ENABLED(AUTO_BED_LEVELING_UBL)
  109. ubl.reset();
  110. #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
  111. bilinear_start[X_AXIS] = bilinear_start[Y_AXIS] =
  112. bilinear_grid_spacing[X_AXIS] = bilinear_grid_spacing[Y_AXIS] = 0;
  113. for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
  114. for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
  115. z_values[x][y] = NAN;
  116. #elif ABL_PLANAR
  117. planner.bed_level_matrix.set_to_identity();
  118. #endif
  119. }
  120. #if ENABLED(AUTO_BED_LEVELING_BILINEAR) || ENABLED(MESH_BED_LEVELING)
  121. /**
  122. * Enable to produce output in JSON format suitable
  123. * for SCAD or JavaScript mesh visualizers.
  124. *
  125. * Visualize meshes in OpenSCAD using the included script.
  126. *
  127. * buildroot/shared/scripts/MarlinMesh.scad
  128. */
  129. //#define SCAD_MESH_OUTPUT
  130. /**
  131. * Print calibration results for plotting or manual frame adjustment.
  132. */
  133. void print_2d_array(const uint8_t sx, const uint8_t sy, const uint8_t precision, element_2d_fn fn) {
  134. #ifndef SCAD_MESH_OUTPUT
  135. for (uint8_t x = 0; x < sx; x++) {
  136. for (uint8_t i = 0; i < precision + 2 + (x < 10 ? 1 : 0); i++)
  137. SERIAL_PROTOCOLCHAR(' ');
  138. SERIAL_PROTOCOL(int(x));
  139. }
  140. SERIAL_EOL();
  141. #endif
  142. #ifdef SCAD_MESH_OUTPUT
  143. SERIAL_PROTOCOLLNPGM("measured_z = ["); // open 2D array
  144. #endif
  145. for (uint8_t y = 0; y < sy; y++) {
  146. #ifdef SCAD_MESH_OUTPUT
  147. SERIAL_PROTOCOLPGM(" ["); // open sub-array
  148. #else
  149. if (y < 10) SERIAL_PROTOCOLCHAR(' ');
  150. SERIAL_PROTOCOL(int(y));
  151. #endif
  152. for (uint8_t x = 0; x < sx; x++) {
  153. SERIAL_PROTOCOLCHAR(' ');
  154. const float offset = fn(x, y);
  155. if (!isnan(offset)) {
  156. if (offset >= 0) SERIAL_PROTOCOLCHAR('+');
  157. SERIAL_PROTOCOL_F(offset, int(precision));
  158. }
  159. else {
  160. #ifdef SCAD_MESH_OUTPUT
  161. for (uint8_t i = 3; i < precision + 3; i++)
  162. SERIAL_PROTOCOLCHAR(' ');
  163. SERIAL_PROTOCOLPGM("NAN");
  164. #else
  165. for (uint8_t i = 0; i < precision + 3; i++)
  166. SERIAL_PROTOCOLCHAR(i ? '=' : ' ');
  167. #endif
  168. }
  169. #ifdef SCAD_MESH_OUTPUT
  170. if (x < sx - 1) SERIAL_PROTOCOLCHAR(',');
  171. #endif
  172. }
  173. #ifdef SCAD_MESH_OUTPUT
  174. SERIAL_PROTOCOLCHAR(' ');
  175. SERIAL_PROTOCOLCHAR(']'); // close sub-array
  176. if (y < sy - 1) SERIAL_PROTOCOLCHAR(',');
  177. #endif
  178. SERIAL_EOL();
  179. }
  180. #ifdef SCAD_MESH_OUTPUT
  181. SERIAL_PROTOCOLPGM("];"); // close 2D array
  182. #endif
  183. SERIAL_EOL();
  184. }
  185. #endif // AUTO_BED_LEVELING_BILINEAR || MESH_BED_LEVELING
  186. #if ENABLED(MESH_BED_LEVELING) || ENABLED(PROBE_MANUALLY)
  187. void _manual_goto_xy(const float &rx, const float &ry) {
  188. #ifdef MANUAL_PROBE_START_Z
  189. #if MANUAL_PROBE_HEIGHT > 0
  190. do_blocking_move_to(rx, ry, MANUAL_PROBE_HEIGHT);
  191. do_blocking_move_to_z(MAX(0,MANUAL_PROBE_START_Z));
  192. #else
  193. do_blocking_move_to(rx, ry, MAX(0,MANUAL_PROBE_START_Z));
  194. #endif
  195. #elif MANUAL_PROBE_HEIGHT > 0
  196. const float prev_z = current_position[Z_AXIS];
  197. do_blocking_move_to(rx, ry, MANUAL_PROBE_HEIGHT);
  198. do_blocking_move_to_z(prev_z);
  199. #else
  200. do_blocking_move_to_xy(rx, ry);
  201. #endif
  202. current_position[X_AXIS] = rx;
  203. current_position[Y_AXIS] = ry;
  204. #if ENABLED(LCD_BED_LEVELING)
  205. lcd_wait_for_move = false;
  206. #endif
  207. }
  208. #endif
  209. #endif // HAS_LEVELING