Browse Source

New feature: BED_SKEW_CORRECTION

Scott Lahteine 6 years ago
parent
commit
0154e3480c

+ 1
- 1
.travis.yml View File

@@ -62,7 +62,7 @@ script:
62 62
   - opt_enable PIDTEMPBED FIX_MOUNTED_PROBE Z_SAFE_HOMING ARC_P_CIRCLES CNC_WORKSPACE_PLANES CNC_COORDINATE_SYSTEMS
63 63
   - opt_enable REPRAP_DISCOUNT_SMART_CONTROLLER SDSUPPORT EEPROM_SETTINGS
64 64
   - opt_enable BLINKM PCA9632 RGB_LED NEOPIXEL_LED
65
-  - opt_enable AUTO_BED_LEVELING_LINEAR Z_MIN_PROBE_REPEATABILITY_TEST DEBUG_LEVELING_FEATURE
65
+  - opt_enable AUTO_BED_LEVELING_LINEAR Z_MIN_PROBE_REPEATABILITY_TEST DEBUG_LEVELING_FEATURE SKEW_CORRECTION SKEW_CORRECTION_FOR_Z SKEW_CORRECTION_GCODE
66 66
   - opt_enable_adv FWRETRACT MAX7219_DEBUG LED_CONTROL_MENU
67 67
   - opt_set ABL_GRID_POINTS_X 16
68 68
   - opt_set ABL_GRID_POINTS_Y 16

+ 58
- 1
Marlin/Configuration.h View File

@@ -832,7 +832,7 @@
832 832
 //===========================================================================
833 833
 //=============================== Bed Leveling ==============================
834 834
 //===========================================================================
835
-// @section bedlevel
835
+// @section calibrate
836 836
 
837 837
 /**
838 838
  * Choose one of the options below to enable G29 Bed Leveling. The parameters
@@ -1039,6 +1039,63 @@
1039 1039
 #define HOMING_FEEDRATE_XY (50*60)
1040 1040
 #define HOMING_FEEDRATE_Z  (4*60)
1041 1041
 
1042
+// @section calibrate
1043
+
1044
+/**
1045
+ * Bed Skew Compensation
1046
+ *
1047
+ * This feature corrects for misalignment in the XYZ axes.
1048
+ *
1049
+ * Take the following steps to get the bed skew in the XY plane:
1050
+ *  1. Print a test square (e.g., https://www.thingiverse.com/thing:2563185)
1051
+ *  2. For XY_DIAG_AC measure the diagonal A to C
1052
+ *  3. For XY_DIAG_BD measure the diagonal B to D
1053
+ *  4. For XY_SIDE_AD measure the edge A to D
1054
+ *
1055
+ * Marlin automatically computes skew factors from these measurements.
1056
+ * Skew factors may also be computed and set manually:
1057
+ *
1058
+ *  - Compute AB     : SQRT(2*AC*AC+2*BD*BD-4*AD*AD)/2
1059
+ *  - XY_SKEW_FACTOR : TAN(PI/2-ACOS((AC*AC-AB*AB-AD*AD)/(2*AB*AD)))
1060
+ *
1061
+ * If desired, follow the same procedure for XZ and YZ.
1062
+ * Use these diagrams for reference:
1063
+ *
1064
+ *    Y                     Z                     Z
1065
+ *    ^     B-------C       ^     B-------C       ^     B-------C
1066
+ *    |    /       /        |    /       /        |    /       /
1067
+ *    |   /       /         |   /       /         |   /       /
1068
+ *    |  A-------D          |  A-------D          |  A-------D
1069
+ *    +-------------->X     +-------------->X     +-------------->Y
1070
+ *     XY_SKEW_FACTOR        XZ_SKEW_FACTOR        YZ_SKEW_FACTOR
1071
+ */
1072
+//#define SKEW_CORRECTION
1073
+
1074
+#if ENABLED(SKEW_CORRECTION)
1075
+  // Input all length measurements here:
1076
+  #define XY_DIAG_AC 282.8427124746
1077
+  #define XY_DIAG_BD 282.8427124746
1078
+  #define XY_SIDE_AD 200
1079
+
1080
+  // Or, set the default skew factors directly here
1081
+  // to override the above measurements:
1082
+  #define XY_SKEW_FACTOR 0.0
1083
+
1084
+  //#define SKEW_CORRECTION_FOR_Z
1085
+  #if ENABLED(SKEW_CORRECTION_FOR_Z)
1086
+    #define XZ_DIAG_AC 282.8427124746
1087
+    #define XZ_DIAG_BD 282.8427124746
1088
+    #define YZ_DIAG_AC 282.8427124746
1089
+    #define YZ_DIAG_BD 282.8427124746
1090
+    #define YZ_SIDE_AD 200
1091
+    #define XZ_SKEW_FACTOR 0.0
1092
+    #define YZ_SKEW_FACTOR 0.0
1093
+  #endif
1094
+
1095
+  // Enable this option for M852 to set skew at runtime
1096
+  //#define SKEW_CORRECTION_GCODE
1097
+#endif
1098
+
1042 1099
 //=============================================================================
