Explorar el Código

Merge pull request #774 from MissionSt/cleanup/probe_pt

Refactor of z probing for auto bed leveling
nothinman hace 11 años
padre
commit
a466c8ef68
Se han modificado 1 ficheros con 29 adiciones y 62 borrados
  1. 29
    62
      Marlin/Marlin_main.cpp

+ 29
- 62
Marlin/Marlin_main.cpp Ver fichero

@@ -978,6 +978,27 @@ static void retract_z_probe() {
978 978
     #endif
979 979
 }
980 980
 
981
+/// Probe bed height at position (x,y), returns the measured z value
982
+static float probe_pt(float x, float y, float z_before) {
983
+  // move to right place
984
+  do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], z_before);
985
+  do_blocking_move_to(x - X_PROBE_OFFSET_FROM_EXTRUDER, y - Y_PROBE_OFFSET_FROM_EXTRUDER, current_position[Z_AXIS]);
986
+
987
+  engage_z_probe();   // Engage Z Servo endstop if available
988
+  run_z_probe();
989
+  float measured_z = current_position[Z_AXIS];
990
+  retract_z_probe();
991
+
992
+  SERIAL_PROTOCOLPGM("Bed x: ");
993
+  SERIAL_PROTOCOL(x);
994
+  SERIAL_PROTOCOLPGM(" y: ");
995
+  SERIAL_PROTOCOL(y);
996
+  SERIAL_PROTOCOLPGM(" z: ");
997
+  SERIAL_PROTOCOL(measured_z);
998
+  SERIAL_PROTOCOLPGM("\n");
999
+  return measured_z;
1000
+}
1001
+
981 1002
 #endif // #ifdef ENABLE_AUTO_BED_LEVELING
982 1003
 
983 1004
 static void homeaxis(int axis) {
@@ -1415,31 +1436,20 @@ void process_commands()
1415 1436
 
1416 1437
               for (int xCount=0; xCount < ACCURATE_BED_LEVELING_POINTS; xCount++)
1417 1438
               {
1439
+                float z_before;
1418 1440
                 if (probePointCounter == 0)
1419 1441
                 {
1420 1442
                   // raise before probing
1421
-                  do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], Z_RAISE_BEFORE_PROBING);
1443
+                  z_before = Z_RAISE_BEFORE_PROBING;
1422 1444
                 } else
1423 1445
                 {
1424 1446
                   // raise extruder
1425
-                  do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS);
1447
+                  z_before = current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS;
1426 1448
                 }
1427 1449
 
1450
+                float measured_z = probe_pt(xProbe, yProbe, z_before);
1428 1451
 
1429
-                do_blocking_move_to(xProbe - X_PROBE_OFFSET_FROM_EXTRUDER, yProbe - Y_PROBE_OFFSET_FROM_EXTRUDER, current_position[Z_AXIS]);
1430
-
1431
-                engage_z_probe();   // Engage Z Servo endstop if available
1432
-                run_z_probe();
1433
-                eqnBVector[probePointCounter] = current_position[Z_AXIS];
1434
-                retract_z_probe();
1435
-
1436
-                SERIAL_PROTOCOLPGM("Bed x: ");
1437
-                SERIAL_PROTOCOL(xProbe);
1438
-                SERIAL_PROTOCOLPGM(" y: ");
1439
-                SERIAL_PROTOCOL(yProbe);
1440
-                SERIAL_PROTOCOLPGM(" z: ");
1441
-                SERIAL_PROTOCOL(current_position[Z_AXIS]);
1442
-                SERIAL_PROTOCOLPGM("\n");
1452
+                eqnBVector[probePointCounter] = measured_z;
1443 1453
 
1444 1454
                 eqnAMatrix[probePointCounter + 0*ACCURATE_BED_LEVELING_POINTS*ACCURATE_BED_LEVELING_POINTS] = xProbe;
1445 1455
                 eqnAMatrix[probePointCounter + 1*ACCURATE_BED_LEVELING_POINTS*ACCURATE_BED_LEVELING_POINTS] = yProbe;
@@ -1469,56 +1479,13 @@ void process_commands()
1469 1479
 
1470 1480
 
1471 1481
             // prob 1
