🐛 Fix steps-to-mm with backlash (#23814)
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
This commit is contained in:
committed by
Scott Lahteine
parent
8e11a2bb83
commit
b0fdbede9c
@ -29,6 +29,11 @@
|
||||
#include "../module/motion.h"
|
||||
#include "../module/planner.h"
|
||||
|
||||
axis_bits_t Backlash::last_direction_bits;
|
||||
#ifdef BACKLASH_SMOOTHING_MM
|
||||
xyz_long_t Backlash::residual_error{0};
|
||||
#endif
|
||||
|
||||
#ifdef BACKLASH_DISTANCE_MM
|
||||
#if ENABLED(BACKLASH_GCODE)
|
||||
xyz_float_t Backlash::distance_mm = BACKLASH_DISTANCE_MM;
|
||||
@ -61,7 +66,6 @@ Backlash backlash;
|
||||
*/
|
||||
|
||||
void Backlash::add_correction_steps(const int32_t &da, const int32_t &db, const int32_t &dc, const axis_bits_t dm, block_t * const block) {
|
||||
static axis_bits_t last_direction_bits;
|
||||
axis_bits_t changed_dir = last_direction_bits ^ dm;
|
||||
// Ignore direction change unless steps are taken in that direction
|
||||
#if DISABLED(CORE_BACKLASH) || EITHER(MARKFORGED_XY, MARKFORGED_YX)
|
||||
@ -91,10 +95,6 @@ void Backlash::add_correction_steps(const int32_t &da, const int32_t &db, const
|
||||
// smoothing distance. Since the computation of this proportion involves a floating point
|
||||
// division, defer computation until needed.
|
||||
float segment_proportion = 0;
|
||||
|
||||
// Residual error carried forward across multiple segments, so correction can be applied
|
||||
// to segments where there is no direction change.
|
||||
static xyz_long_t residual_error{0};
|
||||
#else
|
||||
// No direction change, no correction.
|
||||
if (!changed_dir) return;
|
||||
@ -153,6 +153,27 @@ void Backlash::add_correction_steps(const int32_t &da, const int32_t &db, const
|
||||
}
|
||||
}
|
||||
|
||||
int32_t Backlash::applied_steps(const AxisEnum axis) {
|
||||
if (axis >= LINEAR_AXES) return 0;
|
||||
|
||||
const bool reversing = TEST(last_direction_bits, axis);
|
||||
|
||||
#ifdef BACKLASH_SMOOTHING_MM
|
||||
const int32_t residual_error_axis = residual_error[axis];
|
||||
#else
|
||||
constexpr int32_t residual_error_axis = 0;
|
||||
#endif
|
||||
|
||||
// At startup it is assumed the last move was forwards. So the applied
|
||||
// steps will always be a non-positive number.
|
||||
|
||||
if (!reversing) return -residual_error_axis;
|
||||
|
||||
const float f_corr = float(correction) / 255.0f;
|
||||
const int32_t full_error_axis = -f_corr * distance_mm[axis] * planner.settings.axis_steps_per_mm[axis];
|
||||
return full_error_axis - residual_error_axis;
|
||||
}
|
||||
|
||||
#if ENABLED(MEASURE_BACKLASH_WHEN_PROBING)
|
||||
|
||||
#include "../module/probe.h"
|
||||
|
@ -27,6 +27,12 @@
|
||||
constexpr uint8_t all_on = 0xFF, all_off = 0x00;
|
||||
|
||||
class Backlash {
|
||||
private:
|
||||
static axis_bits_t last_direction_bits;
|
||||
#ifdef BACKLASH_SMOOTHING_MM
|
||||
static xyz_long_t residual_error;
|
||||
#endif
|
||||
|
||||
public:
|
||||
#if ENABLED(BACKLASH_GCODE)
|
||||
static xyz_float_t distance_mm;
|
||||
@ -71,7 +77,8 @@ public:
|
||||
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 axis_bits_t dm, block_t * const block);
|
||||
static void add_correction_steps(const int32_t &da, const int32_t &db, const int32_t &dc, const axis_bits_t dm, block_t * const block);
|
||||
static int32_t applied_steps(const AxisEnum axis);
|
||||
};
|
||||
|
||||
extern Backlash backlash;
|
||||
|
Reference in New Issue
Block a user