Browse Source

✨ X Twist Compensation & Calibration (#23238)

Giuseppe499 2 years ago
parent
commit
a16a059312
No account linked to committer's email address

+ 16
- 0
Marlin/Configuration_adv.h View File

@@ -1270,6 +1270,22 @@
1270 1270
       // Set a convenient position to do the calibration (probing point and nozzle/bed-distance)
1271 1271
       //#define PROBE_OFFSET_WIZARD_XY_POS { X_CENTER, Y_CENTER }
1272 1272
     #endif
1273
+
1274
+    #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
1275
+      // Add a calibration procedure in the Probe Offsets menu
1276
+      // to compensate for twist in the X-axis.
1277
+      //#define X_AXIS_TWIST_COMPENSATION
1278
+      #if ENABLED(X_AXIS_TWIST_COMPENSATION)
1279
+        /**
1280
+         * Enable to init the Probe Z-Offset when starting the Wizard.
1281
+         * Use a height slightly above the estimated nozzle-to-probe Z offset.
1282
+         * For example, with an offset of -5, consider a starting height of -4.
1283
+         */
1284
+        #define XATC_START_Z 0.0
1285
+        #define XATC_MAX_POINTS 3             // Number of points to probe in the wizard
1286
+        #define XATC_Y_POSITION Y_CENTER      // (mm) Y position to probe
1287
+      #endif
1288
+    #endif
1273 1289
   #endif
1274 1290
 
1275 1291
   // Include a page of printer information in the LCD Main Menu

+ 59
- 0
Marlin/src/feature/bedlevel/abl/x_twist.cpp View File

@@ -0,0 +1,59 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#include "../../../inc/MarlinConfig.h"
23
+
24
+#if ENABLED(X_AXIS_TWIST_COMPENSATION)
25
+
26
+#include "../bedlevel.h"
27
+
28
+XATC xatc;
29
+
30
+float XATC::spacing, XATC::start;
31
+xatc_points_t XATC::z_values;
32
+
33
+void XATC::print_points() {
34
+  SERIAL_ECHOLNPGM(" X-Twist Correction:");
35
+  LOOP_L_N(x, XATC_MAX_POINTS) {
36
+    SERIAL_CHAR(' ');
37
+    if (!isnan(z_values[x])) {
38
+      if (z_values[x] >= 0) SERIAL_CHAR('+');
39
+      SERIAL_ECHO_F(z_values[x], 3);
40
+    }
41
+    else {
42
+      LOOP_L_N(i, 6)
43
+        SERIAL_CHAR(i ? '=' : ' ');
44
+    }
45
+  }
46
+  SERIAL_EOL();
47
+}
48
+
49
+float lerp(const_float_t t, const_float_t a, const_float_t b) { return a + t * (b - a); }
50
+
51
+float XATC::compensation(const xy_pos_t &raw) {
52
+  float t = (raw.x - start) / spacing;
53
+  int i = FLOOR(t);
54
+  LIMIT(i, 0, XATC_MAX_POINTS - 2);
55
+  t -= i;
56
+  return lerp(t, z_values[i], z_values[i + 1]);
57
+}
58
+
59
+#endif // X_AXIS_TWIST_COMPENSATION

+ 37
- 0
Marlin/src/feature/bedlevel/abl/x_twist.h View File

@@ -0,0 +1,37 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+#include "../../../inc/MarlinConfigPre.h"
25
+
26
+typedef float xatc_points_t[XATC_MAX_POINTS];
27
+
28
+class XATC {
29
+public:
30
+  static float spacing, start;
31
+  static xatc_points_t z_values;
32
+
33
+  static float compensation(const xy_pos_t &raw);
34
+  static void print_points();
35
+};
36
+
37
+extern XATC xatc;

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

@@ -63,6 +63,9 @@ 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
66 69
   #elif ENABLED(AUTO_BED_LEVELING_UBL)
67 70
     #include "ubl/ubl.h"
68 71
   #elif ENABLED(MESH_BED_LEVELING)

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

@@ -662,7 +662,7 @@ G29_TYPE GcodeSuite::G29() {
662 662
           #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
663 663
 
664 664
             const float z = abl.measured_z + abl.Z_offset;
665
-            z_values[abl.meshCount.x][abl.meshCount.y] = z;
665
+            z_values[abl.meshCount.x][abl.meshCount.y] = z PLUS_TERN0(X_AXIS_TWIST_COMPENSATION, xatc.compensation(abl.probePos));
666 666
             TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(abl.meshCount, z));
667 667
 
668 668
           #endif

+ 4
- 0
Marlin/src/inc/SanityCheck.h View File

@@ -3391,6 +3391,10 @@ static_assert(_PLUS_TEST(4), "HOMING_FEEDRATE_MM_M values must be positive.");
3391 3391
   #endif
3392 3392
 #endif
3393 3393
 
3394
+#if BOTH(X_AXIS_TWIST_COMPENSATION, NOZZLE_AS_PROBE)
3395
+  #error "X_AXIS_TWIST_COMPENSATION is incompatible with NOZZLE_AS_PROBE."
3396
+#endif
3397
+
3394 3398
 #if ENABLED(POWER_LOSS_RECOVERY)
3395 3399
   #if ENABLED(BACKUP_POWER_SUPPLY) && !PIN_EXISTS(POWER_LOSS)
3396 3400
     #error "BACKUP_POWER_SUPPLY requires a POWER_LOSS_PIN."

+ 4
- 0
Marlin/src/lcd/language/language_en.h View File

@@ -734,6 +734,10 @@ namespace Language_en {
734 734
   LSTR MSG_PROBE_WIZARD_PROBING           = _UxGT("Probing Z Reference");
735 735
   LSTR MSG_PROBE_WIZARD_MOVING            = _UxGT("Moving to Probing Pos");
736 736
 
737
+  LSTR MSG_XATC                           = _UxGT("X-Twist Wizard");
738
+  LSTR MSG_XATC_DONE                      = _UxGT("X-Twist Wizard Done!");
739
+  LSTR MSG_XATC_UPDATE_Z_OFFSET           = _UxGT("Update Probe Z-Offset to ");
740
+
737 741
   LSTR MSG_SOUND                          = _UxGT("Sound");
738 742
 
739 743
   LSTR MSG_TOP_LEFT                       = _UxGT("Top Left");

+ 1
- 1
Marlin/src/lcd/marlinui.h View File

@@ -640,7 +640,7 @@ public:
640 640
   //
641 641
   // Special handling if a move is underway
642 642
   //
643
-  #if ANY(DELTA_CALIBRATION_MENU, DELTA_AUTO_CALIBRATION, PROBE_OFFSET_WIZARD) || (ENABLED(LCD_BED_LEVELING) && EITHER(PROBE_MANUALLY, MESH_BED_LEVELING))
643
+  #if ANY(DELTA_CALIBRATION_MENU, DELTA_AUTO_CALIBRATION, PROBE_OFFSET_WIZARD, X_AXIS_TWIST_COMPENSATION) || (ENABLED(LCD_BED_LEVELING) && EITHER(PROBE_MANUALLY, MESH_BED_LEVELING))
644 644
     #define LCD_HAS_WAIT_FOR_MOVE 1
645 645
     static bool wait_for_move;
646 646
   #else

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

@@ -38,7 +38,7 @@
38 38
   #include "../../module/probe.h"
39 39
 #endif
40 40
 
41
-#if EITHER(ENABLE_LEVELING_FADE_HEIGHT, AUTO_BED_LEVELING_UBL)
41
+#if HAS_LEVELING
42 42
   #include "../../feature/bedlevel/bedlevel.h"
43 43
 #endif
44 44
 
@@ -46,6 +46,13 @@
46 46
 ///////////// Global Variables /////////////
47 47
 ////////////////////////////////////////////
48 48
 
49
+#if HAS_LEVELING && ANY(LEVEL_BED_CORNERS, PROBE_OFFSET_WIZARD, X_AXIS_TWIST_COMPENSATION)
50
+  bool leveling_was_active; // = false
51
+#endif
52
+#if ANY(PROBE_MANUALLY, MESH_BED_LEVELING, X_AXIS_TWIST_COMPENSATION)
53
+  uint8_t manual_probe_index; // = 0
54
+#endif
55
+
49 56
 // Menu Navigation
50 57
 int8_t encoderTopLine, encoderLine, screen_items;
51 58
 
@@ -338,8 +345,7 @@ void _lcd_draw_homing() {
338 345
   }
339 346
 }
340 347
 
341
-#if ENABLED(LCD_BED_LEVELING) || (HAS_LEVELING && DISABLED(SLIM_LCD_MENUS))
342
-  #include "../../feature/bedlevel/bedlevel.h"
348
+#if HAS_LEVELING && DISABLED(SLIM_LCD_MENUS)
343 349
   void _lcd_toggle_bed_leveling() { set_bed_leveling_enabled(!planner.leveling_active); }
344 350
 #endif
345 351
 

+ 13
- 0
Marlin/src/lcd/menu/menu.h View File

@@ -218,6 +218,11 @@ void _lcd_draw_homing();
218 218
   void goto_probe_offset_wizard();
219 219
 #endif
220 220
 
221
+#if ENABLED(X_AXIS_TWIST_COMPENSATION)
222
+  void xatc_wizard_continue();
223
+  void menu_advanced_settings();
224
+#endif
225
+
221 226
 #if ENABLED(LCD_BED_LEVELING) || (HAS_LEVELING && DISABLED(SLIM_LCD_MENUS))
222 227
   void _lcd_toggle_bed_leveling();
223 228
 #endif
@@ -249,3 +254,11 @@ extern uint8_t screen_history_depth;
249 254
 inline void clear_menu_history() { screen_history_depth = 0; }
250 255
 
251 256
 #define STICKY_SCREEN(S) []{ ui.defer_status_screen(); ui.goto_screen(S); }
257
+
258
+#if HAS_LEVELING && ANY(LEVEL_BED_CORNERS, PROBE_OFFSET_WIZARD, X_AXIS_TWIST_COMPENSATION)
259
+  extern bool leveling_was_active;
260
+#endif
261
+
262
+#if ANY(PROBE_MANUALLY, MESH_BED_LEVELING, X_AXIS_TWIST_COMPENSATION)
263
+  extern uint8_t manual_probe_index;
264
+#endif

+ 4
- 0
Marlin/src/lcd/menu/menu_advanced.cpp View File

@@ -508,6 +508,10 @@ void menu_backlash();
508 508
         SUBMENU(MSG_PROBE_WIZARD, goto_probe_offset_wizard);
509 509
       #endif
510 510
 
511
+      #if ENABLED(X_AXIS_TWIST_COMPENSATION)
512
+        SUBMENU(MSG_XATC, xatc_wizard_continue);
513
+      #endif
514
+
511 515
       END_MENU();
512 516
     }
