Przeglądaj źródła

Update backlash code

Scott Lahteine 6 lat temu
rodzic
commit
aeec9ef76b

+ 6
- 4
Marlin/src/feature/backlash.cpp Wyświetl plik

20
  *
20
  *
21
  */
21
  */
22
 
22
 
23
-#include "../Marlin.h"
23
+#include "../inc/MarlinConfigPre.h"
24
 
24
 
25
 #if ENABLED(BACKLASH_COMPENSATION)
25
 #if ENABLED(BACKLASH_COMPENSATION)
26
 
26
 
27
 #include "backlash.h"
27
 #include "backlash.h"
28
+
29
+#include "../module/motion.h"
28
 #include "../module/planner.h"
30
 #include "../module/planner.h"
29
 
31
 
30
 #if ENABLED(BACKLASH_GCODE)
32
 #if ENABLED(BACKLASH_GCODE)
75
     // to segments where there is no direction change.
77
     // to segments where there is no direction change.
76
     static int32_t residual_error[XYZ] = { 0 };
78
     static int32_t residual_error[XYZ] = { 0 };
77
   #else
79
   #else
78
-    // No leftover residual error from segment to segment
79
-    int32_t residual_error[XYZ] = { 0 };
80
     // No direction change, no correction.
80
     // No direction change, no correction.
81
     if (!changed_dir) return;
81
     if (!changed_dir) return;
82
+    // No leftover residual error from segment to segment
83
+    int32_t residual_error[XYZ] = { 0 };
82
   #endif
84
   #endif
83
 
85
 
84
   const float f_corr = float(correction) / 255.0f;
86
   const float f_corr = float(correction) / 255.0f;
100
           if (reversing == (error_correction < 0)) {
102
           if (reversing == (error_correction < 0)) {
101
             if (segment_proportion == 0)
103
             if (segment_proportion == 0)
102
               segment_proportion = MIN(1.0f, block->millimeters / smoothing_mm);
104
               segment_proportion = MIN(1.0f, block->millimeters / smoothing_mm);
103
-            error_correction = ceil(segment_proportion * error_correction);
105
+            error_correction = CEIL(segment_proportion * error_correction);
104
           }
106
           }
105
           else
107
           else
106
             error_correction = 0; // Don't take up any backlash in this segment, as it would subtract steps
108
             error_correction = 0; // Don't take up any backlash in this segment, as it would subtract steps

+ 1
- 5
Marlin/src/feature/backlash.h Wyświetl plik

36
     #endif
36
     #endif
37
     static inline void set_correction(const float &v) { correction = MAX(0, MIN(1.0, v)) * all_on; }
37
     static inline void set_correction(const float &v) { correction = MAX(0, MIN(1.0, v)) * all_on; }
38
     static inline float get_correction() { return float(ui8_to_percent(correction)) / 100.0f; }
38
     static inline float get_correction() { return float(ui8_to_percent(correction)) / 100.0f; }
39
-  #elif ENABLED(BACKLASH_COMPENSATION)
39
+  #else
40
     static constexpr uint8_t correction = (BACKLASH_CORRECTION) * 0xFF;
40
     static constexpr uint8_t correction = (BACKLASH_CORRECTION) * 0xFF;
41
     #ifdef BACKLASH_DISTANCE_MM
41
     #ifdef BACKLASH_DISTANCE_MM
42
       static constexpr float distance_mm[XYZ] = BACKLASH_DISTANCE_MM;
42
       static constexpr float distance_mm[XYZ] = BACKLASH_DISTANCE_MM;
46
     #endif
46
     #endif
47
     static inline void set_correction(float) { }
47
     static inline void set_correction(float) { }
48
     static inline float get_correction() { return float(ui8_to_percent(correction)) / 100.0f; }
48
     static inline float get_correction() { return float(ui8_to_percent(correction)) / 100.0f; }
49
-  #else
50
-    static constexpr uint8_t correction = 0;
51
-    static inline void set_correction(float) { }
52
-    static inline float get_correction() { return 0; }
53
   #endif
49
   #endif
54
 
50
 
55
   #if ENABLED(MEASURE_BACKLASH_WHEN_PROBING)
51
   #if ENABLED(MEASURE_BACKLASH_WHEN_PROBING)

+ 5
- 2
Marlin/src/gcode/calibrate/G425.cpp Wyświetl plik

25
 #if ENABLED(CALIBRATION_GCODE)
25
 #if ENABLED(CALIBRATION_GCODE)
26
 
26
 
27
 #include "../gcode.h"
27
 #include "../gcode.h"
