Update backlash code

This commit is contained in:
Scott Lahteine 2019-05-20 21:34:08 -05:00
parent 7b4c3bd92a
commit aeec9ef76b
4 changed files with 30 additions and 23 deletions

View file

@ -20,11 +20,13 @@
* *
*/ */
#include "../Marlin.h" #include "../inc/MarlinConfigPre.h"
#if ENABLED(BACKLASH_COMPENSATION) #if ENABLED(BACKLASH_COMPENSATION)
#include "backlash.h" #include "backlash.h"
#include "../module/motion.h"
#include "../module/planner.h" #include "../module/planner.h"
#if ENABLED(BACKLASH_GCODE) #if ENABLED(BACKLASH_GCODE)
@ -75,10 +77,10 @@ void Backlash::add_correction_steps(const int32_t &da, const int32_t &db, const
// to segments where there is no direction change. // to segments where there is no direction change.
static int32_t residual_error[XYZ] = { 0 }; static int32_t residual_error[XYZ] = { 0 };
#else #else
// No leftover residual error from segment to segment
int32_t residual_error[XYZ] = { 0 };
// No direction change, no correction. // No direction change, no correction.
if (!changed_dir) return; if (!changed_dir) return;
// No leftover residual error from segment to segment
int32_t residual_error[XYZ] = { 0 };
#endif #endif
const float f_corr = float(correction) / 255.0f; const float f_corr = float(correction) / 255.0f;
@ -100,7 +102,7 @@ void Backlash::add_correction_steps(const int32_t &da, const int32_t &db, const
if (reversing == (error_correction < 0)) { if (reversing == (error_correction < 0)) {
if (segment_proportion == 0) if (segment_proportion == 0)
segment_proportion = MIN(1.0f, block->millimeters / smoothing_mm); segment_proportion = MIN(1.0f, block->millimeters / smoothing_mm);
error_correction = ceil(segment_proportion * error_correction); error_correction = CEIL(segment_proportion * error_correction);
} }
else else
error_correction = 0; // Don't take up any backlash in this segment, as it would subtract steps error_correction = 0; // Don't take up any backlash in this segment, as it would subtract steps

View file

@ -36,7 +36,7 @@ public:
#endif #endif
static inline void set_correction(const float &v) { correction = MAX(0, MIN(1.0, v)) * all_on; } static inline void set_correction(const float &v) { correction = MAX(0, MIN(1.0, v)) * all_on; }
static inline float get_correction() { return float(ui8_to_percent(correction)) / 100.0f; } static inline float get_correction() { return float(ui8_to_percent(correction)) / 100.0f; }
#elif ENABLED(BACKLASH_COMPENSATION) #else
static constexpr uint8_t correction = (BACKLASH_CORRECTION) * 0xFF; static constexpr uint8_t correction = (BACKLASH_CORRECTION) * 0xFF;
#ifdef BACKLASH_DISTANCE_MM #ifdef BACKLASH_DISTANCE_MM
static constexpr float distance_mm[XYZ] = BACKLASH_DISTANCE_MM; static constexpr float distance_mm[XYZ] = BACKLASH_DISTANCE_MM;
@ -46,10 +46,6 @@ public:
#endif #endif
static inline void set_correction(float) { } static inline void set_correction(float) { }
static inline float get_correction() { return float(ui8_to_percent(correction)) / 100.0f; } static inline float get_correction() { return float(ui8_to_percent(correction)) / 100.0f; }
#else
static constexpr uint8_t correction = 0;
static inline void set_correction(float) { }
static inline float get_correction() { return 0; }
#endif #endif
#if ENABLED(MEASURE_BACKLASH_WHEN_PROBING) #if ENABLED(MEASURE_BACKLASH_WHEN_PROBING)

View file

@ -25,14 +25,17 @@
#if ENABLED(CALIBRATION_GCODE) #if ENABLED(CALIBRATION_GCODE)
#include "../gcode.h" #include "../gcode.h"
#if ENABLED(BACKLASH_GCODE)
#include "../../feature/backlash.h"
#endif
#include "../../lcd/ultralcd.h" #include "../../lcd/ultralcd.h"
#include "../../module/motion.h" #include "../../module/motion.h"
#include "../../module/planner.h" #include "../../module/planner.h"
#include "../../module/tool_change.h" #include "../../module/tool_change.h"
#include "../../module/endstops.h" #include "../../module/endstops.h"
#include "../../feature/bedlevel/bedlevel.h" #include "../../feature/bedlevel/bedlevel.h"
#include "../../feature/backlash.h"
/** /**
* G425 backs away from the calibration object by various distances * G425 backs away from the calibration object by various distances

View file

@ -1177,17 +1177,20 @@ void MarlinSettings::postprocess() {
// Backlash Compensation // Backlash Compensation
// //
{ {
#if ENABLED(BACKLASH_COMPENSATION) #ifdef BACKLASH_DISTANCE_MM
const float (&backlash_distance_mm)[XYZ] = backlash.distance_mm; const float (&backlash_distance_mm)[XYZ] = backlash.distance_mm;
const uint8_t &backlash_correction = backlash.correction;
#else #else
const float backlash_distance_mm[XYZ] = { 0 }; const float backlash_distance_mm[XYZ] = { 0 };
const uint8_t backlash_correction = 0; #endif
#if ENABLED(BACKLASH_COMPENSATION)
const uint8_t &backlash_correction = backlash.correction;
#else
const uint8_t backlash_correction = 0;
#endif #endif
#ifdef BACKLASH_SMOOTHING_MM #ifdef BACKLASH_SMOOTHING_MM
const float &backlash_smoothing_mm = backlash.smoothing_mm; const float &backlash_smoothing_mm = backlash.smoothing_mm;
#else #else
const float backlash_smoothing_mm = 3; const float backlash_smoothing_mm = 3;
#endif #endif
_FIELD_TEST(backlash_distance_mm); _FIELD_TEST(backlash_distance_mm);
EEPROM_WRITE(backlash_distance_mm[X_AXIS]); EEPROM_WRITE(backlash_distance_mm[X_AXIS]);
@ -1962,17 +1965,20 @@ void MarlinSettings::postprocess() {
// Backlash Compensation // Backlash Compensation
// //
{ {
#if ENABLED(BACKLASH_COMPENSATION) #ifdef BACKLASH_DISTANCE_MM
float (&backlash_distance_mm)[XYZ] = backlash.distance_mm; float (&backlash_distance_mm)[XYZ] = backlash.distance_mm;
uint8_t &backlash_correction = backlash.correction; #else
float backlash_distance_mm[XYZ];
#endif
#if ENABLED(BACKLASH_COMPENSATION)
uint8_t &backlash_correction = backlash.correction;
#else #else
float backlash_distance_mm[XYZ];
uint8_t backlash_correction; uint8_t backlash_correction;
#endif #endif
#ifdef BACKLASH_SMOOTHING_MM #ifdef BACKLASH_SMOOTHING_MM
float &backlash_smoothing_mm = backlash.smoothing_mm; float &backlash_smoothing_mm = backlash.smoothing_mm;
#else #else
float backlash_smoothing_mm; float backlash_smoothing_mm;
#endif #endif
_FIELD_TEST(backlash_distance_mm); _FIELD_TEST(backlash_distance_mm);
EEPROM_READ(backlash_distance_mm[X_AXIS]); EEPROM_READ(backlash_distance_mm[X_AXIS]);