Browse Source

Simplify 3-point probing using new code only

Gabe Rosenhouse 10 years ago
parent
commit
174b8d99d5
4 changed files with 64 additions and 129 deletions
  1. 43
    56
      Marlin/Configuration.h
  2. 19
    71
      Marlin/Marlin_main.cpp
  3. 1
    1
      Marlin/qr_solve.cpp
  4. 1
    1
      Marlin/qr_solve.h

+ 43
- 56
Marlin/Configuration.h View File

335
 
335
 
336
 #ifdef ENABLE_AUTO_BED_LEVELING
336
 #ifdef ENABLE_AUTO_BED_LEVELING
337
 
337
 
338
-// There are 3 different ways to pick the X and Y locations to probe:
339
-// 1. Basic 3-point probe at left-back, left-front, and right-front corners of a rectangle
340
-// 2. Probe all points of a 2D lattice, defined by a rectangle and ACCURATE_BED_LEVELING_POINTS
341
-// 3. 3-point probe at 3 arbitrary points that don't form a line.
342
-
343
-// To enable mode 1:
344
-//   - #define ENABLE_AUTO_BED_LEVELING
345
-//   - Set the XXXX_PROBE_BED_POSITION values below
346
-//   - Don't define AUTO_BED_LEVELING_ANY_POINTS or ACCURATE_BED_LEVELING
347
-
348
-// To enable mode 2:
349
-//  - #define ENABLE_AUTO_BED_LEVELING
350
-//  - Set the XXXX_PROBE_BED_POSITION values below
351
-//  - #define ACCURATE_BED_LEVELING
352
-//  - Set the ACCURATE_BED_LEVELING_POINTS to your desired density
353
-
354
-// To enable mode 3:
355
-//  - #define ENABLE_AUTO_BED_LEVELING
356
-//  - #define AUTO_BED_LEVELING_ANY_POINTS
357
-//  - Set the ABL_PROBE_PT_XXXX values below
358
-//  - Comment out (undefine) ACCURATE_BED_LEVELING since that is incompatible
359
-
360
-
361
-
362
-// Mode 3: Enable auto bed leveling at any 3 points that aren't colinear
363
-// #define AUTO_BED_LEVELING_ANY_POINTS
364
-#ifdef AUTO_BED_LEVELING_ANY_POINTS
365
-  #define ABL_PROBE_PT_1_X 15
366
-  #define ABL_PROBE_PT_1_Y 15
367
-  #define ABL_PROBE_PT_2_X 25
368
-  #define ABL_PROBE_PT_2_Y 75
369
-  #define ABL_PROBE_PT_3_X 125
370
-  #define ABL_PROBE_PT_3_Y 25
371
-#else // not AUTO_BED_LEVELING_ANY_POINTS
372
-
373
-  // Modes 1 & 2:
374
-  //   For mode 1, probing happens at left-back, left-front, and right-front corners
375
-  //   For mode 2, probing happens at lattice points within this rectangle (see ACCURATE_BED_LEVELING_POINTS)
376
-  #define LEFT_PROBE_BED_POSITION 15
377
-  #define RIGHT_PROBE_BED_POSITION 170
378
-  #define BACK_PROBE_BED_POSITION 180
379
-  #define FRONT_PROBE_BED_POSITION 20
338
+// There are 2 different ways to pick the X and Y locations to probe:
339
+
340
+//  - "grid" mode
341
+//    Probe every point in a rectangular grid
342
+//    You must specify the rectangle, and the density of sample points
343
+//    This mode is preferred because there are more measurements.
344
+//    It used to be called ACCURATE_BED_LEVELING but "grid" is more descriptive
345
+
346
+//  - "3-point" mode
347
+//    Probe 3 arbitrary points on the bed (that aren't colinear)
348
+//    You must specify the X & Y coordinates of all 3 points
349
+
350
+  #define AUTO_BED_LEVELING_GRID
351
+  // with AUTO_BED_LEVELING_GRID, the bed is sampled in a
352
+  // AUTO_BED_LEVELING_GRID_POINTSxAUTO_BED_LEVELING_GRID_POINTS grid
353
+  // and least squares solution is calculated
354
+  // Note: this feature occupies 10'206 byte
355
+  #ifdef AUTO_BED_LEVELING_GRID
356
+
357
+    // set the rectangle in which to probe
358
+    #define LEFT_PROBE_BED_POSITION 15
359
+    #define RIGHT_PROBE_BED_POSITION 170
360
+    #define BACK_PROBE_BED_POSITION 180
361
+    #define FRONT_PROBE_BED_POSITION 20
362
+
363
+     // set the number of grid points per dimension
364
+     // I wouldn't see a reason to go above 3 (=9 probing points on the bed)
365
+    #define AUTO_BED_LEVELING_GRID_POINTS 2
366
+
367
+
368
+  #else  // not AUTO_BED_LEVELING_GRID
369
+    // with no grid, just probe 3 arbitrary points.  A simple cross-product
370
+    // is used to esimate the plane of the print bed
371
+
372
+      #define ABL_PROBE_PT_1_X 15
373
+      #define ABL_PROBE_PT_1_Y 180
374
+      #define ABL_PROBE_PT_2_X 15
375
+      #define ABL_PROBE_PT_2_Y 20
376
+      #define ABL_PROBE_PT_3_X 170
377
+      #define ABL_PROBE_PT_3_Y 20
378
+
379
+  #endif // AUTO_BED_LEVELING_GRID
380
 
