ソースを参照

Add M420 C to adjust the whole mesh (#10522)

Scott Lahteine 7年前
コミット
eef0248a1c
コミッターのメールアドレスに関連付けられたアカウントが存在しません

+ 2
- 2
Marlin/src/feature/bedlevel/ubl/ubl.h ファイルの表示

89
     #endif
89
     #endif
90
 
90
 
91
     static bool g29_parameter_parsing() _O0;
91
     static bool g29_parameter_parsing() _O0;
92
-    static void find_mean_mesh_height();
93
     static void shift_mesh_height();
92
     static void shift_mesh_height();
94
     static void probe_entire_mesh(const float &rx, const float &ry, const bool do_ubl_mesh_map, const bool stow_probe, const bool do_furthest) _O0;
93
     static void probe_entire_mesh(const float &rx, const float &ry, const bool do_ubl_mesh_map, const bool stow_probe, const bool do_furthest) _O0;
95
     static void tilt_mesh_based_on_3pts(const float &z1, const float &z2, const float &z3);
94
     static void tilt_mesh_based_on_3pts(const float &z1, const float &z2, const float &z3);
124
     static mesh_index_pair find_furthest_invalid_mesh_point() _O0;
123
     static mesh_index_pair find_furthest_invalid_mesh_point() _O0;
125
     static void reset();
124
     static void reset();
126
     static void invalidate();
125
     static void invalidate();
127
-    static void set_all_mesh_points_to_value(const float);
126
+    static void set_all_mesh_points_to_value(const float value);
127
+    static void adjust_mesh_to_mean(const float value);
128
     static bool sanity_check();
128
     static bool sanity_check();
129
 
129
 
130
     static void G29() _O0;                          // O0 for no optimization
130
     static void G29() _O0;                          // O0 for no optimization

+ 4
- 4
Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp ファイルの表示

544
           #endif
544
           #endif
545
           break;
545
           break;
546
 
546
 
547
-        case 5: find_mean_mesh_height(); break;
547
+        case 5: adjust_mesh_to_mean(g29_constant); break;
548
 
548
 
549
         case 6: shift_mesh_height(); break;
549
         case 6: shift_mesh_height(); break;
550
       }
550
       }
634
     return;
634
     return;
635
   }
635
   }
636
 
636
 
637
-  void unified_bed_leveling::find_mean_mesh_height() {
637
+  void unified_bed_leveling::adjust_mesh_to_mean(const float value) {
638
     float sum = 0.0;
638
     float sum = 0.0;
639
     int n = 0;
639
     int n = 0;
640
     for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
640
     for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
669
       for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
669
       for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
670
         for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
670
         for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
671
           if (!isnan(z_values[x][y]))
671
           if (!isnan(z_values[x][y]))
672
-            z_values[x][y] -= mean + g29_constant;
672
+            z_values[x][y] -= mean + value;
673
   }
673
   }
674
 
674
 
