Browse Source

🚸 Universal X_AXIS_TWIST_COMPENSATION (#23828)

tombrazier 2 years ago
parent
commit
2e39bc30fd
No account linked to committer's email address

+ 2
- 1
Marlin/Configuration_adv.h View File

@@ -1299,7 +1299,7 @@
1299 1299
 
1300 1300
 #if HAS_MARLINUI_MENU
1301 1301
 
1302
-  #if BOTH(HAS_BED_PROBE, AUTO_BED_LEVELING_BILINEAR)
1302
+  #if HAS_BED_PROBE
1303 1303
     // Add calibration in the Probe Offsets menu to compensate for X-axis twist.
1304 1304
     //#define X_AXIS_TWIST_COMPENSATION
1305 1305
     #if ENABLED(X_AXIS_TWIST_COMPENSATION)
@@ -1311,6 +1311,7 @@
1311 1311
       #define XATC_START_Z 0.0
1312 1312
       #define XATC_MAX_POINTS 3             // Number of points to probe in the wizard
1313 1313
       #define XATC_Y_POSITION Y_CENTER      // (mm) Y position to probe
1314
+      #define XATC_Z_OFFSETS { 0, 0, 0 }    // Z offsets for X axis sample points
1314 1315
     #endif
1315 1316
   #endif
1316 1317
 

+ 0
- 3
Marlin/src/feature/bedlevel/bedlevel.h View File

@@ -63,9 +63,6 @@ class TemporaryBedLevelingState {
63 63
 
64 64
   #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
65 65
     #include "abl/abl.h"
66
-    #if ENABLED(X_AXIS_TWIST_COMPENSATION)
67
-      #include "abl/x_twist.h"
68
-    #endif
69 66
   #elif ENABLED(AUTO_BED_LEVELING_UBL)
70 67
     #include "ubl/ubl.h"
71 68
   #elif ENABLED(MESH_BED_LEVELING)

Marlin/src/feature/bedlevel/abl/x_twist.cpp → Marlin/src/feature/x_twist.cpp View File

@@ -19,16 +19,24 @@
19 19
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20 20
  *
21 21
  */
22
-#include "../../../inc/MarlinConfig.h"
22
+#include "../inc/MarlinConfig.h"
23 23
 
24 24
 #if ENABLED(X_AXIS_TWIST_COMPENSATION)
25 25
 
26
-#include "../bedlevel.h"
26
+#include "x_twist.h"
27 27
 
28 28
 XATC xatc;
29 29
 
30
+bool XATC::enabled = true;
30 31
 float XATC::spacing, XATC::start;
31
-xatc_array_t XATC::z_offset;
32
+xatc_array_t XATC::z_offset; // Initialized by settings.load()
33
+
34
+void XATC::reset() {
35
+  constexpr float xzo[] = XATC_Z_OFFSETS;
36
+  static_assert(COUNT(xzo) == XATC_MAX_POINTS, "XATC_Z_OFFSETS is the wrong size.");
37
+  enabled = false;
38
+  COPY(z_offset, xzo);
39
+}
32 40
 
33 41
 void XATC::print_points() {
34 42
   SERIAL_ECHOLNPGM(" X-Twist Correction:");
@@ -49,6 +57,7 @@ void XATC::print_points() {
49 57
 float lerp(const_float_t t, const_float_t a, const_float_t b) { return a + t * (b - a); }
50 58
 
51 59
 float XATC::compensation(const xy_pos_t &raw) {
60
+  if (!enabled) return 0;
52 61
   if (NEAR_ZERO(spacing)) return 0;
53 62
   float t = (raw.x - start) / spacing;
54 63
   int i = FLOOR(t);

Marlin/src/feature/bedlevel/abl/x_twist.h → Marlin/src/feature/x_twist.h View File

@@ -21,15 +21,18 @@
21 21
  */
22 22
 #pragma once
23 23
 
24
-#include "../../../inc/MarlinConfigPre.h"
24
+#include "../inc/MarlinConfigPre.h"
25 25
 
26 26
 typedef float xatc_array_t[XATC_MAX_POINTS];
27 27
 
28 28
 class XATC {
29
+  static bool enabled;
29 30
 public:
30 31
   static float spacing, start;
31 32
   static xatc_array_t z_offset;
32 33
 
34
+  static void reset();
35
+  static void set_enabled(const bool ena) { enabled = ena; }
33 36
   static float compensation(const xy_pos_t &raw);
34 37
   static void print_points();
35 38
 };

+ 1
- 1
Marlin/src/gcode/bedlevel/abl/G29.cpp View File

@@ -681,7 +681,7 @@ G29_TYPE GcodeSuite::G29() {
681 681
           #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
682 682
 
683 683
             const float z = abl.measured_z + abl.Z_offset;
684
-            z_values[abl.meshCount.x][abl.meshCount.y] = z PLUS_TERN0(X_AXIS_TWIST_COMPENSATION, xatc.compensation(abl.probePos));
684
+            z_values[abl.meshCount.x][abl.meshCount.y] = z;
685 685
             TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(abl.meshCount, z));
686 686
 
687 687
           #endif

+ 3
- 0
Marlin/src/lcd/menu/menu_x_twist.cpp View File

@@ -27,6 +27,7 @@
27 27
 #include "menu_addon.h"
28 28
 #include "../../module/planner.h"
29 29
 #include "../../feature/bedlevel/bedlevel.h"
30
+#include "../../feature/x_twist.h"
30 31
 #include "../../module/motion.h"
31 32
 #include "../../gcode/queue.h"
32 33
 #include "../../module/probe.h"
@@ -148,7 +149,9 @@ void xatc_wizard_goto_next_point() {
148 149
       // Deploy certain probes before starting probing
149 150
       TERN_(BLTOUCH, do_z_clearance(Z_CLEARANCE_DEPLOY_PROBE));
150 151
 
152
+      xatc.set_enabled(false);
151 153
       measured_z = probe.probe_at_point(x, XATC_Y_POSITION, PROBE_PT_STOW);
154
+      xatc.set_enabled(true);
152 155
       current_position += probe.offset_xy;
153 156
       current_position.z = XATC_START_Z - probe.offset.z + measured_z;
154 157
       line_to_current_position(MMM_TO_MMS(XY_PROBE_FEEDRATE));

+ 5
- 0
Marlin/src/module/probe.cpp View File

@@ -81,6 +81,10 @@
81 81
   #include "../feature/probe_temp_comp.h"
82 82
 #endif
83 83
 
84
+#if ENABLED(X_AXIS_TWIST_COMPENSATION)
85
+  #include "../feature/x_twist.h"
86
+#endif
87
+
84 88
 #if ENABLED(EXTENSIBLE_UI)
85 89
   #include "../lcd/extui/ui_api.h"
86 90
 #elif ENABLED(DWIN_CREALITY_LCD_ENHANCED)
@@ -808,6 +812,7 @@ float Probe::probe_at_point(const_float_t rx, const_float_t ry, const ProbePtRai
808 812
   if (!deploy()) {
809 813
     measured_z = run_z_probe(sanity_check) + offset.z;
810 814
     TERN_(HAS_PTC, ptc.apply_compensation(measured_z));
815
+    TERN_(X_AXIS_TWIST_COMPENSATION, measured_z += xatc.compensation(npos + offset_xy));
811 816
   }
812 817
   if (!isnan(measured_z)) {
813 818
     const bool big_raise = raise_after == PROBE_PT_BIG_RAISE;

+ 38
- 20
Marlin/src/module/settings.cpp View File

@@ -64,7 +64,7 @@
64 64
 #if HAS_LEVELING
65 65
   #include "../feature/bedlevel/bedlevel.h"
66 66
   #if ENABLED(X_AXIS_TWIST_COMPENSATION)
67
-    #include "../feature/bedlevel/abl/x_twist.h"
67
+    #include "../feature/x_twist.h"
68 68
   #endif
69 69
 #endif
70 70
 
@@ -269,14 +269,18 @@ typedef struct SettingsDataStruct {
269 269
   xy_pos_t bilinear_grid_spacing, bilinear_start;       // G29 L F
270 270
   #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
271 271
     bed_mesh_t z_values;                                // G29
272
-    #if ENABLED(X_AXIS_TWIST_COMPENSATION)
273
-      XATC xatc;                                        // TBD
274
-    #endif
275 272
   #else
276 273
     float z_values[3][3];
277 274
   #endif
278 275
 
279 276
   //
277
+  // X_AXIS_TWIST_COMPENSATION
278
+  //
279
+  #if ENABLED(X_AXIS_TWIST_COMPENSATION)
280
+    XATC xatc;                                          // TBD
281
+  #endif
282
+
283
+  //
280 284
   // AUTO_BED_LEVELING_UBL
281 285
   //
282 286
   bool planner_leveling_active;                         // M420 S  planner.leveling_active
@@ -298,7 +302,7 @@ typedef struct SettingsDataStruct {
298 302
       int16_t z_offsets_bed[COUNT(ptc.z_offsets_bed)];     // M871 B I V
299 303
     #endif
300 304
     #if ENABLED(PTC_HOTEND)
301
-      int16_t z_offsets_hotend[COUNT(ptc.z_offsets_hotend)];     // M871 E I V
305
+      int16_t z_offsets_hotend[COUNT(ptc.z_offsets_hotend)]; // M871 E I V
302 306
     #endif
303 307
   #endif
304 308
 
@@ -873,9 +877,6 @@ void MarlinSettings::postprocess() {
873 877
           sizeof(z_values) == (GRID_MAX_POINTS) * sizeof(z_values[0][0]),
874 878
           "Bilinear Z array is the wrong size."
875 879
         );
876
-        #if ENABLED(X_AXIS_TWIST_COMPENSATION)
877
-          static_assert(COUNT(xatc.z_offset) == XATC_MAX_POINTS, "XATC Z-offset mesh is the wrong size.");
878
-        #endif
879 880
       #else
880 881
         const xy_pos_t bilinear_start{0}, bilinear_grid_spacing{0};
881 882
       #endif
@@ -889,9 +890,6 @@ void MarlinSettings::postprocess() {
889 890
 
890 891
       #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
891 892
         EEPROM_WRITE(z_values);              // 9-256 floats
892
-        #if ENABLED(X_AXIS_TWIST_COMPENSATION)
893
-          EEPROM_WRITE(xatc);
894
-        #endif
895 893
       #else
896 894
         dummyf = 0;
897 895
         for (uint16_t q = grid_max_x * grid_max_y; q--;) EEPROM_WRITE(dummyf);
@@ -899,6 +897,14 @@ void MarlinSettings::postprocess() {
899 897
     }
900 898
 
901 899
     //
900
+    // X Axis Twist Compensation
901
+    //
902
+    #if ENABLED(X_AXIS_TWIST_COMPENSATION)
903
+      _FIELD_TEST(xatc);
904
+      EEPROM_WRITE(xatc);
905
+    #endif
906
+
907
+    //
902 908
     // Unified Bed Leveling
903 909
     //
904 910
     {
@@ -1785,9 +1791,6 @@ void MarlinSettings::postprocess() {
1785 1791
             EEPROM_READ(bilinear_grid_spacing);        // 2 ints
1786 1792
             EEPROM_READ(bilinear_start);               // 2 ints
1787 1793
             EEPROM_READ(z_values);                     // 9 to 256 floats
1788
-            #if ENABLED(X_AXIS_TWIST_COMPENSATION)
1789
-              EEPROM_READ(xatc);
1790
-            #endif
1791 1794
           }
1792 1795
           else // EEPROM data is stale
1793 1796
         #endif // AUTO_BED_LEVELING_BILINEAR
@@ -1801,6 +1804,13 @@ void MarlinSettings::postprocess() {
1801 1804
       }
1802 1805
 
1803 1806
       //
1807
+      // X Axis Twist Compensation
1808
+      //
1809
+      #if ENABLED(X_AXIS_TWIST_COMPENSATION)
1810
+        EEPROM_READ(xatc);
1811
+      #endif
1812
+
1813
+      //
1804 1814
       // Unified Bed Leveling active state
1805 1815
       //
1806 1816
       {
@@ -2849,6 +2859,14 @@ void MarlinSettings::reset() {
2849 2859
   TERN_(ENABLE_LEVELING_FADE_HEIGHT, new_z_fade_height = (DEFAULT_LEVELING_FADE_HEIGHT));
2850 2860
   TERN_(HAS_LEVELING, reset_bed_level());
2851 2861
 
2862
+  //
2863
+  // X Axis Twist Compensation
2864
+  //
2865
+  TERN_(X_AXIS_TWIST_COMPENSATION, xatc.reset());
2866
+
2867
+  //
2868
+  // Nozzle-to-probe Offset
2869
+  //
2852 2870
   #if HAS_BED_PROBE
2853 2871
     constexpr float dpo[] = NOZZLE_TO_PROBE_OFFSET;
2854 2872
     static_assert(COUNT(dpo) == LINEAR_AXES, "NOZZLE_TO_PROBE_OFFSET must contain offsets for each linear axis X, Y, Z....");
@@ -3313,14 +3331,14 @@ void MarlinSettings::reset() {
3313 3331
           }
3314 3332
         }
3315 3333
 
3316
-        // TODO: Create G-code for settings
3317
-        //#if ENABLED(X_AXIS_TWIST_COMPENSATION)
3318
-        //  CONFIG_ECHO_START();
3319
-        //  xatc.print_points();
3320
-        //#endif
3321
-
3322 3334
       #endif
3323 3335
 
3336
+      // TODO: Create G-code for settings
3337
+      //#if ENABLED(X_AXIS_TWIST_COMPENSATION)
3338
+      //  CONFIG_ECHO_START();
3339
+      //  xatc.print_points();
3340
+      //#endif
3341
+
3324 3342
     #endif // HAS_LEVELING
3325 3343
 
3326 3344
     //

+ 1
- 1
ini/features.ini View File

@@ -98,7 +98,7 @@ USB_FLASH_DRIVE_SUPPORT                = src_filter=+<src/sd/usb_flashdrive/Sd2C
98 98
 HAS_MCP3426_ADC                        = src_filter=+<src/feature/adc> +<src/gcode/feature/adc>
99 99
 AUTO_BED_LEVELING_BILINEAR             = src_filter=+<src/feature/bedlevel/abl>
100 100
 AUTO_BED_LEVELING_(3POINT|(BI)?LINEAR) = src_filter=+<src/gcode/bedlevel/abl>
101
-X_AXIS_TWIST_COMPENSATION              = src_filter=+<src/feature/bedlevel/abl/x_twist.cpp> +<src/lcd/menu/menu_x_twist.cpp>
101
+X_AXIS_TWIST_COMPENSATION              = src_filter=+<src/feature/x_twist.cpp> +<src/lcd/menu/menu_x_twist.cpp>
102 102
 MESH_BED_LEVELING                      = src_filter=+<src/feature/bedlevel/mbl> +<src/gcode/bedlevel/mbl>
103 103
 AUTO_BED_LEVELING_UBL                  = src_filter=+<src/feature/bedlevel/ubl> +<src/gcode/bedlevel/ubl>
104 104
 UBL_HILBERT_CURVE                      = src_filter=+<src/feature/bedlevel/hilbert_curve.cpp>

+ 1
- 1
platformio.ini View File

@@ -100,7 +100,6 @@ default_src_filter = +<src/*> -<src/config> -<src/HAL> +<src/HAL/shared>
100 100
   -<src/feature/backlash.cpp>
101 101
   -<src/feature/baricuda.cpp> -<src/gcode/feature/baricuda>
102 102
   -<src/feature/bedlevel/abl> -<src/gcode/bedlevel/abl>
103
-  -<src/feature/bedlevel/abl/x_twist.cpp>
104 103
   -<src/feature/bedlevel/mbl> -<src/gcode/bedlevel/mbl>
105 104
   -<src/feature/bedlevel/ubl> -<src/gcode/bedlevel/ubl>
106 105
   -<src/feature/bedlevel/hilbert_curve.cpp>
@@ -151,6 +150,7 @@ default_src_filter = +<src/*> -<src/config> -<src/HAL> +<src/HAL/shared>
151 150
   -<src/feature/tmc_util.cpp> -<src/module/stepper/trinamic.cpp>
152 151
   -<src/feature/tramming.cpp>
153 152
   -<src/feature/twibus.cpp>
153
+  -<src/feature/x_twist.cpp>
154 154
   -<src/feature/z_stepper_align.cpp>
155 155
   -<src/gcode/bedlevel/G26.cpp>
156 156
   -<src/gcode/bedlevel/G35.cpp>

Loading…
Cancel
Save