380
 
381
-#endif
382
 
381
 
383
   // these are the offsets to the probe relative to the extruder tip (Hotend - Probe)
382
   // these are the offsets to the probe relative to the extruder tip (Hotend - Probe)
384
   #define X_PROBE_OFFSET_FROM_EXTRUDER -25
383
   #define X_PROBE_OFFSET_FROM_EXTRUDER -25
418
 
417
 
419
   #endif
418
   #endif
420
 
419
 
421
-  // with accurate bed leveling, the bed is sampled in a ACCURATE_BED_LEVELING_POINTSxACCURATE_BED_LEVELING_POINTS grid and least squares solution is calculated
422
-  // Note: this feature occupies 10'206 byte
423
-  #define ACCURATE_BED_LEVELING
424
-  // Mode 2 only
425
-  #ifdef ACCURATE_BED_LEVELING
426
-    #ifdef AUTO_BED_LEVELING_ANY_POINTS
427
-      #error AUTO_BED_LEVELING_ANY_POINTS is incompatible with ACCURATE_BED_LEVELING
428
-    #endif
429
-     // I wouldn't see a reason to go above 3 (=9 probing points on the bed)
430
-    #define ACCURATE_BED_LEVELING_POINTS 2
431
-  #endif
432
-
433
-#endif
420
+#endif // ENABLE_AUTO_BED_LEVELING
434
 
421
 
435
 
422
 
436
 // The position of the homing switches
423
 // The position of the homing switches

+ 19
- 71
Marlin/Marlin_main.cpp View File

31
 
31
 
32
 #ifdef ENABLE_AUTO_BED_LEVELING
32
 #ifdef ENABLE_AUTO_BED_LEVELING
33
 #include "vector_3.h"
33
 #include "vector_3.h"
34
-  #ifdef ACCURATE_BED_LEVELING
34
+  #ifdef AUTO_BED_LEVELING_GRID
35
     #include "qr_solve.h"
35
     #include "qr_solve.h"
36
   #endif
36
   #endif
37
 #endif // ENABLE_AUTO_BED_LEVELING
37
 #endif // ENABLE_AUTO_BED_LEVELING
822
 }
822
 }
823
 
823
 
824
 #ifdef ENABLE_AUTO_BED_LEVELING
824
 #ifdef ENABLE_AUTO_BED_LEVELING
825
-#ifdef ACCURATE_BED_LEVELING
825
+#ifdef AUTO_BED_LEVELING_GRID
826
 static void set_bed_level_equation_lsq(double *plane_equation_coefficients)
826
 static void set_bed_level_equation_lsq(double *plane_equation_coefficients)
827
 {
827
 {
828
     vector_3 planeNormal = vector_3(-plane_equation_coefficients[0], -plane_equation_coefficients[1], 1);
828
     vector_3 planeNormal = vector_3(-plane_equation_coefficients[0], -plane_equation_coefficients[1], 1);
846
     plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
846
     plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
847
 }
847
 }
848
 
848
 
849
-#else // not ACCURATE_BED_LEVELING
849
+#else // not AUTO_BED_LEVELING_GRID
850
 
850
 
