소스 검색

Fix up bed leveling code

- Init `zprobe_zoffset`
- Remove `current_position[Z_AXIS] = zprobe_zoffset` lines from the
`set_bed_level_equation_*` functions
- Apply standards to `mesh_bed_leveling` files
- Document `MESH_BED_LEVELING`
Scott Lahteine 9 년 전
부모
커밋
96b5da7198
4개의 변경된 파일181개의 추가작업 그리고 192개의 파일을 삭제
  1. 1
    1
      Marlin/ConfigurationStore.cpp
  2. 142
    145
      Marlin/Marlin_main.cpp
  3. 9
    13
      Marlin/mesh_bed_leveling.cpp
  4. 29
    33
      Marlin/mesh_bed_leveling.h

+ 1
- 1
Marlin/ConfigurationStore.cpp 파일 보기

@@ -11,7 +11,7 @@
11 11
  *  max_acceleration_units_per_sq_second (x4)
12 12
  *  acceleration
13 13
  *  retract_acceleration
14
- *  travel_aceeleration
14
+ *  travel_acceleration
15 15
  *  minimumfeedrate
16 16
  *  mintravelfeedrate
17 17
  *  minsegmenttime

+ 142
- 145
Marlin/Marlin_main.cpp 파일 보기

@@ -255,7 +255,7 @@ float home_offset[3] = { 0, 0, 0 };
255 255
 float min_pos[3] = { X_MIN_POS, Y_MIN_POS, Z_MIN_POS };
256 256
 float max_pos[3] = { X_MAX_POS, Y_MAX_POS, Z_MAX_POS };
257 257
 bool axis_known_position[3] = { false, false, false };
258
-float zprobe_zoffset;
258
+float zprobe_zoffset = -Z_PROBE_OFFSET_FROM_EXTRUDER;
259 259
 
260 260
 // Extruder offset
261 261
 #if EXTRUDERS > 1
@@ -1092,9 +1092,6 @@ static void set_bed_level_equation_lsq(double *plane_equation_coefficients)
1092 1092
     current_position[Y_AXIS] = corrected_position.y;
1093 1093
     current_position[Z_AXIS] = corrected_position.z;
1094 1094
 
1095
-    // put the bed at 0 so we don't go below it.
1096
-    current_position[Z_AXIS] = zprobe_zoffset; // in the lsq we reach here after raising the extruder due to the loop structure
1097
-
1098 1095
     plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
1099 1096
 }
1100 1097
 #endif
@@ -1121,9 +1118,6 @@ static void set_bed_level_equation_3pts(float z_at_pt_1, float z_at_pt_2, float
1121 1118
     current_position[Y_AXIS] = corrected_position.y;
1122 1119
     current_position[Z_AXIS] = corrected_position.z;
1123 1120
 
1124
-    // put the bed at 0 so we don't go below it.
1125
-    current_position[Z_AXIS] = zprobe_zoffset;
1126
-
1127 1121
     plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
1128 1122
 
1129 1123
 }
@@ -2010,8 +2004,19 @@ inline void gcode_G28() {
2010 2004
   endstops_hit_on_purpose();
2011 2005
 }
2012 2006
 
2013
-#if defined(MESH_BED_LEVELING)
2007
+#ifdef MESH_BED_LEVELING
2014 2008
 