1043 1100
 //============================= Additional Features ===========================
1044 1101
 //=============================================================================

+ 3
- 1
Marlin/src/core/language.h View File

@@ -130,7 +130,6 @@
130 130
 #define MSG_ERR_LINE_NO                     "Line Number is not Last Line Number+1, Last Line: "
131 131
 #define MSG_ERR_CHECKSUM_MISMATCH           "checksum mismatch, Last Line: "
132 132
 #define MSG_ERR_NO_CHECKSUM                 "No Checksum with line number, Last Line: "
133
-#define MSG_ERR_NO_LINENUMBER_WITH_CHECKSUM "No Line Number with checksum, Last Line: "
134 133
 #define MSG_FILE_PRINTED                    "Done printing file"
135 134
 #define MSG_BEGIN_FILE_LIST                 "Begin file list"
136 135
 #define MSG_END_FILE_LIST                   "End file list"
@@ -163,6 +162,9 @@
163 162
 #define MSG_Z2_MAX                          "z2_max: "
164 163
 #define MSG_Z_PROBE                         "z_probe: "
165 164
 #define MSG_PROBE_Z_OFFSET                  "Probe Z Offset"
165
+#define MSG_SKEW_MIN                        "min_skew_factor: "
166
+#define MSG_SKEW_MAX                        "max_skew_factor: "
167
+#define MSG_SKEW_WARN                       "WARNING: Skew compensation disabled (outside MIN/MAX limits)"
166 168
 #define MSG_FILAMENT_RUNOUT_SENSOR          "filament: "
167 169
 #define MSG_ERR_MATERIAL_INDEX              "M145 S<index> out of range (0-1)"
168 170
 #define MSG_ERR_M355_NONE                   "No case light"

+ 89
- 0
Marlin/src/gcode/calibrate/M852.cpp View File

