浏览代码

Fix G26's circle drawing... (#8291)

* Fix G26's circle drawing...

This mostly catches the bugfix-v1.1.x branch up to bugfix-v2.0.0

I'll have to do something similar to get bugfix-v2.0.0 caught up to
bugfix-v1.1.x

* only use planner.leveling_active if appropriate
Roxy-3D 7 年前
父节点
当前提交
12151e62ee
没有帐户链接到提交者的电子邮件

+ 20
- 16
Marlin/Marlin_main.cpp 查看文件

9965
                hasQ = !hasZ && parser.seen('Q');
9965
                hasQ = !hasZ && parser.seen('Q');
9966
 
9966
 
9967
     if (hasC) {
9967
     if (hasC) {
9968
-      const mesh_index_pair location = ubl.find_closest_mesh_point_of_type(REAL, current_position[X_AXIS], current_position[Y_AXIS], USE_NOZZLE_AS_REFERENCE, NULL, false);
9968
+      const mesh_index_pair location = ubl.find_closest_mesh_point_of_type(REAL, current_position[X_AXIS], current_position[Y_AXIS], USE_NOZZLE_AS_REFERENCE, NULL);
9969
       ix = location.x_index;
9969
       ix = location.x_index;
9970
       iy = location.y_index;
9970
       iy = location.y_index;
9971
     }
9971
     }
12849
    * Returns true if current_position[] was set to destination[]
12849
    * Returns true if current_position[] was set to destination[]
12850
    */
12850
    */
12851
   inline bool prepare_move_to_destination_cartesian() {
12851
   inline bool prepare_move_to_destination_cartesian() {
12852
-    if (current_position[X_AXIS] != destination[X_AXIS] || current_position[Y_AXIS] != destination[Y_AXIS]) {
12853
-      const float fr_scaled = MMS_SCALED(feedrate_mm_s);
12852
+    const float fr_scaled = MMS_SCALED(feedrate_mm_s);
12854
       #if HAS_MESH
12853
       #if HAS_MESH
12855
-        if (planner.leveling_active) {
12856
-          #if ENABLED(AUTO_BED_LEVELING_UBL)
12857
-            ubl.line_to_destination_cartesian(fr_scaled, active_extruder);
12858
-          #elif ENABLED(MESH_BED_LEVELING)
12859
-            mesh_line_to_destination(fr_scaled);
12860
-          #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
12861
-            bilinear_line_to_destination(fr_scaled);
12862
-          #endif
12863
-          return true;
12854
+        if (!planner.leveling_active) {
12855
+          line_to_destination(fr_scaled);
12856
+          return false;
12864
         }
12857
         }
12858
+        #if ENABLED(AUTO_BED_LEVELING_UBL)
12859
+          ubl.line_to_destination_cartesian(fr_scaled, active_extruder);  // UBL's motion routine needs to know about all moves,
12860
+          return true;                                                    // even purely Z-Axis moves
12861
+        #else
12862
+          if (current_position[X_AXIS] != destination[X_AXIS] || current_position[Y_AXIS] != destination[Y_AXIS]) {
12863
+            #if ENABLED(MESH_BED_LEVELING)
12864
+              mesh_line_to_destination(fr_scaled);
12865
+            #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
12866
+              bilinear_line_to_destination(fr_scaled);
12867
+            #endif
12868
+            return true;
12869
+          }
12870
+          else
12871
+            line_to_destination();
12872
+        #endif
12865
       #endif // HAS_MESH
12873
       #endif // HAS_MESH
12866
-      line_to_destination(fr_scaled);
12867
-    }
12868
-    else
12869
-      line_to_destination();
12870
 
12874
 
12871
     return false;
12875
     return false;
12872
   }
12876
   }

+ 1
- 1
Marlin/example_configurations/gCreate/gMax1.5+/Configuration.h 查看文件

694
  */
694
  */
695
 #define X_PROBE_OFFSET_FROM_EXTRUDER -17    // X offset: -left  +right  [of the nozzle]
695
 #define X_PROBE_OFFSET_FROM_EXTRUDER -17    // X offset: -left  +right  [of the nozzle]
696
 #define Y_PROBE_OFFSET_FROM_EXTRUDER -10    // Y offset: -front +behind [the nozzle]
696
 #define Y_PROBE_OFFSET_FROM_EXTRUDER -10    // Y offset: -front +behind [the nozzle]