675
   void unified_bed_leveling::shift_mesh_height() {
675
   void unified_bed_leveling::shift_mesh_height() {
1081
       SERIAL_EOL();
1081
       SERIAL_EOL();
1082
     #endif
1082
     #endif
1083
 
1083
 
1084
-    find_mean_mesh_height();
1084
+    adjust_mesh_to_mean(g29_constant);
1085
 
1085
 
1086
     #if HAS_BED_PROBE
1086
     #if HAS_BED_PROBE
1087
       SERIAL_PROTOCOLPGM("zprobe_zoffset: ");
1087
       SERIAL_PROTOCOLPGM("zprobe_zoffset: ");

+ 78
- 9
Marlin/src/gcode/bedlevel/M420.cpp ファイルの表示

32
   #include "../../module/configuration_store.h"
32
   #include "../../module/configuration_store.h"
33
 #endif
33
 #endif
34
 
34
 
35
+//#define M420_C_USE_MEAN
36
+
35
 /**
37
 /**
36
  * M420: Enable/Disable Bed Leveling and/or set the Z fade height.
38
  * M420: Enable/Disable Bed Leveling and/or set the Z fade height.
37
  *
39
  *
43
  *
45
  *
44
  *   L[index]  Load UBL mesh from index (0 is default)
46
  *   L[index]  Load UBL mesh from index (0 is default)
45
  *   T[map]    0:Human-readable 1:CSV 2:"LCD" 4:Compact
47
  *   T[map]    0:Human-readable 1:CSV 2:"LCD" 4:Compact
48
+ *
49
+ * With mesh-based leveling only:
50
+ *
51
+ *   C         Center mesh on the mean of the lowest and highest
46
  */
52
  */
47
 void GcodeSuite::M420() {
53
 void GcodeSuite::M420() {
54
+  const bool seen_S = parser.seen('S');
55
+  bool to_enable = seen_S ? parser.value_bool() : planner.leveling_active;
56
+
57
+  // If disabling leveling do it right away
58
+  // (Don't disable for just M420 or M420 V)
59
+  if (seen_S && !to_enable) set_bed_leveling_enabled(false);
48
 
60
 
49
   const float oldpos[] = { current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] };
61
   const float oldpos[] = { current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] };
50
 
62
 
53
     // L to load a mesh from the EEPROM
65
     // L to load a mesh from the EEPROM
54
     if (parser.seen('L')) {
66
     if (parser.seen('L')) {
55
 
67
 
68
+      set_bed_leveling_enabled(false);
69
+
56
       #if ENABLED(EEPROM_SETTINGS)
70
       #if ENABLED(EEPROM_SETTINGS)
57
         const int8_t storage_slot = parser.has_value() ? parser.value_int() : ubl.storage_slot;
71
         const int8_t storage_slot = parser.has_value() ? parser.value_int() : ubl.storage_slot;
58
         const int16_t a = settings.calc_num_meshes();
72
         const int16_t a = settings.calc_num_meshes();
88
 
102
 
89
   #endif // AUTO_BED_LEVELING_UBL
103
   #endif // AUTO_BED_LEVELING_UBL
90
 
104
 
105
+  #if HAS_MESH
106
+
107
+    #if ENABLED(MESH_BED_LEVELING)
108
+      #define Z_VALUES(X,Y) mbl.z_values[X][Y]
109
+    #else
110
+      #define Z_VALUES(X,Y) z_values[X][Y]
111
+    #endif
112
+
113
+    // Subtract the given value or the mean from all mesh values
114
+    if (leveling_is_valid() && parser.seen('C')) {
115
+      const float cval = parser.value_float();
116
+      #if ENABLED(AUTO_BED_LEVELING_UBL)
117
+
118
+        set_bed_leveling_enabled(false);
119
+        ubl.adjust_mesh_to_mean(cval);
120
+
121
+      #else
122
+
123
+        #if ENABLED(M420_C_USE_MEAN)
124
+
125
+          // Get the sum and average of all mesh values
126
+          float mesh_sum = 0;
127
+          for (uint8_t x = GRID_MAX_POINTS_X; x--;)
128
+            for (uint8_t y = GRID_MAX_POINTS_Y; y--;)
129
+              mesh_sum += Z_VALUES(x, y);
130
+          const float zmean = mesh_sum / float(GRID_MAX_POINTS);
131
+
132
+        #else
133
+
134
+          // Find the low and high mesh values
135
+          float lo_val = 100, hi_val = -100;
136
+          for (uint8_t x = GRID_MAX_POINTS_X; x--;)
137
+            for (uint8_t y = GRID_MAX_POINTS_Y; y--;) {
138
+              const float z = Z_VALUES(x, y);
139
+              NOMORE(lo_val, z);
140
+              NOLESS(hi_val, z);
141
+            }
142
+          // Take the mean of the lowest and highest
143
+          const float zmean = (lo_val + hi_val) / 2.0 + cval;
144
+
145
+        #endif
146
+
147
+        // If not very close to 0, adjust the mesh
148
+        if (!NEAR_ZERO(zmean)) {
149
+          set_bed_leveling_enabled(false);
150
+          // Subtract the mean from all values
151
+          for (uint8_t x = GRID_MAX_POINTS_X; x--;)
152
+            for (uint8_t y = GRID_MAX_POINTS_Y; y--;)
153
+              Z_VALUES(x, y) -= zmean;
154
+          #if ENABLED(ABL_BILINEAR_SUBDIVISION)
155
+            bed_level_virt_interpolate();
156
+          #endif
157
+        }
158
+
159
+      #endif
160
+    }
161
+
162
+  #endif // HAS_MESH
163
+
91
   // V to print the matrix or mesh
164
   // V to print the matrix or mesh
92
   if (parser.seen('V')) {
165
   if (parser.seen('V')) {
93
     #if ABL_PLANAR
166
     #if ABL_PLANAR
111
     if (parser.seen('Z')) set_z_fade_height(parser.value_linear_units(), false);
184
     if (parser.seen('Z')) set_z_fade_height(parser.value_linear_units(), false);
112
   #endif
185
   #endif
113
 
186
 
114
-  bool to_enable = false;
115
-  if (parser.seen('S')) {
116
-    to_enable = parser.value_bool();
117
-    set_bed_leveling_enabled(to_enable);
118
-  }
119
-
120
-  const bool new_status = planner.leveling_active;
187
+  // Enable leveling if specified, or if previously active
188
+  set_bed_leveling_enabled(to_enable);
121
 
189
 
122
-  if (to_enable && !new_status) {
190
+  // Error if leveling failed to enable or reenable
191
+  if (to_enable && !planner.leveling_active) {
123
     SERIAL_ERROR_START();
192
     SERIAL_ERROR_START();
124
     SERIAL_ERRORLNPGM(MSG_ERR_M420_FAILED);
193
     SERIAL_ERRORLNPGM(MSG_ERR_M420_FAILED);
125
   }
194
   }
126
 
195
 
127
   SERIAL_ECHO_START();
196
   SERIAL_ECHO_START();
128
-  SERIAL_ECHOLNPAIR("Bed Leveling ", new_status ? MSG_ON : MSG_OFF);
197
+  SERIAL_ECHOLNPAIR("Bed Leveling ", planner.leveling_active ? MSG_ON : MSG_OFF);
129
 
198
 
130
   #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
199
   #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
131
     SERIAL_ECHO_START();
200
     SERIAL_ECHO_START();

読み込み中…
キャンセル
保存