@@ -0,0 +1,89 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 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 <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#include "../../inc/MarlinConfig.h"
24
+
25
+#if ENABLED(SKEW_CORRECTION_GCODE)
26
+
27
+#include "../gcode.h"
28
+#include "../../module/planner.h"
29
+
30
+/**
31
+ * M852: Get or set the machine skew factors. Reports current values with no arguments.
32
+ *
33
+ *  S[xy_factor] - Alias for 'I'
34
+ *  I[xy_factor] - New XY skew factor
35
+ *  J[xz_factor] - New XZ skew factor
36
+ *  K[yz_factor] - New YZ skew factor
37
+ */
38
+void GcodeSuite::M852() {
39
+  const bool ijk = parser.seen('I') || parser.seen('S')
40
+    #if ENABLED(SKEW_CORRECTION_FOR_Z)
41
+      || parser.seen('J') || parser.seen('K')
42
+    #endif
43
+  ;
44
+  bool badval = false;
45
+
46
+  if (parser.seen('I') || parser.seen('S')) {
47
+    const float value = parser.value_linear_units();
48
+    if (WITHIN(value, SKEW_FACTOR_MIN, SKEW_FACTOR_MAX))
49
+      planner.xy_skew_factor = value;
50
+    else
51
+      badval = true;
52
+  }
53
+
54
+  #if ENABLED(SKEW_CORRECTION_FOR_Z)
55
+
56
+    if (parser.seen('J')) {
57
+      const float value = parser.value_linear_units();
58
+      if (WITHIN(value, SKEW_FACTOR_MIN, SKEW_FACTOR_MAX))
59
+        planner.xz_skew_factor = value;
60
+      else
61
+        badval = true;
62
+    }
63
+
64
+    if (parser.seen('K')) {
65
+      const float value = parser.value_linear_units();
66
+      if (WITHIN(value, SKEW_FACTOR_MIN, SKEW_FACTOR_MAX))
67
+        planner.yz_skew_factor = value;
68
+      else
69
+        badval = true;
70
+    }
71
+
72
+  #endif
73
+
74
+  if (badval)
75
+    SERIAL_ECHOLNPGM(MSG_SKEW_MIN " " STRINGIFY(SKEW_FACTOR_MIN) " " MSG_SKEW_MAX " " STRINGIFY(SKEW_FACTOR_MAX));
76
+
77
+  if (!ijk) {
78
+    SERIAL_ECHO_START();
79
+    SERIAL_ECHOPAIR(MSG_SKEW_FACTOR " XY: ", planner.xy_skew_factor);
80
+    #if ENABLED(SKEW_CORRECTION_FOR_Z)
81
+      SERIAL_ECHOPAIR(" XZ: ", planner.xz_skew_factor);
82
+      SERIAL_ECHOLNPAIR(" YZ: ", planner.yz_skew_factor);
83
+    #else
84
+      SERIAL_EOL();
85
+    #endif
86
+  }
87
+}
88
+
89
+#endif // SKEW_CORRECTION_GCODE

+ 6
- 0
Marlin/src/gcode/gcode.cpp View File