697
-#define Z_PROBE_OFFSET_FROM_EXTRUDER -1.027 // Z offset: -below +above  [the nozzle]
697
+#define Z_PROBE_OFFSET_FROM_EXTRUDER -0.87  // Z offset: -below +above  [the nozzle]
698
 
698
 
699
 // X and Y axis travel speed (mm/m) between probes
699
 // X and Y axis travel speed (mm/m) between probes
700
 #define XY_PROBE_SPEED 7500
700
 #define XY_PROBE_SPEED 7500

+ 2
- 2
Marlin/example_configurations/gCreate/gMax1.5+/Configuration_adv.h 查看文件

617
    * On print completion the LCD Menu will open with the file selected.
617
    * On print completion the LCD Menu will open with the file selected.
618
    * You can just click to start the print, or navigate elsewhere.
618
    * You can just click to start the print, or navigate elsewhere.
619
    */
619
    */
620
-  //#define SD_REPRINT_LAST_SELECTED_FILE
620
+  #define SD_REPRINT_LAST_SELECTED_FILE
621
 
621
 
622
 #endif // SDSUPPORT
622
 #endif // SDSUPPORT
623
 
623
 
679
 #if ENABLED(BABYSTEPPING)
679
 #if ENABLED(BABYSTEPPING)
680
   //#define BABYSTEP_XY              // Also enable X/Y Babystepping. Not supported on DELTA!
680
   //#define BABYSTEP_XY              // Also enable X/Y Babystepping. Not supported on DELTA!
681
   #define BABYSTEP_INVERT_Z false    // Change if Z babysteps should go the other way
681
   #define BABYSTEP_INVERT_Z false    // Change if Z babysteps should go the other way
682
-  #define BABYSTEP_MULTIPLICATOR   1 // Babysteps are very small. Increase for faster motion.
682
+  #define BABYSTEP_MULTIPLICATOR   3 // Babysteps are very small. Increase for faster motion.
683
   //#define BABYSTEP_ZPROBE_OFFSET   // Enable to combine M851 and Babystepping
683
   //#define BABYSTEP_ZPROBE_OFFSET   // Enable to combine M851 and Babystepping
684
   #define DOUBLECLICK_FOR_Z_BABYSTEPPING // Double-click on the Status Screen for Z Babystepping.
684
   #define DOUBLECLICK_FOR_Z_BABYSTEPPING // Double-click on the Status Screen for Z Babystepping.
685
   #define DOUBLECLICK_MAX_INTERVAL 1250 // Maximum interval between clicks, in milliseconds.
685
   #define DOUBLECLICK_MAX_INTERVAL 1250 // Maximum interval between clicks, in milliseconds.

+ 3
- 3
Marlin/ubl.cpp 查看文件

36
    * to unsigned long will allow us to go to 32x32 if higher resolution Mesh's are needed
36
    * to unsigned long will allow us to go to 32x32 if higher resolution Mesh's are needed
37
    * in the future.
37
    * in the future.
38
    */
38
    */
39
-  void bit_clear(uint16_t bits[16], uint8_t x, uint8_t y) { CBI(bits[y], x); }
40
-  void bit_set(uint16_t bits[16], uint8_t x, uint8_t y) { SBI(bits[y], x); }
41
-  bool is_bit_set(uint16_t bits[16], uint8_t x, uint8_t y) { return TEST(bits[y], x); }
39
+  void bit_clear(uint16_t bits[16], const uint8_t x, const uint8_t y) { CBI(bits[y], x); }
40
+  void bit_set(uint16_t bits[16], const uint8_t x, const uint8_t y) { SBI(bits[y], x); }
41
+  bool is_bit_set(uint16_t bits[16], const uint8_t x, const uint8_t y) { return TEST(bits[y], x); }
42
 
42
 
43
   uint8_t ubl_cnt = 0;
43
   uint8_t ubl_cnt = 0;
44
 
44
 

+ 26
- 4
Marlin/ubl.h 查看文件

46
 
46
 
47
   // ubl.cpp
47
   // ubl.cpp
48
 
48
 
49
-  void bit_clear(uint16_t bits[16], uint8_t x, uint8_t y);
50
-  void bit_set(uint16_t bits[16], uint8_t x, uint8_t y);
51
-  bool is_bit_set(uint16_t bits[16], uint8_t x, uint8_t y);
49
+void bit_clear(uint16_t bits[16], const uint8_t x, const uint8_t y);
50
+void bit_set(uint16_t bits[16], const uint8_t x, const uint8_t y);
51
+bool is_bit_set(uint16_t bits[16], const uint8_t x, const uint8_t y);
52
 