2009
+  /**
2010
+   * G29: Mesh-based Z-Probe, probes a grid and produces a
2011
+   *      mesh to compensate for variable bed height
2012
+   *
2013
+   * Parameters With MESH_BED_LEVELING:
2014
+   *
2015
+   *  S0 Produce a mesh report
2016
+   *  S1 Start probing mesh points
2017
+   *  S2 Probe the next mesh point
2018
+   *
2019
+   */
2015 2020
   inline void gcode_G29() {
2016 2021
     static int probe_point = -1;
2017 2022
     int state = 0;
@@ -2053,7 +2058,7 @@ inline void gcode_G28() {
2053 2058
     } else if (state == 2) { // Goto next point
2054 2059
 
2055 2060
       if (probe_point < 0) {
2056
-        SERIAL_PROTOCOLPGM("Mesh probing not started.\n");
2061
+        SERIAL_PROTOCOLPGM("Start mesh probing with \"G29 S1\" first.\n");
2057 2062
         return;
2058 2063
       }
2059 2064
       int ix, iy;
@@ -2063,16 +2068,14 @@ inline void gcode_G28() {
2063 2068
       } else {
2064 2069
         ix = (probe_point-1) % MESH_NUM_X_POINTS;
2065 2070
         iy = (probe_point-1) / MESH_NUM_X_POINTS;
2066
-        if (iy&1) { // Zig zag
2067
-          ix = (MESH_NUM_X_POINTS - 1) - ix;
2068
-        }
2071
+        if (iy & 1) ix = (MESH_NUM_X_POINTS - 1) - ix; // zig-zag
2069 2072
         mbl.set_z(ix, iy, current_position[Z_AXIS]);
2070 2073
         current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
2071 2074
         plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], homing_feedrate[X_AXIS]/60, active_extruder);
2072 2075
         st_synchronize();
2073 2076
       }
2074
-      if (probe_point == MESH_NUM_X_POINTS*MESH_NUM_Y_POINTS) {
2075
-        SERIAL_PROTOCOLPGM("Mesh done.\n");
2077
+      if (probe_point == MESH_NUM_X_POINTS * MESH_NUM_Y_POINTS) {
2078
+        SERIAL_PROTOCOLPGM("Mesh probing done.\n");
2076 2079
         probe_point = -1;
2077 2080
         mbl.active = 1;
2078 2081
         enquecommands_P(PSTR("G28"));
@@ -2080,9 +2083,7 @@ inline void gcode_G28() {
2080 2083
       }
2081 2084
       ix = probe_point % MESH_NUM_X_POINTS;
2082 2085
       iy = probe_point / MESH_NUM_X_POINTS;
2083
-      if (iy&1) { // Zig zag
2084
-        ix = (MESH_NUM_X_POINTS - 1) - ix;
2085
-      }
2086
+      if (iy & 1) ix = (MESH_NUM_X_POINTS - 1) - ix; // zig-zag
2086 2087
       current_position[X_AXIS] = mbl.get_x(ix);
2087 2088
       current_position[Y_AXIS] = mbl.get_y(iy);
2088 2089
       plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], homing_feedrate[X_AXIS]/60, active_extruder);
@@ -2091,9 +2092,7 @@ inline void gcode_G28() {
2091 2092
     }
2092 2093
   }
2093 2094
 
2094
-#endif
2095
-
2096
-#ifdef ENABLE_AUTO_BED_LEVELING
2095
+#elif defined(ENABLE_AUTO_BED_LEVELING)
2097 2096
 