@@ -622,6 +622,12 @@ void GcodeSuite::process_parsed_command() {
622 622
           break;
623 623
       #endif // HAS_BED_PROBE
624 624
 
625
+      #if ENABLED(SKEW_CORRECTION_GCODE)
626
+        case 852: // M852: Set Skew factors
627
+          M852();
628
+          break;
629
+      #endif
630
+
625 631
       #if ENABLED(ADVANCED_PAUSE_FEATURE)
626 632
         case 600: // M600: Pause for filament change
627 633
           M600();

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

@@ -201,6 +201,7 @@
201 201
  * M666 - Set delta endstop adjustment. (Requires DELTA)
202 202
  * M605 - Set dual x-carriage movement mode: "M605 S<mode> [X<x_offset>] [R<temp_offset>]". (Requires DUAL_X_CARRIAGE)
203 203
  * M851 - Set Z probe's Z offset in current units. (Negative = below the nozzle.)
204
+ * M852 - Set skew factors: "M852 [I<xy>] [J<xz>] [K<yz>]". (Requires SKEW_CORRECTION_GCODE, and SKEW_CORRECTION_FOR_Z for IJ)
204 205
  * M860 - Report the position of position encoder modules.
205 206
  * M861 - Report the status of position encoder modules.
206 207
  * M862 - Perform an axis continuity test for position encoder modules.
@@ -705,6 +706,10 @@ private:
705 706
     static void M851();
706 707
   #endif
707 708
 
709
+  #if ENABLED(SKEW_CORRECTION_GCODE)
710
+    static void M852();
711
+  #endif
712
+
708 713
   #if ENABLED(I2C_POSITION_ENCODERS)
709 714
     FORCE_INLINE static void M860() { I2CPEM.M860(); }
710 715
     FORCE_INLINE static void M861() { I2CPEM.M861(); }

+ 43
- 0
Marlin/src/inc/Conditionals_post.h View File

@@ -889,6 +889,49 @@
889 889
 #endif
890 890
 
891 891
 /**
892
+ * XYZ Bed Skew Correction
893
+ */
894
+#if ENABLED(SKEW_CORRECTION)
895
+  #define SKEW_FACTOR_MIN -1
896
+  #define SKEW_FACTOR_MAX 1
897
+
898
+  #define _GET_SIDE(a,b,c) (SQRT(2*sq(a)+2*sq(b)-4*sq(c))*0.5)
899
+  #define _SKEW_SIDE(a,b,c) tan(M_PI*0.5-acos((sq(a)-sq(b)-sq(c))/(2*c*b)))
900
+  #define _SKEW_FACTOR(a,b,c) _SKEW_SIDE(a,_GET_SIDE(a,b,c),c)
901
+
902
+  #ifndef XY_SKEW_FACTOR
903
+    constexpr float XY_SKEW_FACTOR = (
904
+      #if defined(XY_DIAG_AC) && defined(XY_DIAG_BD) && defined(XY_SIDE_AD)
905
+        _SKEW_FACTOR(XY_DIAG_AC, XY_DIAG_BD, XY_SIDE_AD)
906
+      #else
907
+        0.0
908
+      #endif
909
+    );
910
+  #endif
911
+  #ifndef XZ_SKEW_FACTOR
912
+    #if defined(XY_SIDE_AD) && !defined(XZ_SIDE_AD)
913
+      #define XZ_SIDE_AD XY_SIDE_AD
914
+    #endif
915
+    constexpr float XZ_SKEW_FACTOR = (
916
+      #if defined(XZ_DIAG_AC) && defined(XZ_DIAG_BD) && defined(XZ_SIDE_AD)
917
+        _SKEW_FACTOR(XZ_DIAG_AC, XZ_DIAG_BD, XZ_SIDE_AD)
918
+      #else
919
+        0.0
920
+      #endif
921
+    );
922
+  #endif
923
+  #ifndef YZ_SKEW_FACTOR
924
+    constexpr float YZ_SKEW_FACTOR = (
925
+      #if defined(YZ_DIAG_AC) && defined(YZ_DIAG_BD) && defined(YZ_SIDE_AD)
926
+        _SKEW_FACTOR(YZ_DIAG_AC, YZ_DIAG_BD, YZ_SIDE_AD)
927
+      #else
928
+        0.0
929
+      #endif
930
+    );
931
+  #endif
932
+#endif // SKEW_CORRECTION
933
+
934
+/**
892 935
  * Heater & Fan Pausing
893 936
  */
894 937
 #if FAN_COUNT == 0

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

@@ -1483,4 +1483,18 @@ static_assert(COUNT(sanity_arr_3) <= XYZE_N, "DEFAULT_MAX_ACCELERATION has too m
1483 1483
   #error "LED_CONTROL_MENU requires an LCD controller."
1484 1484
 #endif
1485 1485
 
1486
+#if ENABLED(SKEW_CORRECTION)
1487
+  #if !defined(XY_SKEW_FACTOR) && !(defined(XY_DIAG_AC) && defined(XY_DIAG_BD) && defined(XY_SIDE_AD))
1488
+    #error "SKEW_CORRECTION requires XY_SKEW_FACTOR or XY_DIAG_AC, XY_DIAG_BD, XY_SIDE_AD."
1489
+  #endif
1490
+  #if ENABLED(SKEW_CORRECTION_FOR_Z)
1491
+    #if !defined(XZ_SKEW_FACTOR) && !(defined(XZ_DIAG_AC) && defined(XZ_DIAG_BD) && defined(XZ_SIDE_AD))
1492
+      #error "SKEW_CORRECTION requires XZ_SKEW_FACTOR or XZ_DIAG_AC, XZ_DIAG_BD, XZ_SIDE_AD."
1493
+    #endif
1494
+    #if !defined(YZ_SKEW_FACTOR) && !(defined(YZ_DIAG_AC) && defined(YZ_DIAG_BD) && defined(YZ_SIDE_AD))
1495
+      #error "SKEW_CORRECTION requires YZ_SKEW_FACTOR or YZ_DIAG_AC, YZ_DIAG_BD, YZ_SIDE_AD."
1496
+    #endif
1497
+  #endif
1498
+#endif
1499
+
1486 1500
 #endif // _SANITYCHECK_H_

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

@@ -698,6 +698,9 @@
698 698
 #ifndef MSG_ZPROBE_OUT
699 699
   #define MSG_ZPROBE_OUT                      _UxGT("Z probe out. bed")
700 700
 #endif
701
+#ifndef MSG_SKEW_FACTOR
702
+  #define MSG_SKEW_FACTOR                     _UxGT("Skew Factor")
703
+#endif
701 704
 #ifndef MSG_BLTOUCH
702 705
   #define MSG_BLTOUCH                         _UxGT("BLTouch")
703 706
 #endif

+ 69
- 4
Marlin/src/module/configuration_store.cpp View File

@@ -36,13 +36,13 @@
36 36
  *
37 37
  */
38 38
 
39
-#define EEPROM_VERSION "V45"
39
+#define EEPROM_VERSION "V46"
40 40
 
41 41
 // Change EEPROM version if these are changed:
42 42
 #define EEPROM_OFFSET 100
43 43
 
44 44
 /**
45
- * V45 EEPROM Layout:
45
+ * V46 EEPROM Layout:
46 46
  *
47 47
  *  100  Version                                    (char x4)
48 48
  *  104  EEPROM CRC16                               (uint16_t)
@@ -166,8 +166,13 @@
166 166
  * CNC_COORDINATE_SYSTEMS                           108 bytes
167 167
  *  602  G54-G59.3 coordinate_system                (float x 27)
168 168
  *
169
- *  710                                   Minimum end-point
170
- * 2239 (710 + 208 + 36 + 9 + 288 + 988)  Maximum end-point
169
+ * SKEW_CORRECTION:                                 12 bytes
170
+ *  710  M852 I    planner.xy_skew_factor           (float)
171
+ *  714  M852 J    planner.xz_skew_factor           (float)
172
+ *  718  M852 K    planner.yz_skew_factor           (float)
173
+ *
174
+ *  722                                   Minimum end-point
175
+ * 2251 (722 + 208 + 36 + 9 + 288 + 988)  Maximum end-point
171 176
  *
172 177
  * ========================================================================
173 178
  * meshes_begin (between max and min end-point, directly above)
@@ -633,6 +638,10 @@ void MarlinSettings::postprocess() {
633 638
       for (uint8_t q = 3; q--;) EEPROM_WRITE(dummyui32);
634 639
     #endif
635 640
 
641
+    //
642
+    // CNC Coordinate Systems
643
+    //
644
+
636 645
     #if ENABLED(CNC_COORDINATE_SYSTEMS)
637 646
       EEPROM_WRITE(coordinate_system); // 27 floats
638 647
     #else
@@ -640,6 +649,19 @@ void MarlinSettings::postprocess() {
640 649
       for (uint8_t q = 27; q--;) EEPROM_WRITE(dummy);
641 650
     #endif
642 651
 
652
+    //
653
+    // Skew correction factors
654
+    //
655
+
656
+    #if ENABLED(SKEW_CORRECTION)
657
+      EEPROM_WRITE(planner.xy_skew_factor);
658
+      EEPROM_WRITE(planner.xz_skew_factor);
659
+      EEPROM_WRITE(planner.yz_skew_factor);
660
+    #else
661
+      dummy = 0.0f;
662
+      for (uint8_t q = 3; q--;) EEPROM_WRITE(dummy);
663
+    #endif
664
+
643 665
     if (!eeprom_error) {
644 666
       #if ENABLED(EEPROM_CHITCHAT)
645 667
         const int eeprom_size = eeprom_index;
@@ -1078,6 +1100,23 @@ void MarlinSettings::postprocess() {
1078 1100
         for (uint8_t q = 27; q--;) EEPROM_READ(dummy);
1079 1101
       #endif
1080 1102
 
1103
+      //
1104
+      // Skew correction factors
1105
+      //
1106
+
1107
+      #if ENABLED(SKEW_CORRECTION_GCODE)
1108
+        EEPROM_READ(planner.xy_skew_factor);
1109
+        #if ENABLED(SKEW_CORRECTION_FOR_Z)
1110
+          EEPROM_READ(planner.xz_skew_factor);
1111
+          EEPROM_READ(planner.yz_skew_factor);
1112
+        #else
1113
+          EEPROM_READ(dummy);
1114
+          EEPROM_READ(dummy);
1115
+        #endif
1116
+      #else
1117
+        for (uint8_t q = 3; q--;) EEPROM_READ(dummy);
1118
+      #endif
1119
+
1081 1120
       if (working_crc == stored_crc) {
1082 1121
         postprocess();
1083 1122
         #if ENABLED(EEPROM_CHITCHAT)
@@ -1463,6 +1502,14 @@ void MarlinSettings::reset() {
1463 1502
     ubl.reset();
1464 1503
   #endif
1465 1504
 
1505
+  #if ENABLED(SKEW_CORRECTION_GCODE)
1506
+    planner.xy_skew_factor = XY_SKEW_FACTOR;
1507
+    #if ENABLED(SKEW_CORRECTION_FOR_Z)
1508
+      planner.xz_skew_factor = XZ_SKEW_FACTOR;
1509
+      planner.yz_skew_factor = YZ_SKEW_FACTOR;
1510
+    #endif
1511
+  #endif
1512
+
1466 1513
   postprocess();
1467 1514
 
1468 1515
   #if ENABLED(EEPROM_CHITCHAT)
@@ -1888,6 +1935,24 @@ void MarlinSettings::reset() {
1888 1935
     #endif
1889 1936
 
1890 1937
     /**
1938
+     * Bed Skew Correction
1939
+     */
1940
+    #if ENABLED(SKEW_CORRECTION_GCODE)
1941
+      if (!forReplay) {
1942
+        CONFIG_ECHO_START;
1943
+        SERIAL_ECHOLNPGM("Skew Factor: ");
1944
+      }
1945
+      CONFIG_ECHO_START;
1946
+      #if ENABLED(SKEW_CORRECTION_FOR_Z)
1947
+        SERIAL_ECHOPAIR("  M852 I", LINEAR_UNIT(planner.xy_skew_factor));
1948
+        SERIAL_ECHOPAIR(" J", LINEAR_UNIT(planner.xz_skew_factor));
1949
+        SERIAL_ECHOLNPAIR(" K", LINEAR_UNIT(planner.yz_skew_factor));
1950
+      #else
1951
+        SERIAL_ECHOLNPAIR("  M852 S", LINEAR_UNIT(planner.xy_skew_factor));
1952
+      #endif
1953
+    #endif
1954
+
1955
+    /**
1891 1956
      * TMC2130 stepper driver current
1892 1957
      */
1893 1958
     #if ENABLED(HAVE_TMC2130)

+ 81
- 34
Marlin/src/module/planner.cpp View File

@@ -135,6 +135,20 @@ float Planner::min_feedrate_mm_s,
135 135
   #endif
136 136
 #endif
137 137
 
138
+#if ENABLED(SKEW_CORRECTION)
139
+  #if ENABLED(SKEW_CORRECTION_GCODE)
140
+    // Initialized by settings.load()
141
+    float Planner::xy_skew_factor;
142
+    #if ENABLED(SKEW_CORRECTION_FOR_Z)
143
+      float Planner::xz_skew_factor, Planner::yz_skew_factor;
144
+    #else
145
+      constexpr float Planner::xz_skew_factor, Planner::yz_skew_factor;
146
+    #endif
147
+  #else
148
+    constexpr float Planner::xy_skew_factor, Planner::xz_skew_factor, Planner::yz_skew_factor;
149
+  #endif
150
+#endif
151
+
138 152
 #if ENABLED(AUTOTEMP)
139 153
   float Planner::autotemp_max = 250,
140 154
         Planner::autotemp_min = 210,
@@ -565,6 +579,19 @@ void Planner::calculate_volumetric_multipliers() {
565 579
    */
566 580
   void Planner::apply_leveling(float &rx, float &ry, float &rz) {
567 581
 
582
+    #if ENABLED(SKEW_CORRECTION)
583
+      if (WITHIN(rx, X_MIN_POS + 1, X_MAX_POS) && WITHIN(ry, Y_MIN_POS + 1, Y_MAX_POS)) {
584
+        const float tempry = ry - (rz * planner.yz_skew_factor),
585
+                    temprx = rx - (ry * planner.xy_skew_factor) - (rz * (planner.xz_skew_factor - (planner.xy_skew_factor * planner.yz_skew_factor)));
586
+        if (WITHIN(temprx, X_MIN_POS, X_MAX_POS) && WITHIN(tempry, Y_MIN_POS, Y_MAX_POS)) {
587
+          rx = temprx;
588
+          ry = tempry;
589
+        }
590
+        else
591
+          SERIAL_ECHOLN(MSG_SKEW_WARN);
592
+      }
593
+    #endif
594
+
568 595
     if (!leveling_active) return;
569 596
 
570 597
     #if ABL_PLANAR
@@ -611,45 +638,56 @@ void Planner::calculate_volumetric_multipliers() {
611 638
 
612 639
   void Planner::unapply_leveling(float raw[XYZ]) {
613 640
 
614
-    if (!leveling_active) return;
641
+    #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
642
+      const float fade_scaling_factor = fade_scaling_factor_for_z(raw[Z_AXIS]);
643
+    #else
644
+      constexpr float fade_scaling_factor = 1.0;
645
+    #endif
615 646
 
616
-    #if ABL_PLANAR
647
+    if (leveling_active && fade_scaling_factor) {
617 648
 
618
-      matrix_3x3 inverse = matrix_3x3::transpose(bed_level_matrix);
649
+      #if ABL_PLANAR
619 650
 
620
-      float dx = raw[X_AXIS] - (X_TILT_FULCRUM),
621
-            dy = raw[Y_AXIS] - (Y_TILT_FULCRUM);
651
+        matrix_3x3 inverse = matrix_3x3::transpose(bed_level_matrix);
622 652
 
623
-      apply_rotation_xyz(inverse, dx, dy, raw[Z_AXIS]);
653
+        float dx = raw[X_AXIS] - (X_TILT_FULCRUM),
654
+              dy = raw[Y_AXIS] - (Y_TILT_FULCRUM);
624 655
 
625
-      raw[X_AXIS] = dx + X_TILT_FULCRUM;
626
-      raw[Y_AXIS] = dy + Y_TILT_FULCRUM;
656
+        apply_rotation_xyz(inverse, dx, dy, raw[Z_AXIS]);
627 657
 
628
-    #else
658
+        raw[X_AXIS] = dx + X_TILT_FULCRUM;
659
+        raw[Y_AXIS] = dy + Y_TILT_FULCRUM;
629 660
 
630
-      #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
631
-        const float fade_scaling_factor = fade_scaling_factor_for_z(raw[Z_AXIS]);
632
-        if (!fade_scaling_factor) return;
633
-      #elif HAS_MESH
634
-        constexpr float fade_scaling_factor = 1.0;
635
-      #endif
661
+      #else // !ABL_PLANAR
636 662
 
637
-      raw[Z_AXIS] -= (
638
-        #if ENABLED(AUTO_BED_LEVELING_UBL)
639
-          ubl.get_z_correction(raw[X_AXIS], raw[Y_AXIS]) * fade_scaling_factor
640
-        #elif ENABLED(MESH_BED_LEVELING)
641
-          mbl.get_z(raw[X_AXIS], raw[Y_AXIS]
642
-            #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
643
-              , fade_scaling_factor
644
-            #endif
645
-          )
646
-        #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
647
-          bilinear_z_offset(raw) * fade_scaling_factor
648
-        #else
649
-          0
650
-        #endif
651
-      );
663
+        raw[Z_AXIS] -= (
664
+          #if ENABLED(AUTO_BED_LEVELING_UBL)
665
+            ubl.get_z_correction(raw[X_AXIS], raw[Y_AXIS]) * fade_scaling_factor
666
+          #elif ENABLED(MESH_BED_LEVELING)
667
+            mbl.get_z(raw[X_AXIS], raw[Y_AXIS]
668
+              #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
669
+                , fade_scaling_factor
670
+              #endif
671
+            )
672
+          #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
673
+            bilinear_z_offset(raw) * fade_scaling_factor
674
+          #else
675
+            0
676
+          #endif
677
+        );
678
+
679
+      #endif // !ABL_PLANAR
680
+    }
652 681
 
682
+    #if ENABLED(SKEW_CORRECTION)
683
+      if (WITHIN(raw[X_AXIS], X_MIN_POS, X_MAX_POS) && WITHIN(raw[Y_AXIS], Y_MIN_POS, Y_MAX_POS)) {
684
+        const float temprx = raw[X_AXIS] + raw[Y_AXIS] * planner.xy_skew_factor + raw[Z_AXIS] * planner.xz_skew_factor,
685
+                    tempry = raw[Y_AXIS] + raw[Z_AXIS] * planner.yz_skew_factor;
686
+        if (WITHIN(temprx, X_MIN_POS, X_MAX_POS) && WITHIN(tempry, Y_MIN_POS, Y_MAX_POS)) {
687
+          raw[X_AXIS] = temprx;
688
+          raw[Y_AXIS] = tempry;
689
+        }
690
+      }
653 691
     #endif
654 692
   }
655 693
 
@@ -658,13 +696,13 @@ void Planner::calculate_volumetric_multipliers() {
658 696
 /**
659 697
  * Planner::_buffer_line
660 698
  *
661
- * Add a new linear movement to the buffer.
699
+ * Add a new linear movement to the buffer in axis units.
662 700
  *
663 701
  * Leveling and kinematics should be applied ahead of calling this.
664 702
  *
665
- *  a,b,c,e     - target positions in mm or degrees
666
- *  fr_mm_s     - (target) speed of the move
667
- *  extruder    - target extruder
703
+ *  a,b,c,e   - target positions in mm and/or degrees
704
+ *  fr_mm_s   - (target) speed of the move
705
+ *  extruder  - target extruder
668 706
  */
669 707
 void Planner::_buffer_line(const float &a, const float &b, const float &c, const float &e, float fr_mm_s, const uint8_t extruder) {
670 708
 
@@ -713,6 +751,10 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
713 751
   SERIAL_EOL();
714 752
   //*/
715 753
 
754
+  // DRYRUN ignores all temperature constraints and assures that the extruder is instantly satisfied
755
+  if (DEBUGGING(DRYRUN))
756
+    position[E_AXIS] = target[E_AXIS];
757
+
716 758
   int32_t de = target[E_AXIS] - position[E_AXIS];
717 759
 
718 760
   #if ENABLED(PREVENT_COLD_EXTRUSION) || ENABLED(PREVENT_LENGTHY_EXTRUDE)
@@ -736,6 +778,10 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
736 778
     }
737 779
   #endif // PREVENT_COLD_EXTRUSION || PREVENT_LENGTHY_EXTRUDE
738 780
 
781
+  #if ENABLED(LIN_ADVANCE)
782
+    float de_float = de * steps_to_mm[E_AXIS_N];
783
+  #endif
784
+
739 785
   // Compute direction bit-mask for this block
740 786
   uint8_t dm = 0;
741 787
   #if CORE_IS_XY
@@ -1332,6 +1378,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
1332 1378
   previous_safe_speed = safe_speed;
1333 1379
 
1334 1380
   #if ENABLED(LIN_ADVANCE)
1381
+
1335 1382
     /**
1336 1383
      *
1337 1384
      * Use LIN_ADVANCE for blocks if all these are true:

+ 17
- 0
Marlin/src/module/planner.h View File

@@ -180,6 +180,23 @@ class Planner {
180 180
       static float extruder_advance_k, advance_ed_ratio;
181 181
     #endif
182 182
 
183
+    #if ENABLED(SKEW_CORRECTION)
184
+      #if ENABLED(SKEW_CORRECTION_GCODE)
185
+        static float xy_skew_factor;
186
+      #else
187
+        static constexpr float xy_skew_factor = XY_SKEW_FACTOR;
188
+      #endif
189
+      #if ENABLED(SKEW_CORRECTION_FOR_Z)
190
+        #if ENABLED(SKEW_CORRECTION_GCODE)
191
+          static float xz_skew_factor, yz_skew_factor;
192
+        #else
193
+          static constexpr float xz_skew_factor = XZ_SKEW_FACTOR, yz_skew_factor = YZ_SKEW_FACTOR;
194
+        #endif
195
+      #else
196
+        static constexpr float xz_skew_factor = 0, yz_skew_factor = 0;
197
+      #endif
198
+    #endif
199
+
183 200
   private:
184 201
 
185 202
     /**

Loading…
Cancel
Save