Prusa MINI Firmware overview
bedlevel.h
Go to the documentation of this file.
1 /**
2  * Marlin 3D Printer Firmware
3  * Copyright (c) 2019 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 #pragma once
23 
24 #include "../../inc/MarlinConfigPre.h"
25 
26 #if ENABLED(PROBE_MANUALLY)
27  extern bool g29_in_progress;
28 #else
29  constexpr bool g29_in_progress = false;
30 #endif
31 
32 bool leveling_is_valid();
33 void set_bed_leveling_enabled(const bool enable=true);
34 void reset_bed_level();
35 
36 #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
37  void set_z_fade_height(const float zfh, const bool do_report=true);
38 #endif
39 
40 #if EITHER(MESH_BED_LEVELING, PROBE_MANUALLY)
41  void _manual_goto_xy(const xy_pos_t &pos);
42 #endif
43 
44 /**
45  * A class to save and change the bed leveling state,
46  * then restore it when it goes out of scope.
47  */
49  bool saved;
50  public:
51  TemporaryBedLevelingState(const bool enable);
53 };
54 #define TEMPORARY_BED_LEVELING_STATE(enable) const TemporaryBedLevelingState tbls(enable)
55 
56 #if HAS_MESH
57 
58  typedef float bed_mesh_t[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
59 
60  #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
61  #include "abl/abl.h"
62  #elif ENABLED(AUTO_BED_LEVELING_UBL)
63  #include "ubl/ubl.h"
64  #elif ENABLED(MESH_BED_LEVELING)
65  #include "mbl/mesh_bed_leveling.h"
66  #endif
67 
68  #define Z_VALUES(X,Y) Z_VALUES_ARR[X][Y]
69  #define _GET_MESH_POS(M) { _GET_MESH_X(M.a), _GET_MESH_Y(M.b) }
70 
71  #if EITHER(AUTO_BED_LEVELING_BILINEAR, MESH_BED_LEVELING)
72 
73  #include <stdint.h>
74 
75  typedef float (*element_2d_fn)(const uint8_t, const uint8_t);
76 
77  /**
78  * Print calibration results for plotting or manual frame adjustment.
79  */
80  void print_2d_array(const uint8_t sx, const uint8_t sy, const uint8_t precision, element_2d_fn fn);
81 
82  #endif
83 
84  struct mesh_index_pair {
85  xy_int8_t pos;
86  float distance; // When populated, the distance from the search location
87  void invalidate() { pos = -1; }
88  bool valid() const { return pos.x >= 0 && pos.y >= 0; }
89  #if ENABLED(AUTO_BED_LEVELING_UBL)
90  xy_pos_t meshpos() {
91  return { ubl.mesh_index_to_xpos(pos.x), ubl.mesh_index_to_ypos(pos.y) };
92  }
93  #endif
94  operator xy_int8_t&() { return pos; }
95  operator const xy_int8_t&() const { return pos; }
96  };
97 
98 #endif
z_values
bed_mesh_t z_values
SERIAL_CHAR
#define SERIAL_CHAR(x)
Definition: serial.h:69
reset_bed_level
void reset_bed_level()
TemporaryBedLevelingState::~TemporaryBedLevelingState
~TemporaryBedLevelingState()
Definition: bedlevel.h:52
XYZEval::z
T z
Definition: types.h:383
Planner::synchronize
static void synchronize()
Definition: planner.cpp:1556
mbl
mesh_bed_leveling mbl
SERIAL_ECHO
#define SERIAL_ECHO(x)
Definition: serial.h:70
mesh_bed_leveling.h
unified_bed_leveling::mesh_index_to_ypos
static float mesh_index_to_ypos(const uint8_t i)
Definition: ubl.h:290
bedlevel.h
Planner::bed_level_matrix
static matrix_3x3 bed_level_matrix
Definition: planner.h:278
DEBUG_ECHOLNPGM
#define DEBUG_ECHOLNPGM(...)
Definition: debug_out.h:79
_MAX
#define _MAX(V...)
Definition: macros.h:346
do_blocking_move_to_z
void do_blocking_move_to_z(const float &rz, const feedRate_t &fr_mm_s)
Definition: motion.cpp:450
Planner::leveling_active
static bool leveling_active
Definition: planner.h:276
unified_bed_leveling::reset
static void reset()
do_blocking_move_to_xy_z
void do_blocking_move_to_xy_z(const xy_pos_t &raw, const float &z, const feedRate_t &fr_mm_s)
Definition: motion.cpp:461
do_blocking_move_to_xy
void do_blocking_move_to_xy(const float &rx, const float &ry, const feedRate_t &fr_mm_s)
Definition: motion.cpp:454
TemporaryBedLevelingState
Definition: bedlevel.h:48
mesh_bed_leveling::reset
static void reset()
i
uint8_t i
Definition: screen_test_graph.c:72
leveling_is_valid
bool leveling_is_valid()
unified_bed_leveling::mesh_index_to_xpos
static float mesh_index_to_xpos(const uint8_t i)
Definition: ubl.h:287
mesh_bed_leveling::has_mesh
static FORCE_INLINE bool has_mesh()
Definition: mesh_bed_leveling.h:54
matrix_3x3::set_to_identity
void set_to_identity()
Definition: vector_3.cpp:94
XYval::reset
FI void reset()
Definition: types.h:191
set_bed_leveling_enabled
void set_bed_leveling_enabled(const bool enable=true)
bilinear_start
xy_int_t bilinear_start
current_position
xyze_pos_t current_position
Definition: motion.cpp:102
ubl.h
sync_plan_position
void sync_plan_position()
Definition: motion.cpp:216
isnan
#define isnan
Definition: Arduino.h:55
bilinear_grid_spacing
xy_int_t bilinear_grid_spacing
ExtUI::onMeshUpdate
void onMeshUpdate(const uint8_t xpos, const uint8_t ypos, const float zval)
Definition: marlin_server.cpp:945
void
void
Definition: png.h:1083
SERIAL_ECHO_F
#define SERIAL_ECHO_F(V...)
Definition: serial.h:71
SERIAL_ECHOPGM
#define SERIAL_ECHOPGM(S)
Definition: serial.h:173
XYval
Definition: types.h:99
XYval::x
T x
Definition: types.h:185
uint8_t
const uint8_t[]
Definition: 404_html.c:3
bilinear_z_offset
float bilinear_z_offset(const xy_pos_t &raw)
ui
MarlinUI ui
unified_bed_leveling::mesh_is_valid
static bool mesh_is_valid()
Definition: ubl.h:300
g29_in_progress
constexpr bool g29_in_progress
Definition: bedlevel.h:29
ubl
unified_bed_leveling ubl
DEBUGGING
#define DEBUGGING(F)
Definition: serial.h:47
report_current_position
void report_current_position()
Definition: motion.cpp:199
SERIAL_EOL
#define SERIAL_EOL()
Definition: serial.h:181
abl.h
XYval::y
T y
Definition: types.h:185
XYZval< float >
SERIAL_ECHOLNPGM
#define SERIAL_ECHOLNPGM(S)
Definition: serial.h:174
Planner::apply_leveling
static void apply_leveling(xyz_pos_t &raw)
Definition: planner.cpp:1381
TemporaryBedLevelingState::TemporaryBedLevelingState
TemporaryBedLevelingState(const bool enable)
Planner::unapply_leveling
static void unapply_leveling(xyz_pos_t &raw)
Definition: planner.cpp:1415
serial_spaces
void serial_spaces(uint8_t count)
Definition: serial.cpp:50
planner
Planner planner
Definition: planner.cpp:111