851
-  #ifdef AUTO_BED_LEVELING_ANY_POINTS
852
-static void set_bed_level_equation_any_pts(float z_at_pt_1, float z_at_pt_2, float z_at_pt_3) {
851
+static void set_bed_level_equation_3pts(float z_at_pt_1, float z_at_pt_2, float z_at_pt_3) {
853
 
852
 
854
     plan_bed_level_matrix.set_to_identity();
853
     plan_bed_level_matrix.set_to_identity();
855
 
854
 
869
     current_position[Y_AXIS] = corrected_position.y;
868
     current_position[Y_AXIS] = corrected_position.y;
870
     current_position[Z_AXIS] = corrected_position.z;
869
     current_position[Z_AXIS] = corrected_position.z;
871
 
870
 
872
-    // but the bed at 0 so we don't go below it.
871
+    // put the bed at 0 so we don't go below it.
873
     current_position[Z_AXIS] = zprobe_zoffset;
872
     current_position[Z_AXIS] = zprobe_zoffset;
874
 
873
 
875
     plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
874
     plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
876
 
875
 
877
 }
876
 }
878
-  #else // not AUTO_BED_LEVELING_ANY_POINTS
879
-static void set_bed_level_equation(float z_at_xLeft_yFront, float z_at_xRight_yFront, float z_at_xLeft_yBack) {
880
-    plan_bed_level_matrix.set_to_identity();
881
-
882
-    vector_3 xLeftyFront = vector_3(LEFT_PROBE_BED_POSITION, FRONT_PROBE_BED_POSITION, z_at_xLeft_yFront);
883
-    vector_3 xLeftyBack = vector_3(LEFT_PROBE_BED_POSITION, BACK_PROBE_BED_POSITION, z_at_xLeft_yBack);
884
-    vector_3 xRightyFront = vector_3(RIGHT_PROBE_BED_POSITION, FRONT_PROBE_BED_POSITION, z_at_xRight_yFront);
885
-
886
-    vector_3 xPositive = (xRightyFront - xLeftyFront).get_normal();
887
-    vector_3 yPositive = (xLeftyBack - xLeftyFront).get_normal();
888
-    vector_3 planeNormal = vector_3::cross(xPositive, yPositive).get_normal();
889
-
890
-    //planeNormal.debug("planeNormal");
891
-    //yPositive.debug("yPositive");
892
-    plan_bed_level_matrix = matrix_3x3::create_look_at(planeNormal);
893
-    //bedLevel.debug("bedLevel");
894
-
895
-    //plan_bed_level_matrix.debug("bed level before");
896
-    //vector_3 uncorrected_position = plan_get_position_mm();
897
-    //uncorrected_position.debug("position before");
898
-
899
-    // and set our bed level equation to do the right thing
900
-    //plan_bed_level_matrix.debug("bed level after");
901
 
877
 
902
-    vector_3 corrected_position = plan_get_position();
903
-    //corrected_position.debug("position after");
904
-    current_position[X_AXIS] = corrected_position.x;
905
-    current_position[Y_AXIS] = corrected_position.y;
906
-    current_position[Z_AXIS] = corrected_position.z;
907
-
908
-    // but the bed at 0 so we don't go below it.
909
-    current_position[Z_AXIS] = zprobe_zoffset;
910
-
911
-    plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
912
-}
913
-  #endif // AUTO_BED_LEVELING_ANY_POINTS
914
-#endif // ACCURATE_BED_LEVELING
878
+#endif // AUTO_BED_LEVELING_GRID
915
 
879
 