52
 
53
   // ubl_motion.cpp
53
   // ubl_motion.cpp
54
 
54
 
147
       static void save_ubl_active_state_and_disable();
147
       static void save_ubl_active_state_and_disable();
148
       static void restore_ubl_active_state_and_leave();
148
       static void restore_ubl_active_state_and_leave();
149
       static void display_map(const int);
149
       static void display_map(const int);
150
-      static mesh_index_pair find_closest_mesh_point_of_type(const MeshPointType, const float&, const float&, const bool, uint16_t[16], bool);
150
+    static mesh_index_pair find_closest_mesh_point_of_type(const MeshPointType, const float&, const float&, const bool, uint16_t[16]);
151
+    static mesh_index_pair find_furthest_invalid_mesh_point();
151
       static void reset();
152
       static void reset();
152
       static void invalidate();
153
       static void invalidate();
153
       static void set_all_mesh_points_to_value(const float);
154
       static void set_all_mesh_points_to_value(const float);
246
        */
247
        */
247
       inline static float z_correction_for_x_on_horizontal_mesh_line(const float &rx0, const int x1_i, const int yi) {
248
       inline static float z_correction_for_x_on_horizontal_mesh_line(const float &rx0, const int x1_i, const int yi) {
248
         if (!WITHIN(x1_i, 0, GRID_MAX_POINTS_X - 2) || !WITHIN(yi, 0, GRID_MAX_POINTS_Y - 1)) {
249
         if (!WITHIN(x1_i, 0, GRID_MAX_POINTS_X - 2) || !WITHIN(yi, 0, GRID_MAX_POINTS_Y - 1)) {
250
+        #if ENABLED(DEBUG_LEVELING_FEATURE)
251
+          if (DEBUGGING(LEVELING)) {
249
           serialprintPGM( !WITHIN(x1_i, 0, GRID_MAX_POINTS_X - 1) ? PSTR("x1l_i") : PSTR("yi") );
252
           serialprintPGM( !WITHIN(x1_i, 0, GRID_MAX_POINTS_X - 1) ? PSTR("x1l_i") : PSTR("yi") );
250
           SERIAL_ECHOPAIR(" out of bounds in z_correction_for_x_on_horizontal_mesh_line(rx0=", rx0);
253
           SERIAL_ECHOPAIR(" out of bounds in z_correction_for_x_on_horizontal_mesh_line(rx0=", rx0);
251
           SERIAL_ECHOPAIR(",x1_i=", x1_i);
254
           SERIAL_ECHOPAIR(",x1_i=", x1_i);
252
           SERIAL_ECHOPAIR(",yi=", yi);
255
           SERIAL_ECHOPAIR(",yi=", yi);
253
           SERIAL_CHAR(')');
256
           SERIAL_CHAR(')');
254
           SERIAL_EOL();
257
           SERIAL_EOL();
258
+          }
259
+        #endif
255
           return NAN;
260
           return NAN;
256
         }
261
         }
257
 
262
 
266
       //
271
       //
267
       inline static float z_correction_for_y_on_vertical_mesh_line(const float &ry0, const int xi, const int y1_i) {
272
       inline static float z_correction_for_y_on_vertical_mesh_line(const float &ry0, const int xi, const int y1_i) {
268
         if (!WITHIN(xi, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(y1_i, 0, GRID_MAX_POINTS_Y - 2)) {
273
         if (!WITHIN(xi, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(y1_i, 0, GRID_MAX_POINTS_Y - 2)) {
274
+        #if ENABLED(DEBUG_LEVELING_FEATURE)
275
+          if (DEBUGGING(LEVELING)) {
269
           serialprintPGM( !WITHIN(xi, 0, GRID_MAX_POINTS_X - 1) ? PSTR("xi") : PSTR("yl_i") );
276
           serialprintPGM( !WITHIN(xi, 0, GRID_MAX_POINTS_X - 1) ? PSTR("xi") : PSTR("yl_i") );
270
           SERIAL_ECHOPAIR(" out of bounds in z_correction_for_y_on_vertical_mesh_line(ry0=", ry0);
277
           SERIAL_ECHOPAIR(" out of bounds in z_correction_for_y_on_vertical_mesh_line(ry0=", ry0);
271
           SERIAL_ECHOPAIR(", xi=", xi);
278
           SERIAL_ECHOPAIR(", xi=", xi);
272
           SERIAL_ECHOPAIR(", y1_i=", y1_i);
279
           SERIAL_ECHOPAIR(", y1_i=", y1_i);
273
           SERIAL_CHAR(')');
280
           SERIAL_CHAR(')');
274
           SERIAL_EOL();
281
           SERIAL_EOL();
282
+          }
283
+        #endif
275
           return NAN;
284
           return NAN;
276
         }
285
         }
277
 
286
 
365
       static bool prepare_segmented_line_to(const float rtarget[XYZE], const float &feedrate);
374
       static bool prepare_segmented_line_to(const float rtarget[XYZE], const float &feedrate);
366
       static void line_to_destination_cartesian(const float &fr, uint8_t e);
375
       static void line_to_destination_cartesian(const float &fr, uint8_t e);
367
 
376
 
377
+    #define _CMPZ(a,b) (z_values[a][b] == z_values[a][b+1])
378
+    #define CMPZ(a) (_CMPZ(a, 0) && _CMPZ(a, 1))
379
+    #define ZZER(a) (z_values[a][0] == 0)
380
+
381
+    FORCE_INLINE bool mesh_is_valid() {
382
+      return !(
383
+        (    CMPZ(0) && CMPZ(1) && CMPZ(2) // adjacent z values all equal?
384
+          && ZZER(0) && ZZER(1) && ZZER(2) // all zero at the edge?
385
+        )
386
+        || isnan(z_values[0][0])
387
+      );
388
+    }
389
+
368
   }; // class unified_bed_leveling
390
   }; // class unified_bed_leveling
369
 
391
 
370
   extern unified_bed_leveling ubl;
392
   extern unified_bed_leveling ubl;

+ 92
- 48
Marlin/ubl_G29.cpp 查看文件

332
       else {
332
       else {
333
         while (g29_repetition_cnt--) {
333
         while (g29_repetition_cnt--) {
334
           if (cnt > 20) { cnt = 0; idle(); }
334
           if (cnt > 20) { cnt = 0; idle(); }
335
-          const mesh_index_pair location = find_closest_mesh_point_of_type(REAL, g29_x_pos, g29_y_pos, USE_NOZZLE_AS_REFERENCE, NULL, false);
335
+          const mesh_index_pair location = find_closest_mesh_point_of_type(REAL, g29_x_pos, g29_y_pos, USE_NOZZLE_AS_REFERENCE, NULL);
336
           if (location.x_index < 0) {
336
           if (location.x_index < 0) {
337
             // No more REACHABLE mesh points to invalidate, so we ASSUME the user
337
             // No more REACHABLE mesh points to invalidate, so we ASSUME the user
338
             // meant to invalidate the ENTIRE mesh, which cannot be done with
338
             // meant to invalidate the ENTIRE mesh, which cannot be done with
528
             }
528
             }
529
             else {
529
             else {
530
               while (g29_repetition_cnt--) {  // this only populates reachable mesh points near
530
               while (g29_repetition_cnt--) {  // this only populates reachable mesh points near
531
-                const mesh_index_pair location = find_closest_mesh_point_of_type(INVALID, g29_x_pos, g29_y_pos, USE_NOZZLE_AS_REFERENCE, NULL, false);
531
+                const mesh_index_pair location = find_closest_mesh_point_of_type(INVALID, g29_x_pos, g29_y_pos, USE_NOZZLE_AS_REFERENCE, NULL);
532
                 if (location.x_index < 0) {
532
                 if (location.x_index < 0) {
533
                   // No more REACHABLE INVALID mesh points to populate, so we ASSUME
533
                   // No more REACHABLE INVALID mesh points to populate, so we ASSUME
534
                   // user meant to populate ALL INVALID mesh points to value
534
                   // user meant to populate ALL INVALID mesh points to value
667
     }
667
     }
668
 
668
 
669
     if (parser.seen('T'))
669
     if (parser.seen('T'))
670
-      display_map(parser.has_value() ? parser.value_int() : 0);
670
+      display_map(g29_map_type);
671
 
671
 
672
     LEAVE:
672
     LEAVE:
673
 
673
 
742
       uint16_t max_iterations = GRID_MAX_POINTS;
742
       uint16_t max_iterations = GRID_MAX_POINTS;
743
 
743
 
744
       do {
744
       do {
745
+        if (do_ubl_mesh_map) display_map(g29_map_type);
746
+
745
         #if ENABLED(NEWPANEL)
747
         #if ENABLED(NEWPANEL)
746
           if (ubl_lcd_clicked()) {
748
           if (ubl_lcd_clicked()) {
747
             SERIAL_PROTOCOLLNPGM("\nMesh only partially populated.\n");
749
             SERIAL_PROTOCOLLNPGM("\nMesh only partially populated.\n");
755
           }
757
           }
756
         #endif
758
         #endif
757
 
759
 
758
-        location = find_closest_mesh_point_of_type(INVALID, rx, ry, USE_PROBE_AS_REFERENCE, NULL, close_or_far);
760
+        if (close_or_far)
761
+          location = find_furthest_invalid_mesh_point();
762
+        else
763
+          location = find_closest_mesh_point_of_type(INVALID, rx, ry, USE_PROBE_AS_REFERENCE, NULL);
759
 
764
 
760
         if (location.x_index >= 0) {    // mesh point found and is reachable by probe
765
         if (location.x_index >= 0) {    // mesh point found and is reachable by probe
761
           const float rawx = mesh_index_to_xpos(location.x_index),
766
           const float rawx = mesh_index_to_xpos(location.x_index),
765
           z_values[location.x_index][location.y_index] = measured_z;
770
           z_values[location.x_index][location.y_index] = measured_z;
766
         }
771
         }
767
 
772
 
768
-        if (do_ubl_mesh_map) display_map(g29_map_type);
769
 
773
 
770
       } while (location.x_index >= 0 && --max_iterations);
774
       } while (location.x_index >= 0 && --max_iterations);
771
 
775
 
958
 
962
 
959
       mesh_index_pair location;
963
       mesh_index_pair location;
960
       do {
964
       do {
961
-        location = find_closest_mesh_point_of_type(INVALID, rx, ry, USE_NOZZLE_AS_REFERENCE, NULL, false);
965
+        location = find_closest_mesh_point_of_type(INVALID, rx, ry, USE_NOZZLE_AS_REFERENCE, NULL);
962
         // It doesn't matter if the probe can't reach the NAN location. This is a manual probe.
966
         // It doesn't matter if the probe can't reach the NAN location. This is a manual probe.
963
         if (location.x_index < 0 && location.y_index < 0) continue;
967
         if (location.x_index < 0 && location.y_index < 0) continue;
964
 
968
 
1228
 
1232
 
1229
     SERIAL_PROTOCOLPGM("X-Axis Mesh Points at: ");
1233
     SERIAL_PROTOCOLPGM("X-Axis Mesh Points at: ");
1230
     for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
1234
     for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
1231
-      SERIAL_PROTOCOL_F(mesh_index_to_xpos(i), 3);
1235
+      SERIAL_PROTOCOL_F(LOGICAL_X_POSITION(mesh_index_to_xpos(i)), 3);
1232
       SERIAL_PROTOCOLPGM("  ");
1236
       SERIAL_PROTOCOLPGM("  ");
1233
       safe_delay(25);
1237
       safe_delay(25);
1234
     }
1238
     }
1236
 
1240
 
1237
     SERIAL_PROTOCOLPGM("Y-Axis Mesh Points at: ");
1241
     SERIAL_PROTOCOLPGM("Y-Axis Mesh Points at: ");
1238
     for (uint8_t i = 0; i < GRID_MAX_POINTS_Y; i++) {
1242
     for (uint8_t i = 0; i < GRID_MAX_POINTS_Y; i++) {
1239
-      SERIAL_PROTOCOL_F(mesh_index_to_ypos(i), 3);
1243
+      SERIAL_PROTOCOL_F(LOGICAL_Y_POSITION(mesh_index_to_ypos(i)), 3);
1240
       SERIAL_PROTOCOLPGM("  ");
1244
       SERIAL_PROTOCOLPGM("  ");
1241
       safe_delay(25);
1245
       safe_delay(25);
1242
     }
1246
     }
1284
    */
1288
    */
1285
   void unified_bed_leveling::g29_eeprom_dump() {
1289
   void unified_bed_leveling::g29_eeprom_dump() {
1286
     unsigned char cccc;
1290
     unsigned char cccc;
1287
-    uint16_t kkkk;
1291
+    unsigned int  kkkk;  // Needs to be of unspecfied size to compile clean on all platforms
1288
 
1292
 
1289
     SERIAL_ECHO_START();
1293
     SERIAL_ECHO_START();
1290
     SERIAL_ECHOLNPGM("EEPROM Dump:");
1294
     SERIAL_ECHOLNPGM("EEPROM Dump:");
1294
       SERIAL_ECHOPGM(": ");
1298
       SERIAL_ECHOPGM(": ");
1295
       for (uint16_t j = 0; j < 16; j++) {
1299
       for (uint16_t j = 0; j < 16; j++) {
1296
         kkkk = i + j;
1300
         kkkk = i + j;
1297
-        eeprom_read_block(&cccc, (void *)kkkk, 1);
1301
+        eeprom_read_block(&cccc, (const void *) kkkk, sizeof(unsigned char));
1298
         print_hex_byte(cccc);
1302
         print_hex_byte(cccc);
1299
         SERIAL_ECHO(' ');
1303
         SERIAL_ECHO(' ');
1300
       }
1304
       }
1340
         z_values[x][y] -= tmp_z_values[x][y];
1344
         z_values[x][y] -= tmp_z_values[x][y];
1341
   }
1345
   }
1342
 
1346
 
1343
-  mesh_index_pair unified_bed_leveling::find_closest_mesh_point_of_type(const MeshPointType type, const float &rx, const float &ry, const bool probe_as_reference, unsigned int bits[16], const bool far_flag) {
1347
+
1348
+  mesh_index_pair unified_bed_leveling::find_furthest_invalid_mesh_point() {
1349
+
1350
+    bool found_a_NAN  = false;
1351
+    bool found_a_real = false;
1352
+    mesh_index_pair out_mesh;
1353
+    out_mesh.x_index = out_mesh.y_index = -1;
1354
+    out_mesh.distance = -99999.99;
1355
+
1356
+    for (int8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
1357
+      for (int8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
1358
+
1359
+        if ( isnan(z_values[i][j])) { // Check to see if this location holds an invalid mesh point
1360
+
1361
+          const float mx = mesh_index_to_xpos(i),
1362
+                      my = mesh_index_to_ypos(j);
1363
+
1364
+          if ( !position_is_reachable_by_probe(mx, my))  // make sure the probe can get to the mesh point
1365
+            continue;
1366
+
1367
+          found_a_NAN = true;
1368
+
1369
+          int8_t closest_x=-1, closest_y=-1;
1370
+          float d1, d2 = 99999.9;
1371
+          for (int8_t k = 0; k < GRID_MAX_POINTS_X; k++) {
1372
+            for (int8_t l = 0; l < GRID_MAX_POINTS_Y; l++) {
1373
+              if (!isnan(z_values[k][l])) {
1374
+                found_a_real = true;
1375
+
1376
+          // Add in a random weighting factor that scrambles the probing of the
1377
+          // last half of the mesh (when every unprobed mesh point is one index
1378
+          // from a probed location).
1379
+
1380
+                d1 = HYPOT(i - k, j - l) + (1.0 / ((millis() % 47) + 13));
1381
+
1382
+                if (d1 < d2) {    // found a closer distance from invalid mesh point at (i,j) to defined mesh point at (k,l)
1383
+                  d2 = d1;       // found a closer location with
1384
+                  closest_x = i;    // an assigned mesh point value
1385
+                  closest_y = j;
1386
+                }
1387
+              }
1388
+            }
1389
+          }
1390
+
1391
+          //
1392
+          // at this point d2 should have the closest defined mesh point to invalid mesh point (i,j)
1393
+          //
1394
+
1395
+          if (found_a_real && (closest_x >= 0) && (d2 > out_mesh.distance)) {
1396
+            out_mesh.distance = d2;         // found an invalid location with a greater distance
1397
+            out_mesh.x_index = closest_x;   // to a defined mesh point
1398
+            out_mesh.y_index = closest_y;
1399
+          }
1400
+        }
1401
+      } // for j
1402
+    } // for i
1403
+
1404
+    if (!found_a_real && found_a_NAN) {        // if the mesh is totally unpopulated, start the probing
1405
+      out_mesh.x_index = GRID_MAX_POINTS_X / 2;
1406
+      out_mesh.y_index = GRID_MAX_POINTS_Y / 2;
1407
+      out_mesh.distance = 1.0;
1408
+    }
1409
+    return out_mesh;
1410
+  }
1411
+
1412
+  mesh_index_pair unified_bed_leveling::find_closest_mesh_point_of_type(const MeshPointType type, const float &rx, const float &ry, const bool probe_as_reference, uint16_t bits[16]) {
1344
     mesh_index_pair out_mesh;
1413
     mesh_index_pair out_mesh;
1345
     out_mesh.x_index = out_mesh.y_index = -1;
1414
     out_mesh.x_index = out_mesh.y_index = -1;
1415
+    out_mesh.distance = -99999.9;
1346
 
1416
 
1347
     // Get our reference position. Either the nozzle or probe location.
1417
     // Get our reference position. Either the nozzle or probe location.
1348
     const float px = rx - (probe_as_reference == USE_PROBE_AS_REFERENCE ? X_PROBE_OFFSET_FROM_EXTRUDER : 0),
1418
     const float px = rx - (probe_as_reference == USE_PROBE_AS_REFERENCE ? X_PROBE_OFFSET_FROM_EXTRUDER : 0),
1349
                 py = ry - (probe_as_reference == USE_PROBE_AS_REFERENCE ? Y_PROBE_OFFSET_FROM_EXTRUDER : 0);
1419
                 py = ry - (probe_as_reference == USE_PROBE_AS_REFERENCE ? Y_PROBE_OFFSET_FROM_EXTRUDER : 0);
1350
 
1420
 
1351
-    float best_so_far = far_flag ? -99999.99 : 99999.99;
1421
+    float best_so_far = 99999.99;
1352
 
1422
 
1353
-    for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
1354
-      for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
1423
+    for (int8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
1424
+      for (int8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
1355
 
1425
 
1356
         if ( (type == INVALID && isnan(z_values[i][j]))  // Check to see if this location holds the right thing
1426
         if ( (type == INVALID && isnan(z_values[i][j]))  // Check to see if this location holds the right thing
1357
           || (type == REAL && !isnan(z_values[i][j]))
1427
           || (type == REAL && !isnan(z_values[i][j]))
1370
             continue;
1440
             continue;
1371
 
1441
 
1372
           // Reachable. Check if it's the best_so_far location to the nozzle.
1442
           // Reachable. Check if it's the best_so_far location to the nozzle.
1373
-          // Add in a weighting factor that considers the current location of the nozzle.
1374
 
1443
 
1375
           float distance = HYPOT(px - mx, py - my);
1444
           float distance = HYPOT(px - mx, py - my);
1376
 
1445
 
1377
-          /**
1378
-           * If doing the far_flag action, we want to be as far as possible
1379
-           * from the starting point and from any other probed points. We
1380
-           * want the next point spread out and filling in any blank spaces
1381
-           * in the mesh. So we add in some of the distance to every probed
1382
-           * point we can find.
1383
-           */
1384
-          if (far_flag) {
1385
-            for (uint8_t k = 0; k < GRID_MAX_POINTS_X; k++) {
1386
-              for (uint8_t l = 0; l < GRID_MAX_POINTS_Y; l++) {
1387
-                if (i != k && j != l && !isnan(z_values[k][l])) {
1388
-                  //distance += pow((float) abs(i - k) * (MESH_X_DIST), 2) + pow((float) abs(j - l) * (MESH_Y_DIST), 2);  // working here
1389
-                  distance += HYPOT(MESH_X_DIST, MESH_Y_DIST) / log(HYPOT((i - k) * (MESH_X_DIST) + .001, (j - l) * (MESH_Y_DIST)) + .001);
1390
-                }
1391
-              }
1392
-            }
1393
-          }
1394
-          else
1395
             // factor in the distance from the current location for the normal case
1446
             // factor in the distance from the current location for the normal case
1396
             // so the nozzle isn't running all over the bed.
1447
             // so the nozzle isn't running all over the bed.
1397
             distance += HYPOT(current_position[X_AXIS] - mx, current_position[Y_AXIS] - my) * 0.1;
1448
             distance += HYPOT(current_position[X_AXIS] - mx, current_position[Y_AXIS] - my) * 0.1;
1398
 
1449
 
1399
-          // if far_flag, look for farthest point
1400
-          if (far_flag == (distance > best_so_far) && distance != best_so_far) {
1401
-            best_so_far = distance;   // We found a closer/farther location with
1450
+          if (distance < best_so_far) {
1451
+            best_so_far = distance;   // We found a closer location with
1402
             out_mesh.x_index = i;     // the specified type of mesh value.
1452
             out_mesh.x_index = i;     // the specified type of mesh value.
1403
             out_mesh.y_index = j;
1453
             out_mesh.y_index = j;
1404
             out_mesh.distance = best_so_far;
1454
             out_mesh.distance = best_so_far;
1442
       uint16_t not_done[16];
1492
       uint16_t not_done[16];
1443
       memset(not_done, 0xFF, sizeof(not_done));
1493
       memset(not_done, 0xFF, sizeof(not_done));
1444
       do {
1494
       do {
1445
-        location = find_closest_mesh_point_of_type(SET_IN_BITMAP, rx, ry, USE_NOZZLE_AS_REFERENCE, not_done, false);
1495
+        location = find_closest_mesh_point_of_type(SET_IN_BITMAP, rx, ry, USE_NOZZLE_AS_REFERENCE, not_done);
1446
 
1496
 
1447
         if (location.x_index < 0) break; // stop when we can't find any more reachable points.
1497
         if (location.x_index < 0) break; // stop when we can't find any more reachable points.
1448
 
1498
 
1566
       info3 PROGMEM = { GRID_MAX_POINTS_X - 1, 0,  0, GRID_MAX_POINTS_Y,      true  };  // Right side of the mesh looking left
1616
       info3 PROGMEM = { GRID_MAX_POINTS_X - 1, 0,  0, GRID_MAX_POINTS_Y,      true  };  // Right side of the mesh looking left
1567
     static const smart_fill_info * const info[] PROGMEM = { &info0, &info1, &info2, &info3 };
1617
     static const smart_fill_info * const info[] PROGMEM = { &info0, &info1, &info2, &info3 };
1568
 
1618
 
1569
-    // static const smart_fill_info info[] PROGMEM = {
1570
-    //   { 0, GRID_MAX_POINTS_X,      0, GRID_MAX_POINTS_Y - 2,  false } PROGMEM,  // Bottom of the mesh looking up
1571
-    //   { 0, GRID_MAX_POINTS_X,      GRID_MAX_POINTS_Y - 1, 0,  false } PROGMEM,  // Top of the mesh looking down
1572
-    //   { 0, GRID_MAX_POINTS_X - 2,  0, GRID_MAX_POINTS_Y,      true  } PROGMEM,  // Left side of the mesh looking right
1573
-    //   { GRID_MAX_POINTS_X - 1, 0,  0, GRID_MAX_POINTS_Y,      true  } PROGMEM   // Right side of the mesh looking left
1574
-    // };
1575
     for (uint8_t i = 0; i < COUNT(info); ++i) {
1619
     for (uint8_t i = 0; i < COUNT(info); ++i) {
1576
-      const smart_fill_info *f = (smart_fill_info*)pgm_read_word(&info[i]);
1577
-      const int8_t sx = pgm_read_word(&f->sx), sy = pgm_read_word(&f->sy),
1578
-                   ex = pgm_read_word(&f->ex), ey = pgm_read_word(&f->ey);
1620
+      const smart_fill_info *f = (smart_fill_info*)pgm_read_ptr(&info[i]);
1621
+      const int8_t sx = pgm_read_byte(&f->sx), sy = pgm_read_byte(&f->sy),
1622
+                   ex = pgm_read_byte(&f->ex), ey = pgm_read_byte(&f->ey);
1579
       if (pgm_read_byte(&f->yfirst)) {
1623
       if (pgm_read_byte(&f->yfirst)) {
1580
         const int8_t dir = ex > sx ? 1 : -1;
1624
         const int8_t dir = ex > sx ? 1 : -1;
1581
         for (uint8_t y = sy; y != ey; ++y)
1625
         for (uint8_t y = sy; y != ey; ++y)
1614
           #if ENABLED(DEBUG_LEVELING_FEATURE)
1658
           #if ENABLED(DEBUG_LEVELING_FEATURE)
1615
             if (DEBUGGING(LEVELING)) {
1659
             if (DEBUGGING(LEVELING)) {
1616
               SERIAL_CHAR('(');
1660
               SERIAL_CHAR('(');
1617
-              SERIAL_PROTOCOL_F(x, 7);
1661
+              SERIAL_PROTOCOL_F(rx, 7);
1618
               SERIAL_CHAR(',');
1662
               SERIAL_CHAR(',');
1619
-              SERIAL_PROTOCOL_F(y, 7);
1663
+              SERIAL_PROTOCOL_F(ry, 7);
1620
               SERIAL_ECHOPGM(")   logical: ");
1664
               SERIAL_ECHOPGM(")   logical: ");
1621
               SERIAL_CHAR('(');
1665
               SERIAL_CHAR('(');
1622
               SERIAL_PROTOCOL_F(LOGICAL_X_POSITION(rx), 7);
1666
               SERIAL_PROTOCOL_F(LOGICAL_X_POSITION(rx), 7);

正在加载...
取消
保存