513 517
   #endif

+ 0
- 4
Marlin/src/lcd/menu/menu_bed_corners.cpp View File

@@ -66,10 +66,6 @@
66 66
 
67 67
 static_assert(LEVEL_CORNERS_Z_HOP >= 0, "LEVEL_CORNERS_Z_HOP must be >= 0. Please update your configuration.");
68 68
 
69
-#if HAS_LEVELING
70
-  static bool leveling_was_active = false;
71
-#endif
72
-
73 69
 #ifndef LEVEL_CORNERS_LEVELING_ORDER
74 70
   #define LEVEL_CORNERS_LEVELING_ORDER { LF, RF, LB, RB } // Default
75 71
   //#define LEVEL_CORNERS_LEVELING_ORDER { LF, LB, RF  }  // 3 hard-coded points

+ 0
- 2
Marlin/src/lcd/menu/menu_bed_leveling.cpp View File

@@ -52,8 +52,6 @@
52 52
   // Motion > Level Bed handlers
53 53
   //
54 54
 
55
-  static uint8_t manual_probe_index;
56
-
57 55
   // LCD probed points are from defaults
58 56
   constexpr uint8_t total_probe_points = TERN(AUTO_BED_LEVELING_3POINT, 3, GRID_MAX_POINTS);
59 57
 