1472
-            do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], Z_RAISE_BEFORE_PROBING);
1473
-            do_blocking_move_to(LEFT_PROBE_BED_POSITION - X_PROBE_OFFSET_FROM_EXTRUDER, BACK_PROBE_BED_POSITION - Y_PROBE_OFFSET_FROM_EXTRUDER, current_position[Z_AXIS]);
1474
-
1475
-            engage_z_probe();   // Engage Z Servo endstop if available
1476
-            run_z_probe();
1477
-            float z_at_xLeft_yBack = current_position[Z_AXIS];
1478
-            retract_z_probe();
1479
-
1480
-            SERIAL_PROTOCOLPGM("Bed x: ");
1481
-            SERIAL_PROTOCOL(LEFT_PROBE_BED_POSITION);
1482
-            SERIAL_PROTOCOLPGM(" y: ");
1483
-            SERIAL_PROTOCOL(BACK_PROBE_BED_POSITION);
1484
-            SERIAL_PROTOCOLPGM(" z: ");
1485
-            SERIAL_PROTOCOL(current_position[Z_AXIS]);
1486
-            SERIAL_PROTOCOLPGM("\n");
1482
+            float z_at_xLeft_yBack = probe_pt(LEFT_PROBE_BED_POSITION, BACK_PROBE_BED_POSITION, Z_RAISE_BEFORE_PROBING);
1487 1483
 
1488 1484
             // prob 2
1489
-            do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS);
1490
-            do_blocking_move_to(LEFT_PROBE_BED_POSITION - X_PROBE_OFFSET_FROM_EXTRUDER, FRONT_PROBE_BED_POSITION - Y_PROBE_OFFSET_FROM_EXTRUDER, current_position[Z_AXIS]);
1491
-
1492
-            engage_z_probe();   // Engage Z Servo endstop if available
1493
-            run_z_probe();
1494
-            float z_at_xLeft_yFront = current_position[Z_AXIS];
1495
-            retract_z_probe();
1496
-
1497
-            SERIAL_PROTOCOLPGM("Bed x: ");
1498
-            SERIAL_PROTOCOL(LEFT_PROBE_BED_POSITION);
1499
-            SERIAL_PROTOCOLPGM(" y: ");
1500
-            SERIAL_PROTOCOL(FRONT_PROBE_BED_POSITION);
1501
-            SERIAL_PROTOCOLPGM(" z: ");
1502
-            SERIAL_PROTOCOL(current_position[Z_AXIS]);
1503
-            SERIAL_PROTOCOLPGM("\n");
1485
+            float z_at_xLeft_yFront = probe_pt(LEFT_PROBE_BED_POSITION, FRONT_PROBE_BED_POSITION, current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS);
1504 1486
 
1505 1487
             // prob 3
1506
-            do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS);
1507
-            // the current position will be updated by the blocking move so the head will not lower on this next call.
1508
-            do_blocking_move_to(RIGHT_PROBE_BED_POSITION - X_PROBE_OFFSET_FROM_EXTRUDER, FRONT_PROBE_BED_POSITION - Y_PROBE_OFFSET_FROM_EXTRUDER, current_position[Z_AXIS]);
1509
-
1510
-            engage_z_probe();   // Engage Z Servo endstop if available
1511
-            run_z_probe();
1512
-            float z_at_xRight_yFront = current_position[Z_AXIS];
1513
-            retract_z_probe(); // Retract Z Servo endstop if available
1514
-
1515
-            SERIAL_PROTOCOLPGM("Bed x: ");
1516
-            SERIAL_PROTOCOL(RIGHT_PROBE_BED_POSITION);
1517
-            SERIAL_PROTOCOLPGM(" y: ");
1518
-            SERIAL_PROTOCOL(FRONT_PROBE_BED_POSITION);
1519
-            SERIAL_PROTOCOLPGM(" z: ");
1520
-            SERIAL_PROTOCOL(current_position[Z_AXIS]);
1521
-            SERIAL_PROTOCOLPGM("\n");
1488
+            float z_at_xRight_yFront = probe_pt(RIGHT_PROBE_BED_POSITION, FRONT_PROBE_BED_POSITION, current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS);
1522 1489
 
1523 1490
             clean_up_after_endstop_move();
1524 1491
 

Loading…
Cancelar
Guardar