2098 2097
   /**
2099 2098
    * G29: Detailed Z-Probe, probes the bed at 3 or more points.
@@ -2154,9 +2153,9 @@ inline void gcode_G28() {
2154 2153
 
2155 2154
     #ifdef AUTO_BED_LEVELING_GRID
2156 2155
 
2157
-    #ifndef DELTA
2158
-      bool do_topography_map = verbose_level > 2 || code_seen('T') || code_seen('t');
2159
-    #endif
2156
+      #ifndef DELTA
2157
+        bool do_topography_map = verbose_level > 2 || code_seen('T') || code_seen('t');
2158
+      #endif
2160 2159
 
2161 2160
       if (verbose_level > 0)
2162 2161
         SERIAL_PROTOCOLPGM("G29 Auto Bed Leveling\n");
@@ -2210,7 +2209,7 @@ inline void gcode_G28() {
2210 2209
 
2211 2210
     #ifdef Z_PROBE_SLED
2212 2211
       dock_sled(false); // engage (un-dock) the probe
2213
-    #elif defined(Z_PROBE_ALLEN_KEY)
2212
+    #elif defined(Z_PROBE_ALLEN_KEY) //|| defined(SERVO_LEVELING)
2214 2213
       engage_z_probe();
2215 2214
     #endif
2216 2215
 
@@ -2218,19 +2217,18 @@ inline void gcode_G28() {
2218 2217
 
2219 2218
     #ifdef DELTA
2220 2219
       reset_bed_level();
2221
-    #else
2222
-
2223
-    // make sure the bed_level_rotation_matrix is identity or the planner will get it incorectly
2224
-    //vector_3 corrected_position = plan_get_position_mm();
2225
-    //corrected_position.debug("position before G29");
2226
-    plan_bed_level_matrix.set_to_identity();
2227
-    vector_3 uncorrected_position = plan_get_position();
2228
-    //uncorrected_position.debug("position during G29");
2229
-    current_position[X_AXIS] = uncorrected_position.x;
2230
-    current_position[Y_AXIS] = uncorrected_position.y;
2231
-    current_position[Z_AXIS] = uncorrected_position.z;
2232
-    plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
2233
-  #endif
2220
+    #else //!DELTA
2221
+      // make sure the bed_level_rotation_matrix is identity or the planner will get it wrong
2222
+      //vector_3 corrected_position = plan_get_position_mm();
2223
+      //corrected_position.debug("position before G29");
2224
+      plan_bed_level_matrix.set_to_identity();
2225
+      vector_3 uncorrected_position = plan_get_position();
2226
+      //uncorrected_position.debug("position during G29");
2227
+      current_position[X_AXIS] = uncorrected_position.x;
2228
+      current_position[Y_AXIS] = uncorrected_position.y;
2229
+      current_position[Z_AXIS] = uncorrected_position.z;
2230
+      plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
2231
+    #endif //!DELTA
2234 2232
 
2235 2233
     setup_for_endstop_move();
2236 2234
 
@@ -2242,26 +2240,24 @@ inline void gcode_G28() {
2242 2240
       const int xGridSpacing = (right_probe_bed_position - left_probe_bed_position) / (auto_bed_leveling_grid_points-1);
2243 2241
       const int yGridSpacing = (back_probe_bed_position - front_probe_bed_position) / (auto_bed_leveling_grid_points-1);
2244 2242
 
2245
-    #ifndef DELTA
2246
-      // solve the plane equation ax + by + d = z
2247
-      // A is the matrix with rows [x y 1] for all the probed points
2248
-      // B is the vector of the Z positions
2249
-      // the normal vector to the plane is formed by the coefficients of the plane equation in the standard form, which is Vx*x+Vy*y+Vz*z+d = 0
2250
-      // so Vx = -a Vy = -b Vz = 1 (we want the vector facing towards positive Z
2251
-
2252
-      int abl2 = auto_bed_leveling_grid_points * auto_bed_leveling_grid_points;
2253
-
2254
-      double eqnAMatrix[abl2 * 3], // "A" matrix of the linear system of equations
2255
-             eqnBVector[abl2],     // "B" vector of Z points
2256
-             mean = 0.0;
2257
-
2258
-    #else
2259
-      delta_grid_spacing[0] = xGridSpacing;
2260
-      delta_grid_spacing[1] = yGridSpacing;
2261
-
2262
-      float z_offset = Z_PROBE_OFFSET_FROM_EXTRUDER;
2263
-      if (code_seen(axis_codes[Z_AXIS])) z_offset += code_value();
2264
-    #endif
2243
+      #ifdef DELTA
2244
+        delta_grid_spacing[0] = xGridSpacing;
2245
+        delta_grid_spacing[1] = yGridSpacing;
2246
+        float z_offset = Z_PROBE_OFFSET_FROM_EXTRUDER;
2247
+        if (code_seen(axis_codes[Z_AXIS])) z_offset += code_value();
2248
+      #else // !DELTA
2249
+        // solve the plane equation ax + by + d = z
2250
+        // A is the matrix with rows [x y 1] for all the probed points
2251
+        // B is the vector of the Z positions
2252
+        // the normal vector to the plane is formed by the coefficients of the plane equation in the standard form, which is Vx*x+Vy*y+Vz*z+d = 0
2253
+        // so Vx = -a Vy = -b Vz = 1 (we want the vector facing towards positive Z
2254
+
2255
+        int abl2 = auto_bed_leveling_grid_points * auto_bed_leveling_grid_points;
2256
+
2257
+        double eqnAMatrix[abl2 * 3], // "A" matrix of the linear system of equations
2258
+               eqnBVector[abl2],     // "B" vector of Z points
2259
+               mean = 0.0;
2260
+      #endif // !DELTA
2265 2261
 
2266 2262
       int probePointCounter = 0;
2267 2263
       bool zig = true;
@@ -2294,12 +2290,12 @@ inline void gcode_G28() {
2294 2290
           float measured_z,
2295 2291
                 z_before = probePointCounter == 0 ? Z_RAISE_BEFORE_PROBING : current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS;
2296 2292
 
2297
-        #ifdef DELTA
2298
-          // Avoid probing the corners (outside the round or hexagon print surface) on a delta printer.
2299
-          float distance_from_center = sqrt(xProbe*xProbe + yProbe*yProbe);
2300
-          if (distance_from_center > DELTA_PROBABLE_RADIUS)
2301
-            continue;
2302
-        #endif //DELTA
2293
+          #ifdef DELTA
2294
+            // Avoid probing the corners (outside the round or hexagon print surface) on a delta printer.
2295
+            float distance_from_center = sqrt(xProbe*xProbe + yProbe*yProbe);
2296
+            if (distance_from_center > DELTA_PROBABLE_RADIUS)
2297
+              continue;
2298
+          #endif //DELTA
2303 2299
 
2304 2300
           // Enhanced G29 - Do not retract servo between probes
2305 2301
           ProbeAction act;
@@ -2316,16 +2312,16 @@ inline void gcode_G28() {
2316 2312
 
2317 2313
           measured_z = probe_pt(xProbe, yProbe, z_before, act, verbose_level);
2318 2314
 
2319
-        #ifndef DELTA
2320
-          mean += measured_z;
2315
+          #ifndef DELTA
2316
+            mean += measured_z;
2321 2317
 
2322
-          eqnBVector[probePointCounter] = measured_z;
2323
-          eqnAMatrix[probePointCounter + 0 * abl2] = xProbe;
2324
-          eqnAMatrix[probePointCounter + 1 * abl2] = yProbe;
2325
-          eqnAMatrix[probePointCounter + 2 * abl2] = 1;
2326
-        #else
2327
-          bed_level[xCount][yCount] = measured_z + z_offset;
2328
-        #endif
2318
+            eqnBVector[probePointCounter] = measured_z;
2319
+            eqnAMatrix[probePointCounter + 0 * abl2] = xProbe;
2320
+            eqnAMatrix[probePointCounter + 1 * abl2] = yProbe;
2321
+            eqnAMatrix[probePointCounter + 2 * abl2] = 1;
2322
+          #else
2323
+            bed_level[xCount][yCount] = measured_z + z_offset;
2324
+          #endif
2329 2325
 
2330 2326
           probePointCounter++;
2331 2327
         } //xProbe
@@ -2333,60 +2329,61 @@ inline void gcode_G28() {
2333 2329
 
2334 2330
       clean_up_after_endstop_move();
2335 2331
 
2336
-    #ifndef DELTA
2337
-      // solve lsq problem
2338
-      double *plane_equation_coefficients = qr_solve(abl2, 3, eqnAMatrix, eqnBVector);
2339
-
2340
-      mean /= abl2;
2341
-
2342
-      if (verbose_level) {
2343
-        SERIAL_PROTOCOLPGM("Eqn coefficients: a: ");
2344
-        SERIAL_PROTOCOL_F(plane_equation_coefficients[0], 8);
2345
-        SERIAL_PROTOCOLPGM(" b: ");
2346
-        SERIAL_PROTOCOL_F(plane_equation_coefficients[1], 8);
2347
-        SERIAL_PROTOCOLPGM(" d: ");
2348
-        SERIAL_PROTOCOL_F(plane_equation_coefficients[2], 8);
2349
-        SERIAL_EOL;
2350
-        if (verbose_level > 2) {
2351
-          SERIAL_PROTOCOLPGM("Mean of sampled points: ");
2352
-          SERIAL_PROTOCOL_F(mean, 8);
2332
+      #ifdef DELTA
2333
+        extrapolate_unprobed_bed_level();
2334
+        print_bed_level();
2335
+      #else // !DELTA
2336
+        // solve lsq problem
2337
+        double *plane_equation_coefficients = qr_solve(abl2, 3, eqnAMatrix, eqnBVector);
2338
+
2339
+        mean /= abl2;
2340
+
2341
+        if (verbose_level) {
2342
+          SERIAL_PROTOCOLPGM("Eqn coefficients: a: ");
2343
+          SERIAL_PROTOCOL_F(plane_equation_coefficients[0], 8);
2344
+          SERIAL_PROTOCOLPGM(" b: ");
2345
+          SERIAL_PROTOCOL_F(plane_equation_coefficients[1], 8);
2346
+          SERIAL_PROTOCOLPGM(" d: ");
2347
+          SERIAL_PROTOCOL_F(plane_equation_coefficients[2], 8);
2353 2348
           SERIAL_EOL;
2349
+          if (verbose_level > 2) {
2350
+            SERIAL_PROTOCOLPGM("Mean of sampled points: ");
2351
+            SERIAL_PROTOCOL_F(mean, 8);
2352
+            SERIAL_EOL;
2353
+          }
2354 2354
         }
2355
-      }
2356 2355
 
2357
-      // Show the Topography map if enabled
2358
-      if (do_topography_map) {
2359
-
2360
-        SERIAL_PROTOCOLPGM(" \nBed Height Topography: \n");
2361
-        SERIAL_PROTOCOLPGM("+-----------+\n");
2362
-        SERIAL_PROTOCOLPGM("|...Back....|\n");
2363
-        SERIAL_PROTOCOLPGM("|Left..Right|\n");
2364
-        SERIAL_PROTOCOLPGM("|...Front...|\n");
2365
-        SERIAL_PROTOCOLPGM("+-----------+\n");
2366
-
2367
-        for (int yy = auto_bed_leveling_grid_points - 1; yy >= 0; yy--) {
2368
-          for (int xx = 0; xx < auto_bed_leveling_grid_points; xx++) {
2369
-            int ind = yy * auto_bed_leveling_grid_points + xx;
2370
-            float diff = eqnBVector[ind] - mean;
2371
-            if (diff >= 0.0)
2372
-              SERIAL_PROTOCOLPGM(" +");   // Include + for column alignment
2373
-            else
2374
-              SERIAL_PROTOCOLPGM(" ");
2375
-            SERIAL_PROTOCOL_F(diff, 5);
2376
-          } // xx
2356
+        // Show the Topography map if enabled
2357
+        if (do_topography_map) {
2358
+
2359
+          SERIAL_PROTOCOLPGM(" \nBed Height Topography: \n");
2360
+          SERIAL_PROTOCOLPGM("+-----------+\n");
2361
+          SERIAL_PROTOCOLPGM("|...Back....|\n");
2362
+          SERIAL_PROTOCOLPGM("|Left..Right|\n");
2363
+          SERIAL_PROTOCOLPGM("|...Front...|\n");
2364
+          SERIAL_PROTOCOLPGM("+-----------+\n");
2365
+
2366
+          for (int yy = auto_bed_leveling_grid_points - 1; yy >= 0; yy--) {
2367
+            for (int xx = 0; xx < auto_bed_leveling_grid_points; xx++) {
2368
+              int ind = yy * auto_bed_leveling_grid_points + xx;
2369
+              float diff = eqnBVector[ind] - mean;
2370
+              if (diff >= 0.0)
2371
+                SERIAL_PROTOCOLPGM(" +");   // Include + for column alignment
2372
+              else
2373
+                SERIAL_PROTOCOLPGM(" ");
2374
+              SERIAL_PROTOCOL_F(diff, 5);
2375
+            } // xx
2376
+            SERIAL_EOL;
2377
+          } // yy
2377 2378
           SERIAL_EOL;
2378
-        } // yy
2379
-        SERIAL_EOL;
2380 2379
 
2381
-      } //do_topography_map
2380
+        } //do_topography_map
2382 2381
 
2383 2382
 
2384
-      set_bed_level_equation_lsq(plane_equation_coefficients);
2385
-      free(plane_equation_coefficients);
2386
-    #else
2387
-      extrapolate_unprobed_bed_level();
2388
-      print_bed_level();
2389
-    #endif
2383
+        set_bed_level_equation_lsq(plane_equation_coefficients);
2384
+        free(plane_equation_coefficients);
2385
+
2386
+      #endif // !DELTA
2390 2387
 
2391 2388
     #else // !AUTO_BED_LEVELING_GRID
2392 2389
 
@@ -2409,33 +2406,33 @@ inline void gcode_G28() {
2409 2406
 
2410 2407
     #endif // !AUTO_BED_LEVELING_GRID
2411 2408
 
2412
-  #ifndef DELTA
2413
-    if (verbose_level > 0)
2414
-      plan_bed_level_matrix.debug(" \n\nBed Level Correction Matrix:");
2415
-
2416
-    // Correct the Z height difference from z-probe position and hotend tip position.
2417
-    // The Z height on homing is measured by Z-Probe, but the probe is quite far from the hotend.
2418
-    // When the bed is uneven, this height must be corrected.
2419
-    real_z = float(st_get_position(Z_AXIS)) / axis_steps_per_unit[Z_AXIS];  //get the real Z (since the auto bed leveling is already correcting the plane)
2420
-    x_tmp = current_position[X_AXIS] + X_PROBE_OFFSET_FROM_EXTRUDER;
2421
-    y_tmp = current_position[Y_AXIS] + Y_PROBE_OFFSET_FROM_EXTRUDER;
2422
-    z_tmp = current_position[Z_AXIS];
2423
-
2424
-    apply_rotation_xyz(plan_bed_level_matrix, x_tmp, y_tmp, z_tmp);         //Apply the correction sending the probe offset
2425
-    current_position[Z_AXIS] = z_tmp - real_z + current_position[Z_AXIS];   //The difference is added to current position and sent to planner.
2426
-    plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
2427
-  #endif
2409
+    #ifndef DELTA
2410
+      if (verbose_level > 0)
2411
+        plan_bed_level_matrix.debug(" \n\nBed Level Correction Matrix:");
2412
+
2413
+      // Correct the Z height difference from z-probe position and hotend tip position.
2414
+      // The Z height on homing is measured by Z-Probe, but the probe is quite far from the hotend.
2415
+      // When the bed is uneven, this height must be corrected.
2416
+      real_z = float(st_get_position(Z_AXIS)) / axis_steps_per_unit[Z_AXIS];  //get the real Z (since the auto bed leveling is already correcting the plane)
2417
+      x_tmp = current_position[X_AXIS] + X_PROBE_OFFSET_FROM_EXTRUDER;
2418
+      y_tmp = current_position[Y_AXIS] + Y_PROBE_OFFSET_FROM_EXTRUDER;
2419
+      z_tmp = current_position[Z_AXIS];
2420
+
2421
+      apply_rotation_xyz(plan_bed_level_matrix, x_tmp, y_tmp, z_tmp);         //Apply the correction sending the probe offset
2422
+      current_position[Z_AXIS] = z_tmp - real_z + current_position[Z_AXIS];   //The difference is added to current position and sent to planner.
2423
+      plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
2424
+    #endif
2428 2425
 
2429
-  #ifdef Z_PROBE_SLED
2430
-    dock_sled(true, -SLED_DOCKING_OFFSET); // dock the probe, correcting for over-travel
2431
-  #elif defined(Z_PROBE_ALLEN_KEY)
2432
-    retract_z_probe();
2433
-  #endif
2434
-    
2435
-  #ifdef Z_PROBE_END_SCRIPT
2436
-    enquecommands_P(PSTR(Z_PROBE_END_SCRIPT));
2437
-    st_synchronize();
2438
-  #endif
2426
+    #ifdef Z_PROBE_SLED
2427
+      dock_sled(true, -SLED_DOCKING_OFFSET); // dock the probe, correcting for over-travel
2428
+    #elif defined(Z_PROBE_ALLEN_KEY) //|| defined(SERVO_LEVELING)
2429
+      retract_z_probe();
2430
+    #endif
2431
+
2432
+    #ifdef Z_PROBE_END_SCRIPT
2433
+      enquecommands_P(PSTR(Z_PROBE_END_SCRIPT));
2434
+      st_synchronize();
2435
+    #endif
2439 2436
   }
2440 2437
 
2441 2438
   #ifndef Z_PROBE_SLED

+ 9
- 13
Marlin/mesh_bed_leveling.cpp 파일 보기

@@ -1,20 +1,16 @@
1 1
 #include "mesh_bed_leveling.h"
2 2
 
3
-#if defined(MESH_BED_LEVELING)
3
+#ifdef MESH_BED_LEVELING
4 4
 
5
-mesh_bed_leveling mbl;
5
+  mesh_bed_leveling mbl;
6 6
 
7
-mesh_bed_leveling::mesh_bed_leveling() {
8
-    reset();
9
-}
10
-    
11
-void mesh_bed_leveling::reset() {
12
-    for (int y=0; y<MESH_NUM_Y_POINTS; y++) {
13
-        for (int x=0; x<MESH_NUM_X_POINTS; x++) {
14
-            z_values[y][x] = 0;
15
-        }
16
-    }
7
+  mesh_bed_leveling::mesh_bed_leveling() { reset(); }
8
+      
9
+  void mesh_bed_leveling::reset() {
17 10
     active = 0;
18
-}
11
+    for (int y = 0; y < MESH_NUM_Y_POINTS; y++)
12
+      for (int x = 0; x < MESH_NUM_X_POINTS; x++)
13
+        z_values[y][x] = 0;
14
+  }
19 15
 
20 16
 #endif  // MESH_BED_LEVELING

+ 29
- 33
Marlin/mesh_bed_leveling.h 파일 보기

@@ -2,11 +2,11 @@
2 2
 
3 3
 #if defined(MESH_BED_LEVELING)
4 4
 
5
-#define MESH_X_DIST ((MESH_MAX_X - MESH_MIN_X)/(MESH_NUM_X_POINTS - 1))
6
-#define MESH_Y_DIST ((MESH_MAX_Y - MESH_MIN_Y)/(MESH_NUM_Y_POINTS - 1))
5
+  #define MESH_X_DIST ((MESH_MAX_X - MESH_MIN_X)/(MESH_NUM_X_POINTS - 1))
6
+  #define MESH_Y_DIST ((MESH_MAX_Y - MESH_MIN_Y)/(MESH_NUM_Y_POINTS - 1))
7 7
 
8
-class mesh_bed_leveling {
9
-public:
8
+  class mesh_bed_leveling {
9
+  public:
10 10
     uint8_t active;
11 11
     float z_values[MESH_NUM_Y_POINTS][MESH_NUM_X_POINTS];
12 12
     
@@ -14,48 +14,44 @@ public:
14 14
     
15 15
     void reset();
16 16
     
17
-    float get_x(int i) { return MESH_MIN_X + MESH_X_DIST*i; }
18
-    float get_y(int i) { return MESH_MIN_Y + MESH_Y_DIST*i; }
17
+    float get_x(int i) { return MESH_MIN_X + MESH_X_DIST * i; }
18
+    float get_y(int i) { return MESH_MIN_Y + MESH_Y_DIST * i; }
19 19
     void set_z(int ix, int iy, float z) { z_values[iy][ix] = z; }
20 20
     
21 21
     int select_x_index(float x) {
22
-        int i = 1;
23
-        while (x > get_x(i) && i < MESH_NUM_X_POINTS-1) {
24
-            i++;
25
-        }
26
-        return i-1;
22
+      int i = 1;
23
+      while (x > get_x(i) && i < MESH_NUM_X_POINTS-1) i++;
24
+      return i - 1;
27 25
     }
28 26
     
29 27
     int select_y_index(float y) {
30
-        int i = 1;
31
-        while (y > get_y(i) && i < MESH_NUM_Y_POINTS-1) {
32
-            i++;
33
-        }
34
-        return i-1;
28
+      int i = 1;
29
+      while (y > get_y(i) && i < MESH_NUM_Y_POINTS - 1) i++;
30
+      return i - 1;
35 31
     }
36 32
     
37 33
     float calc_z0(float a0, float a1, float z1, float a2, float z2) {
38
-        float delta_z = (z2 - z1)/(a2 - a1);
39
-        float delta_a = a0 - a1;
40
-        return z1 + delta_a * delta_z;
34
+      float delta_z = (z2 - z1)/(a2 - a1);
35
+      float delta_a = a0 - a1;
36
+      return z1 + delta_a * delta_z;
41 37
     }
42 38
     
43 39
     float get_z(float x0, float y0) {
44
-        int x_index = select_x_index(x0);
45
-        int y_index = select_y_index(y0);
46
-        float z1 = calc_z0(x0,
47
-                           get_x(x_index), z_values[y_index][x_index],
48
-                           get_x(x_index+1), z_values[y_index][x_index+1]);
49
-        float z2 = calc_z0(x0,
50
-                           get_x(x_index), z_values[y_index+1][x_index],
51
-                           get_x(x_index+1), z_values[y_index+1][x_index+1]);
52
-        float z0 = calc_z0(y0,
53
-                           get_y(y_index), z1,
54
-                           get_y(y_index+1), z2);
55
-        return z0;
40
+      int x_index = select_x_index(x0);
41
+      int y_index = select_y_index(y0);
42
+      float z1 = calc_z0(x0,
43
+                         get_x(x_index), z_values[y_index][x_index],
44
+                         get_x(x_index+1), z_values[y_index][x_index+1]);
45
+      float z2 = calc_z0(x0,
46
+                         get_x(x_index), z_values[y_index+1][x_index],
47
+                         get_x(x_index+1), z_values[y_index+1][x_index+1]);
48
+      float z0 = calc_z0(y0,
49
+                         get_y(y_index), z1,
50
+                         get_y(y_index+1), z2);
51
+      return z0;
56 52
     }
57
-};
53
+  };
58 54
 
59
-extern mesh_bed_leveling mbl;
55
+  extern mesh_bed_leveling mbl;
60 56
 
61 57
 #endif  // MESH_BED_LEVELING

Loading…
취소
저장