28
+
29
+#if ENABLED(BACKLASH_GCODE)
30
+  #include "../../feature/backlash.h"
31
+#endif
32
+
28
 #include "../../lcd/ultralcd.h"
33
 #include "../../lcd/ultralcd.h"
29
 #include "../../module/motion.h"
34
 #include "../../module/motion.h"
30
 #include "../../module/planner.h"
35
 #include "../../module/planner.h"
31
 #include "../../module/tool_change.h"
36
 #include "../../module/tool_change.h"
32
 #include "../../module/endstops.h"
37
 #include "../../module/endstops.h"
33
 #include "../../feature/bedlevel/bedlevel.h"
38
 #include "../../feature/bedlevel/bedlevel.h"
34
-#include "../../feature/backlash.h"
35
-
36
 
39
 
37
 /**
40
 /**
38
  * G425 backs away from the calibration object by various distances
41
  * G425 backs away from the calibration object by various distances

+ 16
- 10
Marlin/src/module/configuration_store.cpp Wyświetl plik

1177
     // Backlash Compensation
1177
     // Backlash Compensation
1178
     //
1178
     //
1179
     {
1179
     {
1180
+      #ifdef BACKLASH_DISTANCE_MM
1181
+        const float (&backlash_distance_mm)[XYZ] = backlash.distance_mm;
1182
+      #else
1183
+        const float backlash_distance_mm[XYZ] = { 0 };
1184
+      #endif
1180
       #if ENABLED(BACKLASH_COMPENSATION)
1185
       #if ENABLED(BACKLASH_COMPENSATION)
1181
-        const float   (&backlash_distance_mm)[XYZ] = backlash.distance_mm;
1182
-        const uint8_t &backlash_correction         = backlash.correction;
1186
+        const uint8_t &backlash_correction = backlash.correction;
1183
       #else
1187
       #else
1184
-        const float    backlash_distance_mm[XYZ]   = { 0 };
1185
-        const uint8_t  backlash_correction         = 0;
1188
+        const uint8_t backlash_correction = 0;
1186
       #endif
1189
       #endif
1187
       #ifdef BACKLASH_SMOOTHING_MM
1190
       #ifdef BACKLASH_SMOOTHING_MM
1188
-        const float   &backlash_smoothing_mm       = backlash.smoothing_mm;
1191
+        const float &backlash_smoothing_mm = backlash.smoothing_mm;
1189
       #else
1192
       #else
1190
-        const float    backlash_smoothing_mm       = 3;
1193
+        const float backlash_smoothing_mm = 3;
1191
       #endif
1194
       #endif
1192
       _FIELD_TEST(backlash_distance_mm);
1195
       _FIELD_TEST(backlash_distance_mm);
1193
       EEPROM_WRITE(backlash_distance_mm[X_AXIS]);
1196
       EEPROM_WRITE(backlash_distance_mm[X_AXIS]);
1962
       // Backlash Compensation
1965
       // Backlash Compensation
1963
       //
1966
       //
1964
       {
1967
       {
1968
+        #ifdef BACKLASH_DISTANCE_MM
1969
+          float (&backlash_distance_mm)[XYZ] = backlash.distance_mm;
1970
+        #else
1971
+          float backlash_distance_mm[XYZ];
1972
+        #endif
1965
         #if ENABLED(BACKLASH_COMPENSATION)
1973
         #if ENABLED(BACKLASH_COMPENSATION)
1966
-          float   (&backlash_distance_mm)[XYZ] = backlash.distance_mm;
1967
-          uint8_t &backlash_correction         = backlash.correction;
1974
+          uint8_t &backlash_correction = backlash.correction;
1968
         #else
1975
         #else
1969
-          float   backlash_distance_mm[XYZ];
1970
           uint8_t backlash_correction;
1976
           uint8_t backlash_correction;
1971
         #endif
1977
         #endif
1972
         #ifdef BACKLASH_SMOOTHING_MM
1978
         #ifdef BACKLASH_SMOOTHING_MM
1973
           float &backlash_smoothing_mm = backlash.smoothing_mm;
1979
           float &backlash_smoothing_mm = backlash.smoothing_mm;
1974
         #else
1980
         #else
1975
-          float  backlash_smoothing_mm;
1981
+          float backlash_smoothing_mm;
1976
         #endif
1982
         #endif
1977
         _FIELD_TEST(backlash_distance_mm);
1983
         _FIELD_TEST(backlash_distance_mm);
1978
         EEPROM_READ(backlash_distance_mm[X_AXIS]);
1984
         EEPROM_READ(backlash_distance_mm[X_AXIS]);

Ładowanie…
Anuluj
Zapisz