2019-05-04 06:53:15 +02:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2020-02-03 15:00:57 +01:00
|
|
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2019-05-04 06:53:15 +02:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-28 06:57:50 +02:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2019-05-04 06:53:15 +02: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
|
2020-07-23 05:20:14 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2019-05-04 06:53:15 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../inc/MarlinConfigPre.h"
|
|
|
|
#include "../module/planner.h"
|
|
|
|
|
2019-06-11 14:41:54 +02:00
|
|
|
constexpr uint8_t all_on = 0xFF, all_off = 0x00;
|
|
|
|
|
2019-05-04 06:53:15 +02:00
|
|
|
class Backlash {
|
|
|
|
public:
|
2019-05-21 04:34:23 +02:00
|
|
|
#if ENABLED(BACKLASH_GCODE)
|
2019-09-29 11:25:39 +02:00
|
|
|
static xyz_float_t distance_mm;
|
2019-05-21 04:34:23 +02:00
|
|
|
static uint8_t correction;
|
2019-05-04 06:53:15 +02:00
|
|
|
#ifdef BACKLASH_SMOOTHING_MM
|
|
|
|
static float smoothing_mm;
|
|
|
|
#endif
|
2019-09-20 07:48:41 +02:00
|
|
|
|
2021-04-02 00:59:57 +02:00
|
|
|
static inline void set_correction(const_float_t v) { correction = _MAX(0, _MIN(1.0, v)) * all_on; }
|
2019-05-04 06:53:15 +02:00
|
|
|
static inline float get_correction() { return float(ui8_to_percent(correction)) / 100.0f; }
|
2019-05-21 04:34:08 +02:00
|
|
|
#else
|
2019-05-04 06:53:15 +02:00
|
|
|
static constexpr uint8_t correction = (BACKLASH_CORRECTION) * 0xFF;
|
2019-09-29 11:25:39 +02:00
|
|
|
static const xyz_float_t distance_mm;
|
2019-05-04 06:53:15 +02:00
|
|
|
#ifdef BACKLASH_SMOOTHING_MM
|
|
|
|
static constexpr float smoothing_mm = BACKLASH_SMOOTHING_MM;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(MEASURE_BACKLASH_WHEN_PROBING)
|
|
|
|
private:
|
2019-09-29 11:25:39 +02:00
|
|
|
static xyz_float_t measured_mm;
|
|
|
|
static xyz_uint8_t measured_count;
|
2019-05-04 06:53:15 +02:00
|
|
|
public:
|
|
|
|
static void measure_with_probe();
|
|
|
|
#endif
|
|
|
|
|
2019-09-14 10:05:10 +02:00
|
|
|
static inline float get_measurement(const AxisEnum a) {
|
2020-11-08 01:28:29 +01:00
|
|
|
UNUSED(a);
|
2019-05-04 06:53:15 +02:00
|
|
|
// Return the measurement averaged over all readings
|
2020-04-22 23:35:03 +02:00
|
|
|
return TERN(MEASURE_BACKLASH_WHEN_PROBING
|
|
|
|
, measured_count[a] > 0 ? measured_mm[a] / measured_count[a] : 0
|
|
|
|
, 0
|
2019-05-04 06:53:15 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-09-14 10:05:10 +02:00
|
|
|
static inline bool has_measurement(const AxisEnum a) {
|
2020-11-08 01:28:29 +01:00
|
|
|
UNUSED(a);
|
2020-04-22 23:35:03 +02:00
|
|
|
return TERN0(MEASURE_BACKLASH_WHEN_PROBING, measured_count[a] > 0);
|
2019-05-04 06:53:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool has_any_measurement() {
|
|
|
|
return has_measurement(X_AXIS) || has_measurement(Y_AXIS) || has_measurement(Z_AXIS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void add_correction_steps(const int32_t &da, const int32_t &db, const int32_t &dc, const uint8_t dm, block_t * const block);
|
|
|
|
};
|
|
|
|
|
|
|
|
extern Backlash backlash;
|