Prusa MINI Firmware overview
backlash.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 #include "../module/planner.h"
26 
27 constexpr uint8_t all_on = 0xFF, all_off = 0x00;
28 
29 class Backlash {
30 public:
31  #if ENABLED(BACKLASH_GCODE)
32  static xyz_float_t distance_mm;
33  static uint8_t correction;
34  #ifdef BACKLASH_SMOOTHING_MM
35  static float smoothing_mm;
36  #endif
37 
38  static inline void set_correction(const float &v) { correction = _MAX(0, _MIN(1.0, v)) * all_on; }
39  static inline float get_correction() { return float(ui8_to_percent(correction)) / 100.0f; }
40  #else
41  static constexpr uint8_t correction = (BACKLASH_CORRECTION) * 0xFF;
42  static const xyz_float_t distance_mm;
43  #ifdef BACKLASH_SMOOTHING_MM
44  static constexpr float smoothing_mm = BACKLASH_SMOOTHING_MM;
45  #endif
46  #endif
47 
48  #if ENABLED(MEASURE_BACKLASH_WHEN_PROBING)
49  private:
50  static xyz_float_t measured_mm;
51  static xyz_uint8_t measured_count;
52  public:
53  static void measure_with_probe();
54  #endif
55 
56  static inline float get_measurement(const AxisEnum a) {
57  // Return the measurement averaged over all readings
58  return (
59  #if ENABLED(MEASURE_BACKLASH_WHEN_PROBING)
60  measured_count[a] > 0 ? measured_mm[a] / measured_count[a] :
61  #endif
62  0
63  );
64  #if DISABLED(MEASURE_BACKLASH_WHEN_PROBING)
65  UNUSED(a);
66  #endif
67  }
68 
69  static inline bool has_measurement(const AxisEnum a) {
70  return (false
71  #if ENABLED(MEASURE_BACKLASH_WHEN_PROBING)
72  || (measured_count[a] > 0)
73  #endif
74  );
75  #if DISABLED(MEASURE_BACKLASH_WHEN_PROBING)
76  UNUSED(a);
77  #endif
78  }
79 
80  static inline bool has_any_measurement() {
82  }
83 
84  void add_correction_steps(const int32_t &da, const int32_t &db, const int32_t &dc, const uint8_t dm, block_t * const block);
85 };
86 
87 extern Backlash backlash;
backlash
Backlash backlash
XYZEval::z
T z
Definition: types.h:383
X_AXIS
Definition: types.h:37
Backlash::correction
static constexpr uint8_t correction
Definition: backlash.h:41
_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
_MIN
#define _MIN(V...)
Definition: macros.h:333
AxisEnum
AxisEnum
Definition: types.h:36
Backlash::has_any_measurement
static bool has_any_measurement()
Definition: backlash.h:80
block_t::steps
abce_ulong_t steps
Definition: planner.h:107
Backlash
Definition: backlash.h:29
Backlash::distance_mm
static const xyz_float_t distance_mm
Definition: backlash.h:42
ABS
#define ABS(a)
Definition: macros.h:266
current_position
xyze_pos_t current_position
Definition: motion.cpp:102
Backlash::add_correction_steps
void add_correction_steps(const int32_t &da, const int32_t &db, const int32_t &dc, const uint8_t dm, block_t *const block)
LOOP_XYZ
#define LOOP_XYZ(VAR)
Definition: types.h:60
planner_settings_t::axis_steps_per_mm
float axis_steps_per_mm[XYZE_N]
Definition: planner.h:181
block_t::millimeters
float millimeters
Definition: planner.h:100
CEIL
#define CEIL(x)
Definition: macros.h:283
Backlash::get_measurement
static float get_measurement(const AxisEnum a)
Definition: backlash.h:56
if
if(size<=((png_alloc_size_t) -1) - ob)
Definition: pngwrite.c:2176
createSpeedLookupTable.a
list a
Definition: createSpeedLookupTable.py:29
uint8_t
const uint8_t[]
Definition: 404_html.c:3
Y_AXIS
Definition: types.h:38
CBI
#define CBI(A, B)
Definition: macros.h:89
backlash.h
Z_AXIS
Definition: types.h:39
ui8_to_percent
constexpr uint8_t ui8_to_percent(const uint8_t i)
Definition: utility.h:81
TEST
#define TEST(n, b)
Definition: macros.h:81
MMM_TO_MMS
#define MMM_TO_MMS(MM_M)
Definition: types.h:83
all_off
constexpr uint8_t all_off
Definition: backlash.h:27
all_on
constexpr uint8_t all_on
Definition: backlash.h:27
XYZval
Definition: types.h:100
Planner::settings
static planner_settings_t settings
Definition: planner.h:251
block_t
Definition: planner.h:95
UNUSED
#define UNUSED(X)
Definition: stm32f4xx_hal_def.h:74
ENABLED
#define ENABLED(V...)
Definition: macros.h:177
planner
Planner planner
Definition: planner.cpp:111
Backlash::has_measurement
static bool has_measurement(const AxisEnum a)
Definition: backlash.h:69