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.

ubl.cpp 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 "Marlin.h"
  23. #include "math.h"
  24. #if ENABLED(AUTO_BED_LEVELING_UBL)
  25. #include "ubl.h"
  26. #include "hex_print_routines.h"
  27. #include "temperature.h"
  28. extern Planner planner;
  29. /**
  30. * These support functions allow the use of large bit arrays of flags that take very
  31. * little RAM. Currently they are limited to being 16x16 in size. Changing the declaration
  32. * to unsigned long will allow us to go to 32x32 if higher resolution Mesh's are needed
  33. * in the future.
  34. */
  35. void bit_clear(uint16_t bits[16], uint8_t x, uint8_t y) { CBI(bits[y], x); }
  36. void bit_set(uint16_t bits[16], uint8_t x, uint8_t y) { SBI(bits[y], x); }
  37. bool is_bit_set(uint16_t bits[16], uint8_t x, uint8_t y) { return TEST(bits[y], x); }
  38. uint8_t ubl_cnt = 0;
  39. void unified_bed_leveling::echo_name() { SERIAL_PROTOCOLPGM("Unified Bed Leveling"); }
  40. void unified_bed_leveling::report_state() {
  41. echo_name();
  42. SERIAL_PROTOCOLPGM(" System v" UBL_VERSION " ");
  43. if (!state.active) SERIAL_PROTOCOLPGM("in");
  44. SERIAL_PROTOCOLLNPGM("active.");
  45. safe_delay(50);
  46. }
  47. static void serial_echo_xy(const int16_t x, const int16_t y) {
  48. SERIAL_CHAR('(');
  49. SERIAL_ECHO(x);
  50. SERIAL_CHAR(',');
  51. SERIAL_ECHO(y);
  52. SERIAL_CHAR(')');
  53. safe_delay(10);
  54. }
  55. ubl_state unified_bed_leveling::state;
  56. float unified_bed_leveling::z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y],
  57. unified_bed_leveling::last_specified_z;
  58. // 15 is the maximum nubmer of grid points supported + 1 safety margin for now,
  59. // until determinism prevails
  60. constexpr float unified_bed_leveling::_mesh_index_to_xpos[16],
  61. unified_bed_leveling::_mesh_index_to_ypos[16];
  62. bool unified_bed_leveling::g26_debug_flag = false,
  63. unified_bed_leveling::has_control_of_lcd_panel = false;
  64. volatile int unified_bed_leveling::encoder_diff;
  65. unified_bed_leveling::unified_bed_leveling() {
  66. ubl_cnt++; // Debug counter to insure we only have one UBL object present in memory. We can eliminate this (and all references to ubl_cnt) very soon.
  67. reset();
  68. }
  69. void unified_bed_leveling::reset() {
  70. set_bed_leveling_enabled(false);
  71. state.z_offset = 0;
  72. state.storage_slot = -1;
  73. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  74. planner.z_fade_height = 10.0;
  75. #endif
  76. ZERO(z_values);
  77. last_specified_z = -999.9;
  78. }
  79. void unified_bed_leveling::invalidate() {
  80. set_bed_leveling_enabled(false);
  81. state.z_offset = 0;
  82. set_all_mesh_points_to_value(NAN);
  83. }
  84. void unified_bed_leveling::set_all_mesh_points_to_value(float value) {
  85. for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) {
  86. for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) {
  87. z_values[x][y] = value;
  88. }
  89. }
  90. }
  91. // display_map() currently produces three different mesh map types
  92. // 0 : suitable for PronterFace and Repetier's serial console
  93. // 1 : .CSV file suitable for importation into various spread sheets
  94. // 2 : disply of the map data on a RepRap Graphical LCD Panel
  95. void unified_bed_leveling::display_map(const int map_type) {
  96. constexpr uint8_t spaces = 8 * (GRID_MAX_POINTS_X - 2);
  97. SERIAL_PROTOCOLPGM("\nBed Topography Report");
  98. if (map_type == 0) {
  99. SERIAL_PROTOCOLPGM(":\n\n");
  100. serial_echo_xy(0, GRID_MAX_POINTS_Y - 1);
  101. SERIAL_ECHO_SP(spaces + 3);
  102. serial_echo_xy(GRID_MAX_POINTS_X - 1, GRID_MAX_POINTS_Y - 1);
  103. SERIAL_EOL();
  104. serial_echo_xy(UBL_MESH_MIN_X, UBL_MESH_MAX_Y);
  105. SERIAL_ECHO_SP(spaces);
  106. serial_echo_xy(UBL_MESH_MAX_X, UBL_MESH_MAX_Y);
  107. SERIAL_EOL();
  108. }
  109. else {
  110. SERIAL_PROTOCOLPGM(" for ");
  111. serialprintPGM(map_type == 1 ? PSTR("CSV:\n\n") : PSTR("LCD:\n\n"));
  112. }
  113. const float current_xi = get_cell_index_x(current_position[X_AXIS] + (MESH_X_DIST) / 2.0),
  114. current_yi = get_cell_index_y(current_position[Y_AXIS] + (MESH_Y_DIST) / 2.0);
  115. for (int8_t j = GRID_MAX_POINTS_Y - 1; j >= 0; j--) {
  116. for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
  117. const bool is_current = i == current_xi && j == current_yi;
  118. // is the nozzle here? then mark the number
  119. if (map_type == 0) SERIAL_CHAR(is_current ? '[' : ' ');
  120. const float f = z_values[i][j];
  121. if (isnan(f)) {
  122. serialprintPGM(map_type == 0 ? PSTR(" . ") : PSTR("NAN"));
  123. }
  124. else if (map_type <= 1) {
  125. // if we don't do this, the columns won't line up nicely
  126. if (map_type == 0 && f >= 0.0) SERIAL_CHAR(' ');
  127. SERIAL_PROTOCOL_F(f, 3);
  128. }
  129. idle();
  130. if (map_type == 1 && i < GRID_MAX_POINTS_X - 1) SERIAL_CHAR(',');
  131. #if TX_BUFFER_SIZE > 0
  132. MYSERIAL.flushTX();
  133. #endif
  134. safe_delay(15);
  135. if (map_type == 0) {
  136. SERIAL_CHAR(is_current ? ']' : ' ');
  137. SERIAL_CHAR(' ');
  138. }
  139. }
  140. SERIAL_EOL();
  141. if (j && map_type == 0) { // we want the (0,0) up tight against the block of numbers
  142. SERIAL_CHAR(' ');
  143. SERIAL_EOL();
  144. }
  145. }
  146. if (map_type == 0) {
  147. serial_echo_xy(UBL_MESH_MIN_X, UBL_MESH_MIN_Y);
  148. SERIAL_ECHO_SP(spaces + 4);
  149. serial_echo_xy(UBL_MESH_MAX_X, UBL_MESH_MIN_Y);
  150. SERIAL_EOL();
  151. serial_echo_xy(0, 0);
  152. SERIAL_ECHO_SP(spaces + 5);
  153. serial_echo_xy(GRID_MAX_POINTS_X - 1, 0);
  154. SERIAL_EOL();
  155. }
  156. }
  157. bool unified_bed_leveling::sanity_check() {
  158. uint8_t error_flag = 0;
  159. if (settings.calc_num_meshes() < 1) {
  160. SERIAL_PROTOCOLLNPGM("?Insufficient EEPROM storage for a mesh of this size.");
  161. error_flag++;
  162. }
  163. return !!error_flag;
  164. }
  165. #endif // AUTO_BED_LEVELING_UBL