Browse Source

🚸 Fix, extend X Axis Twist Compensation (#23745)

Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
Giuseppe499 2 years ago
parent
commit
df4e022a48
No account linked to committer's email address

+ 8
- 0
Marlin/src/core/serial.cpp View File

@@ -78,6 +78,14 @@ void serial_error_start() { static PGMSTR(errormagic, "Error:"); serial_print_P(
78 78
 
79 79
 void serial_spaces(uint8_t count) { count *= (PROPORTIONAL_FONT_RATIO); while (count--) SERIAL_CHAR(' '); }
80 80
 
81
+void serial_offset(const_float_t v, const uint8_t sp/*=0*/) {
82
+  if (v == 0 && sp == 1)
83
+    SERIAL_CHAR(' ');
84
+  else if (v > 0 || (v == 0 && sp == 2))
85
+    SERIAL_CHAR('+');
86
+  SERIAL_DECIMAL(v);
87
+}
88
+
81 89
 void serial_ternary(const bool onoff, FSTR_P const pre, FSTR_P const on, FSTR_P const off, FSTR_P const post/*=nullptr*/) {
82 90
   if (pre) serial_print(pre);
83 91
   serial_print(onoff ? on : off);

+ 1
- 0
Marlin/src/core/serial.h View File

@@ -345,6 +345,7 @@ void serialprint_onoff(const bool onoff);
345 345
 void serialprintln_onoff(const bool onoff);
346 346
 void serialprint_truefalse(const bool tf);
347 347
 void serial_spaces(uint8_t count);
348
+void serial_offset(const_float_t v, const uint8_t sp=0); // For v==0 draw space (sp==1) or plus (sp==2)
348 349
 
349 350
 void print_bin(const uint16_t val);
350 351
 void print_pos(LINEAR_AXIS_ARGS(const_float_t), FSTR_P const prefix=nullptr, FSTR_P const suffix=nullptr);

+ 1
- 3
Marlin/src/core/utility.cpp View File

@@ -126,10 +126,8 @@ void safe_delay(millis_t ms) {
126 126
         #if ABL_PLANAR
127 127
           SERIAL_ECHOPGM("ABL Adjustment");
128 128
           LOOP_LINEAR_AXES(a) {
129
-            const float v = planner.get_axis_position_mm(AxisEnum(a)) - current_position[a];
130 129
             SERIAL_CHAR(' ', AXIS_CHAR(a));
131
-            if (v > 0) SERIAL_CHAR('+');
132
-            SERIAL_DECIMAL(v);
130
+            serial_offset(planner.get_axis_position_mm(AxisEnum(a)) - current_position[a]);
133 131
           }
134 132
         #else
135 133
           #if ENABLED(AUTO_BED_LEVELING_UBL)

+ 2
- 2
Marlin/src/feature/bedlevel/ubl/ubl.cpp View File

@@ -213,8 +213,8 @@ void unified_bed_leveling::display_map(const uint8_t map_type) {
213 213
       else if (isnan(f))
214 214
         SERIAL_ECHOF(human ? F("  .   ") : F("NAN"));
215 215
       else if (human || csv) {
216
-        if (human && f >= 0.0) SERIAL_CHAR(f > 0 ? '+' : ' ');  // Display sign also for positive numbers (' ' for 0)
217
-        SERIAL_ECHO_F(f, 3);                                    // Positive: 5 digits, Negative: 6 digits
216
+        if (human && f >= 0) SERIAL_CHAR(f > 0 ? '+' : ' ');  // Display sign also for positive numbers (' ' for 0)
217
+        SERIAL_DECIMAL(f);                                    // Positive: 5 digits, Negative: 6 digits
218 218
       }
219 219
       if (csv && i < (GRID_MAX_POINTS_X) - 1) SERIAL_CHAR('\t');
220 220
 

+ 1
- 1
Marlin/src/feature/mixing.cpp View File

@@ -63,7 +63,7 @@ void Mixer::normalize(const uint8_t tool_index) {
63 63
   #ifdef MIXER_NORMALIZER_DEBUG
64 64
     SERIAL_ECHOPGM("Mixer: Old relation : [ ");
65 65
     MIXER_STEPPER_LOOP(i) {
66
-      SERIAL_ECHO_F(collector[i] / csum, 3);
66
+      SERIAL_DECIMAL(collector[i] / csum);
67 67
       SERIAL_CHAR(' ');
68 68
     }
69 69
     SERIAL_ECHOLNPGM("]");

+ 7
- 12
Marlin/src/feature/x_twist.cpp View File

@@ -36,8 +36,8 @@ void XATC::reset() {
36 36
   constexpr float xzo[] = XATC_Z_OFFSETS;
37 37
   static_assert(COUNT(xzo) == XATC_MAX_POINTS, "XATC_Z_OFFSETS is the wrong size.");
38 38
   COPY(z_offset, xzo);
39
-  xatc.spacing = (probe.max_x() - probe.min_x()) / (XATC_MAX_POINTS - 1);
40
-  xatc.start = probe.min_x();
39
+  start = probe.min_x();
40
+  spacing = (probe.max_x() - start) / (XATC_MAX_POINTS - 1);
41 41
   enabled = true;
42 42
 }
43 43
 
@@ -45,14 +45,10 @@ void XATC::print_points() {
45 45
   SERIAL_ECHOLNPGM(" X-Twist Correction:");
46 46
   LOOP_L_N(x, XATC_MAX_POINTS) {
47 47
     SERIAL_CHAR(' ');
48
-    if (!isnan(z_offset[x])) {
49
-      if (z_offset[x] >= 0) SERIAL_CHAR('+');
50
-      SERIAL_ECHO_F(z_offset[x], 3);
51
-    }
52
-    else {
53
-      LOOP_L_N(i, 6)
54
-        SERIAL_CHAR(i ? '=' : ' ');
55
-    }
48
+    if (!isnan(z_offset[x]))
49
+      serial_offset(z_offset[x]);
50
+    else
51
+      LOOP_L_N(i, 6) SERIAL_CHAR(i ? '=' : ' ');
56 52
   }
57 53
   SERIAL_EOL();
58 54
 }
@@ -63,8 +59,7 @@ float XATC::compensation(const xy_pos_t &raw) {
63 59
   if (!enabled) return 0;
64 60
   if (NEAR_ZERO(spacing)) return 0;
65 61
   float t = (raw.x - start) / spacing;
66
-  int i = FLOOR(t);
67
-  LIMIT(i, 0, XATC_MAX_POINTS - 2);
62
+  const int i = constrain(FLOOR(t), 0, XATC_MAX_POINTS - 2);
68 63
   t -= i;
69 64
   return lerp(t, z_offset[i], z_offset[i + 1]);
70 65
 }

+ 1
- 2
Marlin/src/gcode/calibrate/G33.cpp View File

@@ -98,8 +98,7 @@ void ac_cleanup(TERN_(HAS_MULTI_HOTEND, const uint8_t old_tool_index)) {
98 98
 void print_signed_float(FSTR_P const prefix, const_float_t f) {
99 99
   SERIAL_ECHOPGM("  ");
100 100
   SERIAL_ECHOF(prefix, AS_CHAR(':'));
101
-  if (f >= 0) SERIAL_CHAR('+');
102
-  SERIAL_ECHO_F(f, 2);
101
+  serial_offset(f);
103 102
 }
104 103
 
105 104
 /**

+ 5
- 0
Marlin/src/gcode/gcode.h View File

@@ -1195,6 +1195,11 @@ private:
1195 1195
     static void M1000();
1196 1196
   #endif
1197 1197
 
1198
+  #if ENABLED(X_AXIS_TWIST_COMPENSATION)
1199
+    static void M423();
1200
+    static void M423_report(const bool forReplay=true);
1201
+  #endif
1202
+
1198 1203
   #if ENABLED(SDSUPPORT)
1199 1204
     static void M1001();
1200 1205
   #endif

+ 99
- 0
Marlin/src/gcode/probe/M423.cpp View File

@@ -0,0 +1,99 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2022 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
+
23
+/**
24
+ * M423.cpp - X-Axis Twist Compensation
25
+ */
26
+
27
+#include "../../inc/MarlinConfig.h"
28
+
29
+#if ENABLED(X_AXIS_TWIST_COMPENSATION)
30
+
31
+#include "../gcode.h"
32
+#include "../../feature/x_twist.h"
33
+#include "../../module/probe.h"
34
+
35
+/**
36
+ * M423: Set a Z offset for X-Twist (added to the mesh on future G29).
37
+ *  M423 [R] [A<startx>] [I<interval>] [X<index> Z<offset>]
38
+ *
39
+ *    R         - Reset the twist compensation data
40
+ *    A<linear> - Set the X twist starting X position
41
+ *    E<linear> - Set the X twist ending X position
42
+ *    I<linear> - Set the X twist X-spacing directly
43
+ *    X<index>  - Index of a Z value in the list
44
+ *    Z<linear> - A Z value to set
45
+ */
46
+void GcodeSuite::M423() {
47
+
48
+  bool do_report = true;
49
+  float new_spacing = 0;
50
+
51
+  if (parser.seen_test('R')) {
52
+    do_report = false;
53
+    xatc.reset();
54
+  }
55
+  if (parser.seenval('A')) {
56
+    do_report = false;
57
+    xatc.start = parser.value_float();
58
+    new_spacing = (probe.max_x() - xatc.start) / (XATC_MAX_POINTS - 1);
59
+  }
60
+  if (parser.seenval('E')) {
61
+    do_report = false;
62
+    new_spacing = (parser.value_float() - xatc.start) / (XATC_MAX_POINTS - 1);
63
+  }
64
+  else if (parser.seenval('I')) {
65
+    do_report = false;
66
+    new_spacing = parser.value_float();
67
+  }
68
+
69
+  if (new_spacing) xatc.spacing = new_spacing;
70
+
71
+  if (parser.seenval('X')) {
72
+    do_report = false;
73
+    const int8_t x = parser.value_int();
74
+    if (!WITHIN(x, 0, XATC_MAX_POINTS - 1))
75
+      SERIAL_ECHOLNPGM("?(X) out of range (0..", XATC_MAX_POINTS - 1, ").");
76
+    else {
77
+      if (parser.seenval('Z'))
78
+        xatc.z_offset[x] = parser.value_linear_units();
79
+      else
80
+        SERIAL_ECHOLNPGM("?(Z) required.");
81
+    }
82
+  }
83
+
84
+  if (do_report) M423_report();
85
+
86
+}
87
+
88
+void GcodeSuite::M423_report(const bool forReplay/*=true*/) {
89
+  report_heading(forReplay, F("X-Twist Correction"));
90
+  SERIAL_ECHOLNPGM("  M423 A", xatc.start, " I", xatc.spacing);
91
+  LOOP_L_N(x, XATC_MAX_POINTS) {
92
+    const float z = xatc.z_offset[x];
93
+    SERIAL_ECHOPGM("  M423 X", x, " Z");
94
+    serial_offset(isnan(z) ? 0 : z);
95
+    SERIAL_EOL();
96
+  }
97
+}
98
+
99
+#endif // X_AXIS_TWIST_COMPENSATION

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

@@ -153,7 +153,7 @@ void xatc_wizard_goto_next_point() {
153 153
       measured_z = probe.probe_at_point(x, XATC_Y_POSITION, PROBE_PT_STOW);
154 154
       xatc.set_enabled(true);
155 155
       current_position += probe.offset_xy;
156
-      current_position.z = XATC_START_Z - probe.offset.z + measured_z;
156
+      current_position.z = (XATC_START_Z) - probe.offset.z + measured_z;
157 157
       line_to_current_position(MMM_TO_MMS(XY_PROBE_FEEDRATE));
158 158
       ui.wait_for_move = false;
159 159
     }

+ 1
- 2
Marlin/src/libs/vector_3.cpp View File

@@ -141,8 +141,7 @@ void matrix_3x3::debug(FSTR_P const title) {
141 141
   if (title) SERIAL_ECHOLNF(title);
142 142
   LOOP_L_N(i, 3) {
143 143
     LOOP_L_N(j, 3) {
144
-      if (vectors[i][j] >= 0.0) SERIAL_CHAR('+');
145
-      SERIAL_ECHO_F(vectors[i][j], 6);
144
+      serial_offset(vectors[i][j], 2);
146 145
       SERIAL_CHAR(' ');
147 146
     }
148 147
     SERIAL_EOL();

+ 13
- 9
Marlin/src/module/settings.cpp View File

@@ -277,7 +277,7 @@ typedef struct SettingsDataStruct {
277 277
   // X_AXIS_TWIST_COMPENSATION
278 278
   //
279 279
   #if ENABLED(X_AXIS_TWIST_COMPENSATION)
280
-    XATC xatc;                                          // TBD
280
+    XATC xatc;                                          // M423 X Z
281 281
   #endif
282 282
 
283 283
   //
@@ -901,7 +901,9 @@ void MarlinSettings::postprocess() {
901 901
     //
902 902
     #if ENABLED(X_AXIS_TWIST_COMPENSATION)
903 903
       _FIELD_TEST(xatc);
904
-      EEPROM_WRITE(xatc);
904
+      EEPROM_WRITE(xatc.spacing);
905
+      EEPROM_WRITE(xatc.start);
906
+      EEPROM_WRITE(xatc.z_offset);
905 907
     #endif
906 908
 
907 909
     //
@@ -1809,7 +1811,10 @@ void MarlinSettings::postprocess() {
1809 1811
       // X Axis Twist Compensation
1810 1812
       //
1811 1813
       #if ENABLED(X_AXIS_TWIST_COMPENSATION)
1812
-        EEPROM_READ(xatc);
1814
+        _FIELD_TEST(xatc);
1815
+        EEPROM_READ(xatc.spacing);
1816
+        EEPROM_READ(xatc.start);
1817
+        EEPROM_READ(xatc.z_offset);
1813 1818
       #endif
1814 1819
 
1815 1820
       //
@@ -3337,15 +3342,14 @@ void MarlinSettings::reset() {
3337 3342
 
3338 3343
       #endif
3339 3344
 
3340
-      // TODO: Create G-code for settings
3341
-      //#if ENABLED(X_AXIS_TWIST_COMPENSATION)
3342
-      //  CONFIG_ECHO_START();
3343
-      //  xatc.print_points();
3344
-      //#endif
3345
-
3346 3345
     #endif // HAS_LEVELING
3347 3346
 
3348 3347
     //
3348
+    // X Axis Twist Compensation
3349
+    //
3350
+    TERN_(X_AXIS_TWIST_COMPENSATION, gcode.M423_report(forReplay));
3351
+
3352
+    //
3349 3353
     // Editable Servo Angles
3350 3354
     //
3351 3355
     TERN_(EDITABLE_SERVO_ANGLES, gcode.M281_report(forReplay));

+ 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/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> +<src/gcode/probe/M423.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

@@ -150,7 +150,7 @@ default_src_filter = +<src/*> -<src/config> -<src/HAL> +<src/HAL/shared>
150 150
   -<src/feature/tmc_util.cpp> -<src/module/stepper/trinamic.cpp>
151 151
   -<src/feature/tramming.cpp>
152 152
   -<src/feature/twibus.cpp>
153
-  -<src/feature/x_twist.cpp>
153
+  -<src/feature/x_twist.cpp> -<src/gcode/probe/M423.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