+ 9
- 0
Marlin/src/lcd/menu/menu_motion.cpp View File

@@ -134,6 +134,15 @@ void lcd_move_x() { _lcd_move_xyz(GET_TEXT(MSG_MOVE_X), X_AXIS); }
134 134
 
135 135
 #endif // E_MANUAL
136 136
 
137
+#if EITHER(PROBE_OFFSET_WIZARD, X_AXIS_TWIST_COMPENSATION)
138
+
139
+  void _goto_manual_move_z(const_float_t scale) {
140
+    ui.manual_move.menu_scale = scale;
141
+    ui.goto_screen(lcd_move_z);
142
+  }
143
+
144
+#endif
145
+
137 146
 //
138 147
 // "Motion" > "Move Xmm" > "Move XYZ" submenu
139 148
 //

+ 2
- 9
Marlin/src/lcd/menu/menu_probe_offset.cpp View File

@@ -39,13 +39,11 @@
39 39
   #include "../../feature/bedlevel/bedlevel.h"
40 40
 #endif
41 41
 
42
+void _goto_manual_move_z(const_float_t);
43
+
42 44
 // Global storage
43 45
 float z_offset_backup, calculated_z_offset, z_offset_ref;
44 46
 
45
-#if HAS_LEVELING
46
-  bool leveling_was_active;
47
-#endif
48
-
49 47
 inline void z_clearance_move() {
50 48
   do_z_clearance(
51 49
     #ifdef Z_AFTER_HOMING
@@ -65,11 +63,6 @@ void set_offset_and_go_back(const_float_t z) {
65 63
   ui.goto_previous_screen_no_defer();
66 64
 }
67 65
 
68
-void _goto_manual_move_z(const_float_t scale) {
69
-  ui.manual_move.menu_scale = scale;
70
-  ui.goto_screen(lcd_move_z);
71
-}
72
-
73 66
 void probe_offset_wizard_menu() {
74 67
   START_MENU();
75 68
   calculated_z_offset = probe.offset.z + current_position.z - z_offset_ref;

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

@@ -0,0 +1,224 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#include "../../inc/MarlinConfigPre.h"
23
+
24
+#if ENABLED(X_AXIS_TWIST_COMPENSATION)
25
+
26
+#include "menu_item.h"
27
+#include "menu_addon.h"
28
+#include "../../module/planner.h"
29
+#include "../../feature/bedlevel/bedlevel.h"
30
+#include "../../module/motion.h"
31
+#include "../../gcode/queue.h"
32
+#include "../../module/probe.h"
33
+
34
+#ifndef XATC_Y_POSITION
35
+  #define XATC_Y_POSITION ((probe.max_y() - probe.min_y())/2)
36
+#endif
37
+
38
+void _goto_manual_move_z(const_float_t);
39
+
40
+float measured_z, z_offset;
41
+
42
+//
43
+// Step 9: X Axis Twist Compensation Wizard is finished.
44
+//
45
+void xatc_wizard_done() {
46
+  if (!ui.wait_for_move) {
47
+    xatc.print_points();
48
+    set_bed_leveling_enabled(leveling_was_active);
49
+    SET_SOFT_ENDSTOP_LOOSE(false);
50
+    ui.goto_screen(menu_advanced_settings);
51
+  }
52
+  if (ui.should_draw())
53
+    MenuItem_static::draw(LCD_HEIGHT >= 4, GET_TEXT(MSG_XATC_DONE));
54
+  ui.refresh(LCDVIEW_CALL_REDRAW_NEXT);
55
+}
56
+
57
+void xatc_wizard_goto_next_point();
58
+
59
+//
60
+// Step 8: Ask the user if he wants to update the z-offset of the probe
61
+//
62
+void xatc_wizard_update_z_offset() {
63
+  MenuItem_confirm::select_screen(
64
+      GET_TEXT(MSG_YES), GET_TEXT(MSG_NO)
65
+    , []{
66
+        probe.offset.z = z_offset;
67
+        ui.goto_screen(xatc_wizard_done);
68
+      }
69
+    , xatc_wizard_done
70
+    , GET_TEXT(MSG_XATC_UPDATE_Z_OFFSET)
71
+    , ftostr42_52(z_offset), PSTR("?")
72
+  );
73
+}
74
+
75
+//
76
+// Step 7: Set the Z-offset for this point and go to the next one.
77
+//
78
+void xatc_wizard_set_offset_and_go_to_next_point() {
79
+  // Set Z-offset at probed point
80
+  xatc.z_values[manual_probe_index++] = probe.offset.z + current_position.z - measured_z;
81
+  // Go to next point
82
+  ui.goto_screen(xatc_wizard_goto_next_point);
83
+}
84
+
85
+//
86
+// Step 6: Wizard Menu. Move the nozzle down until it touches the bed.
87
+//
88
+void xatc_wizard_menu() {
89
+  START_MENU();
90
+  float calculated_z_offset = probe.offset.z + current_position.z - measured_z;
91
+
92
+  if (LCD_HEIGHT >= 4)
93
+    STATIC_ITEM(MSG_MOVE_NOZZLE_TO_BED, SS_CENTER|SS_INVERT);
94
+
95
+  STATIC_ITEM_P(PSTR("Z="), SS_CENTER, ftostr42_52(current_position.z));
96
+  STATIC_ITEM(MSG_ZPROBE_ZOFFSET, SS_LEFT, ftostr42_52(calculated_z_offset));
97
+
98
+  SUBMENU(MSG_MOVE_1MM,  []{ _goto_manual_move_z( 1);    });
99
+  SUBMENU(MSG_MOVE_01MM, []{ _goto_manual_move_z( 0.1f); });
100
+
101
+  if ((FINE_MANUAL_MOVE) > 0.0f && (FINE_MANUAL_MOVE) < 0.1f) {
102
+    char tmp[20], numstr[10];
103
+    // Determine digits needed right of decimal
104
+    const uint8_t digs = !UNEAR_ZERO((FINE_MANUAL_MOVE) * 1000 - int((FINE_MANUAL_MOVE) * 1000)) ? 4 :
105
+                         !UNEAR_ZERO((FINE_MANUAL_MOVE) *  100 - int((FINE_MANUAL_MOVE) *  100)) ? 3 : 2;
106
+    sprintf_P(tmp, GET_TEXT(MSG_MOVE_N_MM), dtostrf(FINE_MANUAL_MOVE, 1, digs, numstr));
107
+    #if DISABLED(HAS_GRAPHICAL_TFT)
108
+      SUBMENU_P(NUL_STR, []{ _goto_manual_move_z(float(FINE_MANUAL_MOVE)); });
109
+      MENU_ITEM_ADDON_START(0 + ENABLED(HAS_MARLINUI_HD44780));
110
+      lcd_put_u8str(tmp);
111
+      MENU_ITEM_ADDON_END();
112
+    #else
113
+      SUBMENU_P(tmp, []{ _goto_manual_move_z(float(FINE_MANUAL_MOVE)); });
114
+    #endif
115
+  }
116
+
117
+  ACTION_ITEM(MSG_BUTTON_DONE, xatc_wizard_set_offset_and_go_to_next_point);
118
+
119
+  END_MENU();
120
+}
121
+
122
+//
123
+// Step 5: Display "Next point: 1 / 9" while waiting for move to finish
124
+//
125
+void xatc_wizard_moving() {
126
+  if (ui.should_draw()) {
127
+    char msg[10];
128
+    sprintf_P(msg, PSTR("%i / %u"), manual_probe_index + 1, XATC_MAX_POINTS);
129
+    MenuEditItemBase::draw_edit_screen(GET_TEXT(MSG_LEVEL_BED_NEXT_POINT), msg);
130
+  }
131
+  ui.refresh(LCDVIEW_CALL_NO_REDRAW);
132
+  if (!ui.wait_for_move) ui.goto_screen(xatc_wizard_menu);
133
+}
134
+
135
+//
136
+// Step 4: Initiate a move to the next point
137
+//
138
+void xatc_wizard_goto_next_point() {
139
+  if (manual_probe_index < XATC_MAX_POINTS) {
140
+
141
+    const float x = xatc.start + manual_probe_index * xatc.spacing;
142
+
143
+    // Avoid probing outside the round or hexagonal area
144
+    if (!TERN0(IS_KINEMATIC, !probe.can_reach(x, XATC_Y_POSITION))) {
145
+      ui.wait_for_move = true;
146
+      ui.goto_screen(xatc_wizard_moving);
147
+
148
+      // Deploy certain probes before starting probing
149
+      TERN_(BLTOUCH, do_z_clearance(Z_CLEARANCE_DEPLOY_PROBE));
150
+
151
+      measured_z = probe.probe_at_point(x, XATC_Y_POSITION, PROBE_PT_STOW);
152
+      current_position += probe.offset_xy;
153
+      current_position.z = XATC_START_Z - probe.offset.z + measured_z;
154
+      line_to_current_position(MMM_TO_MMS(XY_PROBE_FEEDRATE));
155
+      ui.wait_for_move = false;
156
+    }
157
+    else
158
+      manual_probe_index++; // Go to next point
159
+  }
160
+  else {
161
+    // Compute the z-offset by averaging the values found with this wizard
162
+    z_offset = 0;
163
+    LOOP_L_N(i, XATC_MAX_POINTS) z_offset += xatc.z_values[i];
164
+    z_offset /= XATC_MAX_POINTS;
165
+
166
+    // Subtract the average from the values found with this wizard.
167
+    // This way they are indipendent from the z-offset
168
+    LOOP_L_N(i, XATC_MAX_POINTS) xatc.z_values[i] -= z_offset;
169
+
170
+    ui.goto_screen(xatc_wizard_update_z_offset);
171
+  }
172
+}
173
+
174
+//
175
+// Step 3: Display "Click to Begin", wait for click
176
+//         Move to the first probe position
177
+//
178
+void xatc_wizard_homing_done() {
179
+  if (ui.should_draw()) {
180
+    MenuItem_static::draw(1, GET_TEXT(MSG_LEVEL_BED_WAITING));
181
+
182
+    // Color UI needs a control to detect a touch
183
+    #if BOTH(TOUCH_SCREEN, HAS_GRAPHICAL_TFT)
184
+      touch.add_control(CLICK, 0, 0, TFT_WIDTH, TFT_HEIGHT);
185
+    #endif
186
+  }
187
+
188
+  if (ui.use_click()) {
189
+    xatc.spacing = (probe.max_x() - probe.min_x()) / (XATC_MAX_POINTS - 1);
190
+    xatc.start = probe.min_x();
191
+
192
+    SET_SOFT_ENDSTOP_LOOSE(true); // Disable soft endstops for free Z movement
193
+
194
+    ui.goto_screen(xatc_wizard_goto_next_point);
195
+  }
196
+}
197
+
198
+//
199
+// Step 2: Display "Homing XYZ" - Wait for homing to finish
200
+//
201
+void xatc_wizard_homing() {
202
+  _lcd_draw_homing();
203
+  if (all_axes_homed())
204
+    ui.goto_screen(xatc_wizard_homing_done);
205
+}
206
+
207
+//
208
+// Step 1: Prepare for the wizard...
209
+//
210
+void xatc_wizard_continue() {
211
+  // Store Bed-Leveling-State and disable
212
+  #if HAS_LEVELING
213
+    leveling_was_active = planner.leveling_active;
214
+    set_bed_leveling_enabled(false);
215
+  #endif
216
+
217
+  // Home all axes
218
+  ui.defer_status_screen();
219
+  set_all_unhomed();
220
+  ui.goto_screen(xatc_wizard_homing);
221
+  queue.inject_P(G28_STR);
222
+}
223
+
224
+#endif // X_AXIS_TWIST_COMPENSATION

+ 24
- 0
Marlin/src/module/settings.cpp View File

@@ -63,6 +63,9 @@
63 63
 
64 64
 #if HAS_LEVELING
65 65
   #include "../feature/bedlevel/bedlevel.h"
66
+  #if ENABLED(X_AXIS_TWIST_COMPENSATION)
67
+    #include "../feature/bedlevel/abl/x_twist.h"
68
+  #endif
66 69
 #endif
67 70
 
68 71
 #if ENABLED(Z_STEPPER_AUTO_ALIGN)
@@ -250,6 +253,9 @@ typedef struct SettingsDataStruct {
250 253
   xy_pos_t bilinear_grid_spacing, bilinear_start;       // G29 L F
251 254
   #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
252 255
     bed_mesh_t z_values;                                // G29
256
+    #if ENABLED(X_AXIS_TWIST_COMPENSATION)
257
+      XATC xatc;                                        // TBD
258
+    #endif
253 259
   #else
254 260
     float z_values[3][3];
255 261
   #endif
@@ -814,6 +820,12 @@ void MarlinSettings::postprocess() {
814 820
           sizeof(z_values) == (GRID_MAX_POINTS) * sizeof(z_values[0][0]),
815 821
           "Bilinear Z array is the wrong size."
816 822
         );
823
+        #if ENABLED(X_AXIS_TWIST_COMPENSATION)
824
+          static_assert(
825
+            sizeof(xatc.z_values) == (XATC_MAX_POINTS) * sizeof(xatc.z_values[0]),
826
+            "Z-offset mesh is the wrong size."
827
+          );
828
+        #endif
817 829
       #else
818 830
         const xy_pos_t bilinear_start{0}, bilinear_grid_spacing{0};
819 831
       #endif
@@ -827,6 +839,9 @@ void MarlinSettings::postprocess() {
827 839
 
828 840
       #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
829 841
         EEPROM_WRITE(z_values);              // 9-256 floats
842
+        #if ENABLED(X_AXIS_TWIST_COMPENSATION)
843
+          EEPROM_WRITE(xatc);
844
+        #endif
830 845
       #else
831 846
         dummyf = 0;
832 847
         for (uint16_t q = grid_max_x * grid_max_y; q--;) EEPROM_WRITE(dummyf);
@@ -1691,6 +1706,9 @@ void MarlinSettings::postprocess() {
1691 1706
             EEPROM_READ(bilinear_grid_spacing);        // 2 ints
1692 1707
             EEPROM_READ(bilinear_start);               // 2 ints
1693 1708
             EEPROM_READ(z_values);                     // 9 to 256 floats
1709
+            #if ENABLED(X_AXIS_TWIST_COMPENSATION)
1710
+              EEPROM_READ(xatc);
1711
+            #endif
1694 1712
           }
1695 1713
           else // EEPROM data is stale
1696 1714
         #endif // AUTO_BED_LEVELING_BILINEAR
@@ -3197,6 +3215,12 @@ void MarlinSettings::reset() {
3197 3215
           }
3198 3216
         }
3199 3217
 
3218
+        // TODO: Create G-code for settings
3219
+        //#if ENABLED(X_AXIS_TWIST_COMPENSATION)
3220
+        //  CONFIG_ECHO_START();
3221
+        //  xatc.print_points();
3222
+        //#endif
3223
+
3200 3224
       #endif
3201 3225
 
3202 3226
     #endif // HAS_LEVELING

+ 4
- 3
buildroot/tests/rambo View File

@@ -91,7 +91,7 @@ opt_set MOTHERBOARD BOARD_MINIRAMBO \
91 91
         I2C_SLAVE_ADDRESS 63
92 92
 opt_enable EEPROM_SETTINGS EEPROM_CHITCHAT REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER \
93 93
           SDSUPPORT PCA9632 SOUND_MENU_ITEM GCODE_REPEAT_MARKERS \
94
-          AUTO_BED_LEVELING_BILINEAR PROBE_MANUALLY LCD_BED_LEVELING G26_MESH_VALIDATION MESH_EDIT_MENU \
94
+          AUTO_BED_LEVELING_LINEAR PROBE_MANUALLY LCD_BED_LEVELING \
95 95
           LIN_ADVANCE EXTRA_LIN_ADVANCE_K \
96 96
           INCH_MODE_SUPPORT TEMPERATURE_UNITS_SUPPORT EXPERIMENTAL_I2CBUS M100_FREE_MEMORY_WATCHER \
97 97
           NOZZLE_PARK_FEATURE NOZZLE_CLEAN_FEATURE \
@@ -99,7 +99,7 @@ opt_enable EEPROM_SETTINGS EEPROM_CHITCHAT REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CO
99 99
           PRINTCOUNTER SERVICE_NAME_1 SERVICE_INTERVAL_1 M114_DETAIL
100 100
 opt_add M100_FREE_MEMORY_DUMPER
101 101
 opt_add M100_FREE_MEMORY_CORRUPTOR
102
-exec_test $1 $2 "MINIRAMBO | RRDGFSC | ABL Bilinear Manual | M100 | PWM_MOTOR_CURRENT | M600..." "$3"
102
+exec_test $1 $2 "MINIRAMBO | RRDGFSC | ABL Linear Manual | M100 | PWM_MOTOR_CURRENT | M600..." "$3"
103 103
 
104 104
 #
105 105
 # Test many less common options
@@ -118,7 +118,8 @@ opt_enable COREYX USE_XMAX_PLUG MIXING_EXTRUDER GRADIENT_MIX \
118 118
            BABYSTEPPING BABYSTEP_DISPLAY_TOTAL FILAMENT_LCD_DISPLAY FILAMENT_WIDTH_SENSOR \
119 119
            REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER MENU_ADDAUTOSTART SDSUPPORT SDCARD_SORT_ALPHA \
120 120
            ENDSTOP_NOISE_THRESHOLD FAN_SOFT_PWM \
121
-           FIX_MOUNTED_PROBE PROBING_ESTEPPERS_OFF AUTO_BED_LEVELING_LINEAR DEBUG_LEVELING_FEATURE PROBE_OFFSET_WIZARD \
121
+           FIX_MOUNTED_PROBE PROBING_ESTEPPERS_OFF PROBE_OFFSET_WIZARD \
122
+           AUTO_BED_LEVELING_BILINEAR X_AXIS_TWIST_COMPENSATION MESH_EDIT_MENU DEBUG_LEVELING_FEATURE G26_MESH_VALIDATION \
122 123
            Z_SAFE_HOMING SHOW_TEMP_ADC_VALUES HOME_Y_BEFORE_X EMERGENCY_PARSER \
123 124
            SD_ABORT_ON_ENDSTOP_HIT HOST_ACTION_COMMANDS HOST_PROMPT_SUPPORT HOST_PAUSE_M76 ADVANCED_OK M114_DETAIL \
124 125
            VOLUMETRIC_DEFAULT_ON NO_WORKSPACE_OFFSETS EXTRA_FAN_SPEED FWRETRACT \

+ 1
- 0
ini/features.ini View File

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

+ 2
- 0
platformio.ini View File

@@ -74,6 +74,7 @@ default_src_filter = +<src/*> -<src/config> -<src/HAL> +<src/HAL/shared>
74 74
   -<src/lcd/menu/menu_touch_screen.cpp>
75 75
   -<src/lcd/menu/menu_tramming.cpp>
76 76
   -<src/lcd/menu/menu_ubl.cpp>
77
+  -<src/lcd/menu/menu_x_twist.cpp>
77 78
   -<src/lcd/extui/anycubic_chiron>
78 79
   -<src/lcd/extui/anycubic_i3mega>
79 80
   -<src/lcd/extui/dgus> -<src/lcd/extui/dgus/fysetc> -<src/lcd/extui/dgus/hiprecy> -<src/lcd/extui/dgus/mks> -<src/lcd/extui/dgus/origin>
@@ -97,6 +98,7 @@ default_src_filter = +<src/*> -<src/config> -<src/HAL> +<src/HAL/shared>
97 98
   -<src/feature/backlash.cpp>
98 99
   -<src/feature/baricuda.cpp> -<src/gcode/feature/baricuda>
99 100
   -<src/feature/bedlevel/abl> -<src/gcode/bedlevel/abl>
101
+  -<src/feature/bedlevel/abl/x_twist.cpp>
100 102
   -<src/feature/bedlevel/mbl> -<src/gcode/bedlevel/mbl>
101 103
   -<src/feature/bedlevel/ubl> -<src/gcode/bedlevel/ubl>
102 104
   -<src/feature/bedlevel/hilbert_curve.cpp>

Loading…
Cancel
Save