2017-03-18 16:14:31 +01:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2019-06-28 06:57:50 +02:00
|
|
|
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2017-03-18 16:14:31 +01:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-28 06:57:50 +02:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2017-03-18 16:14:31 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-09-08 22:35:25 +02:00
|
|
|
#include "../../../inc/MarlinConfig.h"
|
2017-03-18 16:14:31 +01:00
|
|
|
|
|
|
|
#if ENABLED(AUTO_BED_LEVELING_UBL)
|
2017-03-24 06:53:37 +01:00
|
|
|
|
2019-09-18 01:16:28 +02:00
|
|
|
#include "../bedlevel.h"
|
|
|
|
|
2017-09-06 13:28:32 +02:00
|
|
|
unified_bed_leveling ubl;
|
2017-03-18 16:14:31 +01:00
|
|
|
|
2017-09-08 22:35:25 +02:00
|
|
|
#include "../../../module/configuration_store.h"
|
|
|
|
#include "../../../module/planner.h"
|
|
|
|
#include "../../../module/motion.h"
|
2019-09-18 01:16:28 +02:00
|
|
|
#include "../../../module/probe.h"
|
2017-09-06 13:28:32 +02:00
|
|
|
|
2019-03-17 13:57:54 +01:00
|
|
|
#if ENABLED(EXTENSIBLE_UI)
|
|
|
|
#include "../../../lcd/extensible_ui/ui_api.h"
|
|
|
|
#endif
|
2019-04-04 03:21:06 +02:00
|
|
|
|
2017-09-06 13:28:32 +02:00
|
|
|
#include "math.h"
|
2017-05-22 05:09:51 +02:00
|
|
|
|
2019-02-24 05:53:01 +01:00
|
|
|
void unified_bed_leveling::echo_name() {
|
|
|
|
SERIAL_ECHOPGM("Unified Bed Leveling");
|
2017-11-05 15:49:38 +01:00
|
|
|
}
|
2017-05-16 09:34:36 +02:00
|
|
|
|
2019-02-24 05:53:01 +01:00
|
|
|
void unified_bed_leveling::report_current_mesh() {
|
2018-02-25 15:07:48 +01:00
|
|
|
if (!leveling_is_valid()) return;
|
2019-02-24 05:53:01 +01:00
|
|
|
SERIAL_ECHO_MSG(" G29 I99");
|
2018-02-25 15:07:48 +01:00
|
|
|
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
|
|
|
|
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
|
|
|
|
if (!isnan(z_values[x][y])) {
|
2019-02-24 05:53:01 +01:00
|
|
|
SERIAL_ECHO_START();
|
2019-03-05 13:46:19 +01:00
|
|
|
SERIAL_ECHOPAIR(" M421 I", x, " J", y);
|
2019-07-07 04:01:56 +02:00
|
|
|
SERIAL_ECHOPAIR_F(" Z", z_values[x][y], 4);
|
2019-02-24 05:53:01 +01:00
|
|
|
SERIAL_EOL();
|
2018-11-24 04:05:59 +01:00
|
|
|
serial_delay(75); // Prevent Printrun from exploding
|
2018-02-25 15:07:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-24 05:53:01 +01:00
|
|
|
void unified_bed_leveling::report_state() {
|
|
|
|
echo_name();
|
2019-09-08 07:55:34 +02:00
|
|
|
SERIAL_ECHO_TERNARY(planner.leveling_active, " System v" UBL_VERSION " ", "", "in", "active\n");
|
2018-11-24 04:05:59 +01:00
|
|
|
serial_delay(50);
|
2017-05-16 09:34:36 +02:00
|
|
|
}
|
|
|
|
|
2017-10-14 04:56:27 +02:00
|
|
|
int8_t unified_bed_leveling::storage_slot;
|
2017-03-18 16:14:31 +01:00
|
|
|
|
2017-10-14 04:56:27 +02:00
|
|
|
float unified_bed_leveling::z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
|
2017-04-23 01:01:39 +02:00
|
|
|
|
2019-09-18 01:16:28 +02:00
|
|
|
#define _GRIDPOS(A,N) (MESH_MIN_##A + N * (MESH_##A##_DIST))
|
|
|
|
|
|
|
|
const float
|
|
|
|
unified_bed_leveling::_mesh_index_to_xpos[GRID_MAX_POINTS_X] PROGMEM = ARRAY_N(GRID_MAX_POINTS_X,
|
|
|
|
_GRIDPOS(X, 0), _GRIDPOS(X, 1), _GRIDPOS(X, 2), _GRIDPOS(X, 3),
|
|
|
|
_GRIDPOS(X, 4), _GRIDPOS(X, 5), _GRIDPOS(X, 6), _GRIDPOS(X, 7),
|
|
|
|
_GRIDPOS(X, 8), _GRIDPOS(X, 9), _GRIDPOS(X, 10), _GRIDPOS(X, 11),
|
|
|
|
_GRIDPOS(X, 12), _GRIDPOS(X, 13), _GRIDPOS(X, 14), _GRIDPOS(X, 15)
|
|
|
|
),
|
|
|
|
unified_bed_leveling::_mesh_index_to_ypos[GRID_MAX_POINTS_Y] PROGMEM = ARRAY_N(GRID_MAX_POINTS_Y,
|
|
|
|
_GRIDPOS(Y, 0), _GRIDPOS(Y, 1), _GRIDPOS(Y, 2), _GRIDPOS(Y, 3),
|
|
|
|
_GRIDPOS(Y, 4), _GRIDPOS(Y, 5), _GRIDPOS(Y, 6), _GRIDPOS(Y, 7),
|
|
|
|
_GRIDPOS(Y, 8), _GRIDPOS(Y, 9), _GRIDPOS(Y, 10), _GRIDPOS(Y, 11),
|
|
|
|
_GRIDPOS(Y, 12), _GRIDPOS(Y, 13), _GRIDPOS(Y, 14), _GRIDPOS(Y, 15)
|
|
|
|
);
|
2017-03-31 07:15:32 +02:00
|
|
|
|
2018-10-30 22:34:45 +01:00
|
|
|
#if HAS_LCD_MENU
|
2017-09-08 22:35:25 +02:00
|
|
|
bool unified_bed_leveling::lcd_map_control = false;
|
|
|
|
#endif
|
|
|
|
|
2017-03-31 07:15:32 +02:00
|
|
|
volatile int unified_bed_leveling::encoder_diff;
|
|
|
|
|
|
|
|
unified_bed_leveling::unified_bed_leveling() {
|
2017-03-18 16:14:31 +01:00
|
|
|
reset();
|
|
|
|
}
|
|
|
|
|
2017-03-20 07:42:41 +01:00
|
|
|
void unified_bed_leveling::reset() {
|
2017-12-11 04:17:07 +01:00
|
|
|
const bool was_enabled = planner.leveling_active;
|
2017-06-04 00:11:43 +02:00
|
|
|
set_bed_leveling_enabled(false);
|
2017-10-14 04:56:27 +02:00
|
|
|
storage_slot = -1;
|
2017-05-22 05:09:51 +02:00
|
|
|
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
|
2017-10-14 00:21:25 +02:00
|
|
|
planner.set_z_fade_height(10.0);
|
2017-05-22 05:09:51 +02:00
|
|
|
#endif
|
2017-03-18 16:14:31 +01:00
|
|
|
ZERO(z_values);
|
2019-03-13 06:45:52 +01:00
|
|
|
#if ENABLED(EXTENSIBLE_UI)
|
|
|
|
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
|
2019-04-04 03:21:06 +02:00
|
|
|
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
|
|
|
|
ExtUI::onMeshUpdate(x, y, 0);
|
2019-03-13 06:45:52 +01:00
|
|
|
#endif
|
2017-12-11 04:17:07 +01:00
|
|
|
if (was_enabled) report_current_position();
|
2017-03-18 16:14:31 +01:00
|
|
|
}
|
|
|
|
|
2017-03-20 07:42:41 +01:00
|
|
|
void unified_bed_leveling::invalidate() {
|
2017-06-04 00:11:43 +02:00
|
|
|
set_bed_leveling_enabled(false);
|
|
|
|
set_all_mesh_points_to_value(NAN);
|
|
|
|
}
|
|
|
|
|
2017-10-13 05:20:02 +02:00
|
|
|
void unified_bed_leveling::set_all_mesh_points_to_value(const float value) {
|
2017-06-04 00:11:43 +02:00
|
|
|
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) {
|
|
|
|
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) {
|
|
|
|
z_values[x][y] = value;
|
2019-03-13 06:45:52 +01:00
|
|
|
#if ENABLED(EXTENSIBLE_UI)
|
|
|
|
ExtUI::onMeshUpdate(x, y, value);
|
|
|
|
#endif
|
2017-06-04 00:11:43 +02:00
|
|
|
}
|
|
|
|
}
|
2017-03-18 16:14:31 +01:00
|
|
|
}
|
|
|
|
|
2018-04-17 22:52:56 +02:00
|
|
|
static void serial_echo_xy(const uint8_t sp, const int16_t x, const int16_t y) {
|
|
|
|
SERIAL_ECHO_SP(sp);
|
|
|
|
SERIAL_CHAR('(');
|
|
|
|
if (x < 100) { SERIAL_CHAR(' '); if (x < 10) SERIAL_CHAR(' '); }
|
|
|
|
SERIAL_ECHO(x);
|
|
|
|
SERIAL_CHAR(',');
|
|
|
|
if (y < 100) { SERIAL_CHAR(' '); if (y < 10) SERIAL_CHAR(' '); }
|
|
|
|
SERIAL_ECHO(y);
|
|
|
|
SERIAL_CHAR(')');
|
2018-11-24 04:05:59 +01:00
|
|
|
serial_delay(5);
|
2018-04-17 22:52:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void serial_echo_column_labels(const uint8_t sp) {
|
|
|
|
SERIAL_ECHO_SP(7);
|
|
|
|
for (int8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
|
|
|
|
if (i < 10) SERIAL_CHAR(' ');
|
|
|
|
SERIAL_ECHO(i);
|
|
|
|
SERIAL_ECHO_SP(sp);
|
|
|
|
}
|
2018-11-24 04:05:59 +01:00
|
|
|
serial_delay(10);
|
2018-04-17 22:52:56 +02:00
|
|
|
}
|
2017-06-13 01:26:49 +02:00
|
|
|
|
2018-04-17 22:52:56 +02:00
|
|
|
/**
|
|
|
|
* Produce one of these mesh maps:
|
|
|
|
* 0: Human-readable
|
|
|
|
* 1: CSV format for spreadsheet import
|
|
|
|
* 2: TODO: Display on Graphical LCD
|
|
|
|
* 4: Compact Human-Readable
|
|
|
|
*/
|
2017-03-24 06:53:37 +01:00
|
|
|
void unified_bed_leveling::display_map(const int map_type) {
|
2018-03-21 06:29:09 +01:00
|
|
|
#if HAS_AUTO_REPORTING || ENABLED(HOST_KEEPALIVE_FEATURE)
|
2018-03-07 09:00:19 +01:00
|
|
|
suspend_auto_report = true;
|
|
|
|
#endif
|
|
|
|
|
2018-04-17 22:52:56 +02:00
|
|
|
constexpr uint8_t eachsp = 1 + 6 + 1, // [-3.567]
|
|
|
|
twixt = eachsp * (GRID_MAX_POINTS_X) - 9 * 2; // Leading 4sp, Coordinates 9sp each
|
2017-03-18 16:14:31 +01:00
|
|
|
|
2018-04-17 22:52:56 +02:00
|
|
|
const bool human = !(map_type & 0x3), csv = map_type == 1, lcd = map_type == 2, comp = map_type & 0x4;
|
|
|
|
|
|
|
|
SERIAL_ECHOPGM("\nBed Topography Report");
|
|
|
|
if (human) {
|
2019-02-03 06:32:48 +01:00
|
|
|
SERIAL_ECHOLNPGM(":\n");
|
2018-04-17 22:52:56 +02:00
|
|
|
serial_echo_xy(4, MESH_MIN_X, MESH_MAX_Y);
|
|
|
|
serial_echo_xy(twixt, MESH_MAX_X, MESH_MAX_Y);
|
2017-06-09 17:51:23 +02:00
|
|
|
SERIAL_EOL();
|
2018-04-17 22:52:56 +02:00
|
|
|
serial_echo_column_labels(eachsp - 2);
|
2017-03-26 00:37:54 +01:00
|
|
|
}
|
2017-06-16 20:01:52 +02:00
|
|
|
else {
|
2018-04-17 22:52:56 +02:00
|
|
|
SERIAL_ECHOPGM(" for ");
|
|
|
|
serialprintPGM(csv ? PSTR("CSV:\n") : PSTR("LCD:\n"));
|
2017-06-16 20:01:52 +02:00
|
|
|
}
|
2017-06-13 01:26:49 +02:00
|
|
|
|
2019-02-27 05:25:53 +01:00
|
|
|
// Add XY_PROBE_OFFSET_FROM_EXTRUDER because probe_pt() subtracts these when
|
|
|
|
// moving to the xy position to be measured. This ensures better agreement between
|
|
|
|
// the current Z position after G28 and the mesh values.
|
|
|
|
const float current_xi = find_closest_x_index(current_position[X_AXIS] + X_PROBE_OFFSET_FROM_EXTRUDER),
|
|
|
|
current_yi = find_closest_y_index(current_position[Y_AXIS] + Y_PROBE_OFFSET_FROM_EXTRUDER);
|
2017-03-29 02:45:54 +02:00
|
|
|
|
2018-04-17 22:52:56 +02:00
|
|
|
if (!lcd) SERIAL_EOL();
|
2017-04-06 05:29:44 +02:00
|
|
|
for (int8_t j = GRID_MAX_POINTS_Y - 1; j >= 0; j--) {
|
2018-04-17 22:52:56 +02:00
|
|
|
|
|
|
|
// Row Label (J index)
|
|
|
|
if (human) {
|
|
|
|
if (j < 10) SERIAL_CHAR(' ');
|
|
|
|
SERIAL_ECHO(j);
|
|
|
|
SERIAL_ECHOPGM(" |");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Row Values (I indexes)
|
2017-04-06 05:29:44 +02:00
|
|
|
for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
|
2017-03-18 16:14:31 +01:00
|
|
|
|
2018-04-17 22:52:56 +02:00
|
|
|
// Opening Brace or Space
|
|
|
|
const bool is_current = i == current_xi && j == current_yi;
|
|
|
|
if (human) SERIAL_CHAR(is_current ? '[' : ' ');
|
2017-03-29 02:45:54 +02:00
|
|
|
|
2018-04-17 22:52:56 +02:00
|
|
|
// Z Value at current I, J
|
2017-03-29 02:45:54 +02:00
|
|
|
const float f = z_values[i][j];
|
2018-04-17 22:52:56 +02:00
|
|
|
if (lcd) {
|
|
|
|
// TODO: Display on Graphical LCD
|
2017-03-29 02:45:54 +02:00
|
|
|
}
|
2018-04-17 22:52:56 +02:00
|
|
|
else if (isnan(f))
|
|
|
|
serialprintPGM(human ? PSTR(" . ") : PSTR("NAN"));
|
|
|
|
else if (human || csv) {
|
|
|
|
if (human && f >= 0.0) SERIAL_CHAR(f > 0 ? '+' : ' '); // Space for positive ('-' for negative)
|
|
|
|
SERIAL_ECHO_F(f, 3); // Positive: 5 digits, Negative: 6 digits
|
2017-03-18 16:14:31 +01:00
|
|
|
}
|
2018-04-17 22:52:56 +02:00
|
|
|
if (csv && i < GRID_MAX_POINTS_X - 1) SERIAL_CHAR('\t');
|
|
|
|
|
|
|
|
// Closing Brace or Space
|
|
|
|
if (human) SERIAL_CHAR(is_current ? ']' : ' ');
|
|
|
|
|
2017-11-05 15:49:38 +01:00
|
|
|
SERIAL_FLUSHTX();
|
2018-04-17 22:52:56 +02:00
|
|
|
idle();
|
2017-03-18 16:14:31 +01:00
|
|
|
}
|
2018-04-17 22:52:56 +02:00
|
|
|
if (!lcd) SERIAL_EOL();
|
|
|
|
|
|
|
|
// A blank line between rows (unless compact)
|
|
|
|
if (j && human && !comp) SERIAL_ECHOLNPGM(" |");
|
2017-03-18 16:14:31 +01:00
|
|
|
}
|
|
|
|
|
2018-04-17 22:52:56 +02:00
|
|
|
if (human) {
|
|
|
|
serial_echo_column_labels(eachsp - 2);
|
|
|
|
SERIAL_EOL();
|
|
|
|
serial_echo_xy(4, MESH_MIN_X, MESH_MIN_Y);
|
|
|
|
serial_echo_xy(twixt, MESH_MAX_X, MESH_MIN_Y);
|
2017-06-09 17:51:23 +02:00
|
|
|
SERIAL_EOL();
|
|
|
|
SERIAL_EOL();
|
2017-03-25 00:35:10 +01:00
|
|
|
}
|
2018-03-07 09:00:19 +01:00
|
|
|
|
2018-03-21 06:29:09 +01:00
|
|
|
#if HAS_AUTO_REPORTING || ENABLED(HOST_KEEPALIVE_FEATURE)
|
2018-03-07 09:00:19 +01:00
|
|
|
suspend_auto_report = false;
|
|
|
|
#endif
|
2017-03-18 16:14:31 +01:00
|
|
|
}
|
|
|
|
|
2017-03-20 07:42:41 +01:00
|
|
|
bool unified_bed_leveling::sanity_check() {
|
2017-03-18 16:14:31 +01:00
|
|
|
uint8_t error_flag = 0;
|
|
|
|
|
2017-06-16 20:01:52 +02:00
|
|
|
if (settings.calc_num_meshes() < 1) {
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPGM("?Mesh too big for EEPROM.");
|
2017-03-18 16:14:31 +01:00
|
|
|
error_flag++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return !!error_flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // AUTO_BED_LEVELING_UBL
|