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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. /**
  29. * These support functions allow the use of large bit arrays of flags that take very
  30. * little RAM. Currently they are limited to being 16x16 in size. Changing the declaration
  31. * to unsigned long will allow us to go to 32x32 if higher resolution Mesh's are needed
  32. * in the future.
  33. */
  34. void bit_clear(uint16_t bits[16], uint8_t x, uint8_t y) { CBI(bits[y], x); }
  35. void bit_set(uint16_t bits[16], uint8_t x, uint8_t y) { SBI(bits[y], x); }
  36. bool is_bit_set(uint16_t bits[16], uint8_t x, uint8_t y) { return TEST(bits[y], x); }
  37. uint8_t ubl_cnt = 0;
  38. static void serial_echo_xy(const int16_t x, const int16_t y) {
  39. SERIAL_CHAR('(');
  40. SERIAL_ECHO(x);
  41. SERIAL_CHAR(',');
  42. SERIAL_ECHO(y);
  43. SERIAL_CHAR(')');
  44. safe_delay(10);
  45. }
  46. ubl_state unified_bed_leveling::state;
  47. float unified_bed_leveling::z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y],
  48. unified_bed_leveling::last_specified_z;
  49. // 15 is the maximum nubmer of grid points supported + 1 safety margin for now,
  50. // until determinism prevails
  51. constexpr float unified_bed_leveling::mesh_index_to_xpos[16],
  52. unified_bed_leveling::mesh_index_to_ypos[16];
  53. bool unified_bed_leveling::g26_debug_flag = false,
  54. unified_bed_leveling::has_control_of_lcd_panel = false;
  55. volatile int unified_bed_leveling::encoder_diff;
  56. unified_bed_leveling::unified_bed_leveling() {
  57. ubl_cnt++; // Debug counter to insure we only have one UBL object present in memory.
  58. reset();
  59. }
  60. void unified_bed_leveling::reset() {
  61. state.active = false;
  62. state.z_offset = 0;
  63. state.storage_slot = -1;
  64. ZERO(z_values);
  65. last_specified_z = -999.9;
  66. }
  67. void unified_bed_leveling::invalidate() {
  68. state.active = false;
  69. state.z_offset = 0;
  70. for (int x = 0; x < GRID_MAX_POINTS_X; x++)
  71. for (int y = 0; y < GRID_MAX_POINTS_Y; y++)
  72. z_values[x][y] = NAN;
  73. }
  74. void unified_bed_leveling::display_map(const int map_type) {
  75. const bool map0 = map_type == 0;
  76. constexpr uint8_t spaces = 9 * (GRID_MAX_POINTS_X - 2);
  77. if (map0) {
  78. SERIAL_PROTOCOLLNPGM("\nBed Topography Report:\n");
  79. serial_echo_xy(0, GRID_MAX_POINTS_Y - 1);
  80. SERIAL_ECHO_SP(spaces + 3);
  81. serial_echo_xy(GRID_MAX_POINTS_X - 1, GRID_MAX_POINTS_Y - 1);
  82. SERIAL_EOL;
  83. serial_echo_xy(UBL_MESH_MIN_X, UBL_MESH_MAX_Y);
  84. SERIAL_ECHO_SP(spaces);
  85. serial_echo_xy(UBL_MESH_MAX_X, UBL_MESH_MAX_Y);
  86. SERIAL_EOL;
  87. }
  88. const float current_xi = ubl.get_cell_index_x(current_position[X_AXIS] + (MESH_X_DIST) / 2.0),
  89. current_yi = ubl.get_cell_index_y(current_position[Y_AXIS] + (MESH_Y_DIST) / 2.0);
  90. for (int8_t j = GRID_MAX_POINTS_Y - 1; j >= 0; j--) {
  91. for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
  92. const bool is_current = i == current_xi && j == current_yi;
  93. // is the nozzle here? then mark the number
  94. if (map0) SERIAL_CHAR(is_current ? '[' : ' ');
  95. const float f = z_values[i][j];
  96. if (isnan(f)) {
  97. serialprintPGM(map0 ? PSTR(" . ") : PSTR("NAN"));
  98. }
  99. else {
  100. // if we don't do this, the columns won't line up nicely
  101. if (map0 && f >= 0.0) SERIAL_CHAR(' ');
  102. SERIAL_PROTOCOL_F(f, 3);
  103. idle();
  104. }
  105. if (!map0 && i < GRID_MAX_POINTS_X - 1) SERIAL_CHAR(',');
  106. #if TX_BUFFER_SIZE > 0
  107. MYSERIAL.flushTX();
  108. #endif
  109. safe_delay(15);
  110. if (map0) {
  111. SERIAL_CHAR(is_current ? ']' : ' ');
  112. SERIAL_CHAR(' ');
  113. }
  114. }
  115. SERIAL_EOL;
  116. if (j && map0) { // we want the (0,0) up tight against the block of numbers
  117. SERIAL_CHAR(' ');
  118. SERIAL_EOL;
  119. }
  120. }
  121. if (map0) {
  122. serial_echo_xy(UBL_MESH_MIN_X, UBL_MESH_MIN_Y);
  123. SERIAL_ECHO_SP(spaces + 4);
  124. serial_echo_xy(UBL_MESH_MAX_X, UBL_MESH_MIN_Y);
  125. SERIAL_EOL;
  126. serial_echo_xy(0, 0);
  127. SERIAL_ECHO_SP(spaces + 5);
  128. serial_echo_xy(GRID_MAX_POINTS_X - 1, 0);
  129. SERIAL_EOL;
  130. }
  131. }
  132. bool unified_bed_leveling::sanity_check() {
  133. uint8_t error_flag = 0;
  134. const int a = settings.calc_num_meshes();
  135. if (a < 1) {
  136. SERIAL_PROTOCOLLNPGM("?Insufficient EEPROM storage for a mesh of this size.");
  137. error_flag++;
  138. }
  139. return !!error_flag;
  140. }
  141. #endif // AUTO_BED_LEVELING_UBL