Browse Source

🚸 Universal X_AXIS_TWIST_COMPENSATION (#23828)

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

+ 2
- 1
Marlin/Configuration_adv.h View File

1299
 
1299
 
1300
 #if HAS_MARLINUI_MENU
1300
 #if HAS_MARLINUI_MENU
1301
 
1301
 
1302
-  #if BOTH(HAS_BED_PROBE, AUTO_BED_LEVELING_BILINEAR)
1302
+  #if HAS_BED_PROBE
1303
     // Add calibration in the Probe Offsets menu to compensate for X-axis twist.
1303
     // Add calibration in the Probe Offsets menu to compensate for X-axis twist.
1304
     //#define X_AXIS_TWIST_COMPENSATION
1304
     //#define X_AXIS_TWIST_COMPENSATION
1305
     #if ENABLED(X_AXIS_TWIST_COMPENSATION)
1305
     #if ENABLED(X_AXIS_TWIST_COMPENSATION)
1311
       #define XATC_START_Z 0.0
1311
       #define XATC_START_Z 0.0
1312
       #define XATC_MAX_POINTS 3             // Number of points to probe in the wizard
1312
       #define XATC_MAX_POINTS 3             // Number of points to probe in the wizard
1313
       #define XATC_Y_POSITION Y_CENTER      // (mm) Y position to probe
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
     #endif
1315
     #endif
1315
   #endif
1316
   #endif
1316
 
1317
 

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

63
 
63
 
64
   #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
64
   #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
65
     #include "abl/abl.h"
65
     #include "abl/abl.h"
66
-    #if ENABLED(X_AXIS_TWIST_COMPENSATION)
67
-      #include "abl/x_twist.h"
68
-    #endif
69
   #elif ENABLED(AUTO_BED_LEVELING_UBL)
66
   #elif ENABLED(AUTO_BED_LEVELING_UBL)
70
     #include "ubl/ubl.h"
67
     #include "ubl/ubl.h"
71
   #elif ENABLED(MESH_BED_LEVELING)
68
   #elif ENABLED(MESH_BED_LEVELING)

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

19
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
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
 #if ENABLED(X_AXIS_TWIST_COMPENSATION)
24
 #if ENABLED(X_AXIS_TWIST_COMPENSATION)
25
 
25
 
26
-#include "../bedlevel.h"
26
+#include "x_twist.h"
27
 
27
 
28
 XATC xatc;
28
 XATC xatc;
29
 
29
 
30
+bool XATC::enabled = true;
30
 float XATC::spacing, XATC::start;
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
 void XATC::print_points() {
41
 void XATC::print_points() {
34
   SERIAL_ECHOLNPGM(" X-Twist Correction:");
42
   SERIAL_ECHOLNPGM(" X-Twist Correction:");
49
 float lerp(const_float_t t, const_float_t a, const_float_t b) { return a + t * (b - a); }
57
 float lerp(const_float_t t, const_float_t a, const_float_t b) { return a + t * (b - a); }
50
 
58
 
51
 float XATC::compensation(const xy_pos_t &raw) {
59
 float XATC::compensation(const xy_pos_t &raw) {
60
+  if (!enabled) return 0;
52
   if (NEAR_ZERO(spacing)) return 0;
61
   if (NEAR_ZERO(spacing)) return 0;
53
   float t = (raw.x - start) / spacing;
62
   float t = (raw.x - start) / spacing;
54
   int i = FLOOR(t);
63
   int i = FLOOR(t);

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

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

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

681
           #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
681
           #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
682
 
682
 
683
             const float z = abl.measured_z + abl.Z_offset;
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
             TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(abl.meshCount, z));
685
             TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(abl.meshCount, z));
686
 
686
 
687
           #endif
687
           #endif

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

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

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

81
   #include "../feature/probe_temp_comp.h"
81
   #include "../feature/probe_temp_comp.h"
82
 #endif
82
 #endif
83
 
83
 
84
+#if ENABLED(X_AXIS_TWIST_COMPENSATION)
85
+  #include "../feature/x_twist.h"
86
+#endif
87
+
84
 #if ENABLED(EXTENSIBLE_UI)
88
 #if ENABLED(EXTENSIBLE_UI)
85
   #include "../lcd/extui/ui_api.h"
89
   #include "../lcd/extui/ui_api.h"
86
 #elif ENABLED(DWIN_CREALITY_LCD_ENHANCED)
90
 #elif ENABLED(DWIN_CREALITY_LCD_ENHANCED)
808
   if (!deploy()) {
812
   if (!deploy()) {
809
     measured_z = run_z_probe(sanity_check) + offset.z;
813
     measured_z = run_z_probe(sanity_check) + offset.z;
810
     TERN_(HAS_PTC, ptc.apply_compensation(measured_z));
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
   if (!isnan(measured_z)) {
817
   if (!isnan(measured_z)) {
813
     const bool big_raise = raise_after == PROBE_PT_BIG_RAISE;
818
     const bool big_raise = raise_after == PROBE_PT_BIG_RAISE;

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

64
 #if HAS_LEVELING
64
 #if HAS_LEVELING
65
   #include "../feature/bedlevel/bedlevel.h"
65
   #include "../feature/bedlevel/bedlevel.h"
66
   #if ENABLED(X_AXIS_TWIST_COMPENSATION)
66
   #if ENABLED(X_AXIS_TWIST_COMPENSATION)
67
-    #include "../feature/bedlevel/abl/x_twist.h"
67
+    #include "../feature/x_twist.h"
68
   #endif
68
   #endif
69
 #endif
69
 #endif
70
 
70
 
269
   xy_pos_t bilinear_grid_spacing, bilinear_start;       // G29 L F
269
   xy_pos_t bilinear_grid_spacing, bilinear_start;       // G29 L F
270
   #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
270
   #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
271
     bed_mesh_t z_values;                                // G29
271
     bed_mesh_t z_values;                                // G29
272
-    #if ENABLED(X_AXIS_TWIST_COMPENSATION)
273
-      XATC xatc;                                        // TBD
274
-    #endif
275
   #else
272
   #else
276
     float z_values[3][3];
273
     float z_values[3][3];
277
   #endif
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
   // AUTO_BED_LEVELING_UBL
284
   // AUTO_BED_LEVELING_UBL
281
   //
285
   //
282
   bool planner_leveling_active;                         // M420 S  planner.leveling_active
286
   bool planner_leveling_active;                         // M420 S  planner.leveling_active
298
       int16_t z_offsets_bed[COUNT(ptc.z_offsets_bed)];     // M871 B I V
302
       int16_t z_offsets_bed[COUNT(ptc.z_offsets_bed)];     // M871 B I V
299
     #endif
303
     #endif
300
     #if ENABLED(PTC_HOTEND)
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
     #endif
306
     #endif
303
   #endif
307
   #endif
304
 
308
 
873
           sizeof(z_values) == (GRID_MAX_POINTS) * sizeof(z_values[0][0]),
877
           sizeof(z_values) == (GRID_MAX_POINTS) * sizeof(z_values[0][0]),
874
           "Bilinear Z array is the wrong size."
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
       #else
880
       #else
880
         const xy_pos_t bilinear_start{0}, bilinear_grid_spacing{0};
881
         const xy_pos_t bilinear_start{0}, bilinear_grid_spacing{0};
881
       #endif
882
       #endif
889
 
890
 
890
       #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
891
       #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
891
         EEPROM_WRITE(z_values);              // 9-256 floats
892
         EEPROM_WRITE(z_values);              // 9-256 floats
892
-        #if ENABLED(X_AXIS_TWIST_COMPENSATION)
893
-          EEPROM_WRITE(xatc);
894
-        #endif
895
       #else
893
       #else
896
         dummyf = 0;
894
         dummyf = 0;
897
         for (uint16_t q = grid_max_x * grid_max_y; q--;) EEPROM_WRITE(dummyf);
895
         for (uint16_t q = grid_max_x * grid_max_y; q--;) EEPROM_WRITE(dummyf);
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
     // Unified Bed Leveling
908
     // Unified Bed Leveling
903
     //
909
     //
904
     {
910
     {
1785
             EEPROM_READ(bilinear_grid_spacing);        // 2 ints
1791
             EEPROM_READ(bilinear_grid_spacing);        // 2 ints
1786
             EEPROM_READ(bilinear_start);               // 2 ints
1792
             EEPROM_READ(bilinear_start);               // 2 ints
1787
             EEPROM_READ(z_values);                     // 9 to 256 floats
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
           else // EEPROM data is stale
1795
           else // EEPROM data is stale
1793
         #endif // AUTO_BED_LEVELING_BILINEAR
1796
         #endif // AUTO_BED_LEVELING_BILINEAR
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
       // Unified Bed Leveling active state
1814
       // Unified Bed Leveling active state
1805
       //
1815
       //
1806
       {
1816
       {
2849
   TERN_(ENABLE_LEVELING_FADE_HEIGHT, new_z_fade_height = (DEFAULT_LEVELING_FADE_HEIGHT));
2859
   TERN_(ENABLE_LEVELING_FADE_HEIGHT, new_z_fade_height = (DEFAULT_LEVELING_FADE_HEIGHT));
2850
   TERN_(HAS_LEVELING, reset_bed_level());
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
   #if HAS_BED_PROBE
2870
   #if HAS_BED_PROBE
2853
     constexpr float dpo[] = NOZZLE_TO_PROBE_OFFSET;
2871
     constexpr float dpo[] = NOZZLE_TO_PROBE_OFFSET;
2854
     static_assert(COUNT(dpo) == LINEAR_AXES, "NOZZLE_TO_PROBE_OFFSET must contain offsets for each linear axis X, Y, Z....");
2872
     static_assert(COUNT(dpo) == LINEAR_AXES, "NOZZLE_TO_PROBE_OFFSET must contain offsets for each linear axis X, Y, Z....");
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
       #endif
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
     #endif // HAS_LEVELING
3342
     #endif // HAS_LEVELING
3325
 
3343
 
3326
     //
3344
     //

+ 1
- 1
ini/features.ini View File

98
 HAS_MCP3426_ADC                        = src_filter=+<src/feature/adc> +<src/gcode/feature/adc>
98
 HAS_MCP3426_ADC                        = src_filter=+<src/feature/adc> +<src/gcode/feature/adc>
99
 AUTO_BED_LEVELING_BILINEAR             = src_filter=+<src/feature/bedlevel/abl>
99
 AUTO_BED_LEVELING_BILINEAR             = src_filter=+<src/feature/bedlevel/abl>
100
 AUTO_BED_LEVELING_(3POINT|(BI)?LINEAR) = src_filter=+<src/gcode/bedlevel/abl>
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
 MESH_BED_LEVELING                      = src_filter=+<src/feature/bedlevel/mbl> +<src/gcode/bedlevel/mbl>
102
 MESH_BED_LEVELING                      = src_filter=+<src/feature/bedlevel/mbl> +<src/gcode/bedlevel/mbl>
103
 AUTO_BED_LEVELING_UBL                  = src_filter=+<src/feature/bedlevel/ubl> +<src/gcode/bedlevel/ubl>
103
 AUTO_BED_LEVELING_UBL                  = src_filter=+<src/feature/bedlevel/ubl> +<src/gcode/bedlevel/ubl>
104
 UBL_HILBERT_CURVE                      = src_filter=+<src/feature/bedlevel/hilbert_curve.cpp>
104
 UBL_HILBERT_CURVE                      = src_filter=+<src/feature/bedlevel/hilbert_curve.cpp>

+ 1
- 1
platformio.ini View File

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

Loading…
Cancel
Save