916
 static void run_z_probe() {
880
 static void run_z_probe() {
917
     plan_bed_level_matrix.set_to_identity();
881
     plan_bed_level_matrix.set_to_identity();
1462
             setup_for_endstop_move();
1426
             setup_for_endstop_move();
1463
 
1427
 
1464
             feedrate = homing_feedrate[Z_AXIS];
1428
             feedrate = homing_feedrate[Z_AXIS];
1465
-#ifdef ACCURATE_BED_LEVELING
1429
+#ifdef AUTO_BED_LEVELING_GRID
1466
             // probe at the points of a lattice grid
1430
             // probe at the points of a lattice grid
1467
 
1431
 
1468
-            int xGridSpacing = (RIGHT_PROBE_BED_POSITION - LEFT_PROBE_BED_POSITION) / (ACCURATE_BED_LEVELING_POINTS-1);
1469
-            int yGridSpacing = (BACK_PROBE_BED_POSITION - FRONT_PROBE_BED_POSITION) / (ACCURATE_BED_LEVELING_POINTS-1);
1432
+            int xGridSpacing = (RIGHT_PROBE_BED_POSITION - LEFT_PROBE_BED_POSITION) / (AUTO_BED_LEVELING_GRID_POINTS-1);
1433
+            int yGridSpacing = (BACK_PROBE_BED_POSITION - FRONT_PROBE_BED_POSITION) / (AUTO_BED_LEVELING_GRID_POINTS-1);
1470
 
1434
 
1471
 
1435
 
1472
             // solve the plane equation ax + by + d = z
1436
             // solve the plane equation ax + by + d = z
1476
             // so Vx = -a Vy = -b Vz = 1 (we want the vector facing towards positive Z
1440
             // so Vx = -a Vy = -b Vz = 1 (we want the vector facing towards positive Z
1477
 
1441
 
1478
             // "A" matrix of the linear system of equations
1442
             // "A" matrix of the linear system of equations
1479
-            double eqnAMatrix[ACCURATE_BED_LEVELING_POINTS*ACCURATE_BED_LEVELING_POINTS*3];
1443
+            double eqnAMatrix[AUTO_BED_LEVELING_GRID_POINTS*AUTO_BED_LEVELING_GRID_POINTS*3];
1480
             // "B" vector of Z points
1444
             // "B" vector of Z points
1481
-            double eqnBVector[ACCURATE_BED_LEVELING_POINTS*ACCURATE_BED_LEVELING_POINTS];
1445
+            double eqnBVector[AUTO_BED_LEVELING_GRID_POINTS*AUTO_BED_LEVELING_GRID_POINTS];
1482
 
1446
 
1483
 
1447
 
1484
             int probePointCounter = 0;
1448
             int probePointCounter = 0;
1501
                 zig = true;
1465
                 zig = true;
1502
               }
1466
               }
1503
 
1467
 
1504
-              for (int xCount=0; xCount < ACCURATE_BED_LEVELING_POINTS; xCount++)
1468
+              for (int xCount=0; xCount < AUTO_BED_LEVELING_GRID_POINTS; xCount++)
1505
               {
1469
               {
1506
                 float z_before;
1470
                 float z_before;
1507
                 if (probePointCounter == 0)
1471
                 if (probePointCounter == 0)
1518
 
1482
 
1519
                 eqnBVector[probePointCounter] = measured_z;
1483
                 eqnBVector[probePointCounter] = measured_z;
1520
 
1484
 
1521
-                eqnAMatrix[probePointCounter + 0*ACCURATE_BED_LEVELING_POINTS*ACCURATE_BED_LEVELING_POINTS] = xProbe;
1522
-                eqnAMatrix[probePointCounter + 1*ACCURATE_BED_LEVELING_POINTS*ACCURATE_BED_LEVELING_POINTS] = yProbe;
1523
-                eqnAMatrix[probePointCounter + 2*ACCURATE_BED_LEVELING_POINTS*ACCURATE_BED_LEVELING_POINTS] = 1;
1485
+                eqnAMatrix[probePointCounter + 0*AUTO_BED_LEVELING_GRID_POINTS*AUTO_BED_LEVELING_GRID_POINTS] = xProbe;
1486
+                eqnAMatrix[probePointCounter + 1*AUTO_BED_LEVELING_GRID_POINTS*AUTO_BED_LEVELING_GRID_POINTS] = yProbe;
1487
+                eqnAMatrix[probePointCounter + 2*AUTO_BED_LEVELING_GRID_POINTS*AUTO_BED_LEVELING_GRID_POINTS] = 1;
1524
                 probePointCounter++;
1488
                 probePointCounter++;
1525
                 xProbe += xInc;
1489
                 xProbe += xInc;
1526
               }
1490
               }
1528
             clean_up_after_endstop_move();
1492
             clean_up_after_endstop_move();
1529
 
1493
 
1530
             // solve lsq problem
1494
             // solve lsq problem
1531
-            double *plane_equation_coefficients = qr_solve(ACCURATE_BED_LEVELING_POINTS*ACCURATE_BED_LEVELING_POINTS, 3, eqnAMatrix, eqnBVector);
1495
+            double *plane_equation_coefficients = qr_solve(AUTO_BED_LEVELING_GRID_POINTS*AUTO_BED_LEVELING_GRID_POINTS, 3, eqnAMatrix, eqnBVector);
1532
 
1496
 
1533
             SERIAL_PROTOCOLPGM("Eqn coefficients: a: ");
1497
             SERIAL_PROTOCOLPGM("Eqn coefficients: a: ");
1534
             SERIAL_PROTOCOL(plane_equation_coefficients[0]);
1498
             SERIAL_PROTOCOL(plane_equation_coefficients[0]);
1542
 
1506
 
1543
             free(plane_equation_coefficients);
1507
             free(plane_equation_coefficients);
1544
 
1508
 
1545
-#else // ACCURATE_BED_LEVELING not defined
1509
+#else // AUTO_BED_LEVELING_GRID not defined
1546
 
1510
 
1547
-
1548
-  #ifdef AUTO_BED_LEVELING_ANY_POINTS
1549
             // Probe at 3 arbitrary points
1511
             // Probe at 3 arbitrary points
1550
             // probe 1
1512
             // probe 1
1551
             float z_at_pt_1 = probe_pt(ABL_PROBE_PT_1_X, ABL_PROBE_PT_1_Y, Z_RAISE_BEFORE_PROBING);
1513
             float z_at_pt_1 = probe_pt(ABL_PROBE_PT_1_X, ABL_PROBE_PT_1_Y, Z_RAISE_BEFORE_PROBING);
1558
 
1520
 
1559
             clean_up_after_endstop_move();
1521
             clean_up_after_endstop_move();
1560
 
1522
 
1561
-            set_bed_level_equation_any_pts(z_at_pt_1, z_at_pt_2, z_at_pt_3);
1562
-  #else // not AUTO_BED_LEVELING_ANY_POINTS
1563
-            // probe at 3 corners of a rectangle
1564
-            // probe 1
1565
-            float z_at_xLeft_yBack = probe_pt(LEFT_PROBE_BED_POSITION, BACK_PROBE_BED_POSITION, Z_RAISE_BEFORE_PROBING);
1523
+            set_bed_level_equation_3pts(z_at_pt_1, z_at_pt_2, z_at_pt_3);
1566
 
1524
 
1567
-            // probe 2
1568
-            float z_at_xLeft_yFront = probe_pt(LEFT_PROBE_BED_POSITION, FRONT_PROBE_BED_POSITION, current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS);
1569
-
1570
-            // probe 3
1571
-            float z_at_xRight_yFront = probe_pt(RIGHT_PROBE_BED_POSITION, FRONT_PROBE_BED_POSITION, current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS);
1572
-
1573
-            clean_up_after_endstop_move();
1574
-
1575
-            set_bed_level_equation(z_at_xLeft_yFront, z_at_xRight_yFront, z_at_xLeft_yBack);
1576
-  #endif
1577
 
1525
 
1578
-#endif // ACCURATE_BED_LEVELING
1526
+#endif // AUTO_BED_LEVELING_GRID
1579
             st_synchronize();
1527
             st_synchronize();
1580
 
1528
 
1581
             // The following code correct the Z height difference from z-probe position and hotend tip position.
1529
             // The following code correct the Z height difference from z-probe position and hotend tip position.

+ 1
- 1
Marlin/qr_solve.cpp View File

1
 #include "qr_solve.h"
1
 #include "qr_solve.h"
2
 
2
 
3
-#ifdef ACCURATE_BED_LEVELING
3
+#ifdef AUTO_BED_LEVELING_GRID
4
 
4
 
5
 #include <stdlib.h>
5
 #include <stdlib.h>
6
 #include <math.h>
6
 #include <math.h>

+ 1
- 1
Marlin/qr_solve.h View File

1
 #include "Configuration.h"
1
 #include "Configuration.h"
2
 
2
 
3
-#ifdef ACCURATE_BED_LEVELING
3
+#ifdef AUTO_BED_LEVELING_GRID
4
 
4
 
5
 void daxpy ( int n, double da, double dx[], int incx, double dy[], int incy );
5
 void daxpy ( int n, double da, double dx[], int incx, double dy[], int incy );
6
 double ddot ( int n, double dx[], int incx, double dy[], int incy );
6
 double ddot ( int n, double dx[], int incx, double dy[], int incy );

Loading…
Cancel
Save