Преглед на файлове

Clean up, document home_axis

Scott Lahteine преди 10 години
родител
ревизия
97a258b0b0
променени са 1 файла, в които са добавени 71 реда и са изтрити 62 реда
  1. 71
    62
      Marlin/Marlin_main.cpp

+ 71
- 62
Marlin/Marlin_main.cpp Целия файл

@@ -1109,7 +1109,7 @@ inline void sync_plan_position() {
1109 1109
       destination[Z_AXIS] = -10;
1110 1110
       prepare_move_raw();
1111 1111
       st_synchronize();
1112
-      endstops_hit_on_purpose();
1112
+      endstops_hit_on_purpose(); // clear endstop hit flags
1113 1113
       
1114 1114
       // we have to let the planner know where we are right now as it is not where we said to go.
1115 1115
       long stop_steps = st_get_position(Z_AXIS);
@@ -1135,7 +1135,7 @@ inline void sync_plan_position() {
1135 1135
       zPosition += home_retract_mm(Z_AXIS);
1136 1136
       line_to_z(zPosition);
1137 1137
       st_synchronize();
1138
-      endstops_hit_on_purpose();
1138
+      endstops_hit_on_purpose(); // clear endstop hit flags
1139 1139
 
1140 1140
       // move back down slowly to find bed
1141 1141
       if (homing_bump_divisor[Z_AXIS] >= 1)
@@ -1148,7 +1148,7 @@ inline void sync_plan_position() {
1148 1148
       zPosition -= home_retract_mm(Z_AXIS) * 2;
1149 1149
       line_to_z(zPosition);
1150 1150
       st_synchronize();
1151
-      endstops_hit_on_purpose();
1151
+      endstops_hit_on_purpose(); // clear endstop hit flags
1152 1152
 
1153 1153
       current_position[Z_AXIS] = st_get_position_mm(Z_AXIS);
1154 1154
       // make sure the planner knows where we are as it may be a bit different than we last said to move to
@@ -1435,13 +1435,17 @@ inline void sync_plan_position() {
1435 1435
 
1436 1436
 #endif // ENABLE_AUTO_BED_LEVELING
1437 1437
 
1438
+/**
1439
+ * Home an individual axis
1440
+ */
1441
+
1442
+#define HOMEAXIS(LETTER) homeaxis(LETTER##_AXIS)
1443
+
1438 1444
 static void homeaxis(int axis) {
1439 1445
   #define HOMEAXIS_DO(LETTER) \
1440 1446
     ((LETTER##_MIN_PIN > -1 && LETTER##_HOME_DIR==-1) || (LETTER##_MAX_PIN > -1 && LETTER##_HOME_DIR==1))
1441 1447
 
1442
-  if (axis == X_AXIS ? HOMEAXIS_DO(X) :
1443
-      axis == Y_AXIS ? HOMEAXIS_DO(Y) :
1444
-      axis == Z_AXIS ? HOMEAXIS_DO(Z) : 0) {
1448
+  if (axis == X_AXIS ? HOMEAXIS_DO(X) : axis == Y_AXIS ? HOMEAXIS_DO(Y) : axis == Z_AXIS ? HOMEAXIS_DO(Z) : 0) {
1445 1449
 
1446 1450
     int axis_home_dir;
1447 1451
 
@@ -1451,108 +1455,112 @@ static void homeaxis(int axis) {
1451 1455
       axis_home_dir = home_dir(axis);
1452 1456
     #endif
1453 1457
 
1458
+    // Set the axis position as setup for the move
1454 1459
     current_position[axis] = 0;
1455 1460
     sync_plan_position();
1456 1461
 
1457
-    #ifndef Z_PROBE_SLED
1458
-      // Engage Servo endstop if enabled
1459
-      #ifdef SERVO_ENDSTOPS
1460
-        #if SERVO_LEVELING
1461
-          if (axis == Z_AXIS) {
1462
-            engage_z_probe();
1463
-          }
1464
-          else
1465
-        #endif // SERVO_LEVELING
1466
-
1467
-        if (servo_endstops[axis] > -1)
1468
-          servos[servo_endstops[axis]].write(servo_endstop_angles[axis * 2]);
1462
+    // Engage Servo endstop if enabled
1463
+    #ifdef SERVO_ENDSTOPS && !defined(Z_PROBE_SLED)
1469 1464
 
1470
-      #endif // SERVO_ENDSTOPS
1465
+      #if SERVO_LEVELING
1466
+        if (axis == Z_AXIS) engage_z_probe(); else
1467
+      #endif
1468
+        {
1469
+          if (servo_endstops[axis] > -1)
1470
+            servos[servo_endstops[axis]].write(servo_endstop_angles[axis * 2]);
1471
+        }
1471 1472
 
1472
-    #endif // Z_PROBE_SLED
1473
+    #endif // SERVO_ENDSTOPS && !Z_PROBE_SLED
1473 1474
 
1474 1475
     #ifdef Z_DUAL_ENDSTOPS
1475 1476
       if (axis == Z_AXIS) In_Homing_Process(true);
1476 1477
     #endif
1477 1478
 
1479
+    // Move towards the endstop until an endstop is triggered
1478 1480
     destination[axis] = 1.5 * max_length(axis) * axis_home_dir;
1479 1481
     feedrate = homing_feedrate[axis];
1480 1482
     line_to_destination();
1481 1483
     st_synchronize();
1482 1484
 
1485
+    // Set the axis position as setup for the move
1483 1486
     current_position[axis] = 0;
1484 1487
     sync_plan_position();
1488
+
1489
+    // Move away from the endstop by the axis HOME_RETRACT_MM
1485 1490
     destination[axis] = -home_retract_mm(axis) * axis_home_dir;
1486 1491
     line_to_destination();
1487 1492
     st_synchronize();
1488 1493
 
1489
-    destination[axis] = 2 * home_retract_mm(axis) * axis_home_dir;
1490
-
1494
+    // Slow down the feedrate for the next move
1491 1495
     if (homing_bump_divisor[axis] >= 1)
1492 1496
       feedrate = homing_feedrate[axis] / homing_bump_divisor[axis];
1493 1497
     else {
1494 1498
       feedrate = homing_feedrate[axis] / 10;
1495
-      SERIAL_ECHOLN("Warning: The Homing Bump Feedrate Divisor cannot be less than 1");
1499
+      SERIAL_ECHOLNPGM("Warning: The Homing Bump Feedrate Divisor cannot be less than 1");
1496 1500
     }
1497 1501
 
1502
+    // Move slowly towards the endstop until triggered
1503
+    destination[axis] = 2 * home_retract_mm(axis) * axis_home_dir;
1498 1504
     line_to_destination();
1499 1505
     st_synchronize();
1506
+
1500 1507
     #ifdef Z_DUAL_ENDSTOPS
1501
-      if (axis==Z_AXIS)
1502
-      {
1503
-        feedrate = homing_feedrate[axis];
1504
-        sync_plan_position();
1505
-        if (axis_home_dir > 0)
1506
-        {
1507
-          destination[axis] = (-1) * fabs(z_endstop_adj);
1508
-          if (z_endstop_adj > 0) Lock_z_motor(true); else Lock_z2_motor(true);
1509
-        } else {
1510
-          destination[axis] = fabs(z_endstop_adj);
1511
-          if (z_endstop_adj < 0) Lock_z_motor(true); else Lock_z2_motor(true);        
1508
+      if (axis == Z_AXIS) {
1509
+        float adj = fabs(z_endstop_adj);
1510
+        bool lockZ1;
1511
+        if (axis_home_dir > 0) {
1512
+          adj = -adj;
1513
+          lockZ1 = (z_endstop_adj > 0);
1512 1514
         }
1515
+        else
1516
+          lockZ1 = (z_endstop_adj < 0);
1517
+
1518
+        if (lockZ1) Lock_z_motor(true); else Lock_z2_motor(true);
1519
+        sync_plan_position();
1520
+
1521
+        // Move to the adjusted endstop height
1522
+        feedrate = homing_feedrate[axis];
1523
+        destination[Z_AXIS] = adj;
1513 1524
         line_to_destination();
1514 1525
         st_synchronize();
1515
-        Lock_z_motor(false);
1516
-        Lock_z2_motor(false);
1526
+
1527
+        if (lockZ1) Lock_z_motor(false); else Lock_z2_motor(false);
1517 1528
         In_Homing_Process(false);
1529
+      } // Z_AXIS
1530
+    #endif
1531
+
1532
+    #ifdef DELTA
1533
+      // retrace by the amount specified in endstop_adj
1534
+      if (endstop_adj[axis] * axis_home_dir < 0) {
1535
+        sync_plan_position();
1536
+        destination[axis] = endstop_adj[axis];
1537
+        line_to_destination();
1538
+        st_synchronize();
1518 1539
       }
1519 1540
     #endif
1520 1541
 
1521
-#ifdef DELTA
1522
-    // retrace by the amount specified in endstop_adj
1523
-    if (endstop_adj[axis] * axis_home_dir < 0) {
1524
-      sync_plan_position();
1525
-      destination[axis] = endstop_adj[axis];
1526
-      line_to_destination();
1527
-      st_synchronize();
1528
-    }
1529
-#endif
1542
+    // Set the axis position to its home position (plus home offsets)
1530 1543
     axis_is_at_home(axis);
1544
+
1531 1545
     destination[axis] = current_position[axis];
1532 1546
     feedrate = 0.0;
1533
-    endstops_hit_on_purpose();
1547
+    endstops_hit_on_purpose(); // clear endstop hit flags
1534 1548
     axis_known_position[axis] = true;
1535 1549
 
1536 1550
     // Retract Servo endstop if enabled
1537 1551
     #ifdef SERVO_ENDSTOPS
1538
-      if (servo_endstops[axis] > -1) {
1552
+      if (servo_endstops[axis] > -1)
1539 1553
         servos[servo_endstops[axis]].write(servo_endstop_angles[axis * 2 + 1]);
1540
-      }
1541 1554
     #endif
1542
-#if SERVO_LEVELING
1543
-  #ifndef Z_PROBE_SLED
1544
-    if (axis==Z_AXIS) retract_z_probe();
1545
-  #endif
1546
-#endif
1555
+
1556
+    #if SERVO_LEVELING && !defined(Z_PROBE_SLED)
1557
+      if (axis == Z_AXIS) retract_z_probe();
1558
+    #endif
1547 1559
 
1548 1560
   }
1549 1561
 }
1550
-#define HOMEAXIS(LETTER) homeaxis(LETTER##_AXIS)
1551 1562
 
1552
-void refresh_cmd_timeout(void)
1553
-{
1554
-  previous_millis_cmd = millis();
1555
-}
1563
+void refresh_cmd_timeout(void) { previous_millis_cmd = millis(); }
1556 1564
 
1557 1565
 #ifdef FWRETRACT
1558 1566
 
@@ -1780,7 +1788,7 @@ inline void gcode_G28() {
1780 1788
     feedrate = 1.732 * homing_feedrate[X_AXIS];
1781 1789
     line_to_destination();
1782 1790
     st_synchronize();
1783
-    endstops_hit_on_purpose();
1791
+    endstops_hit_on_purpose(); // clear endstop hit flags
1784 1792
 
1785 1793
     // Destination reached
1786 1794
     for (int i = X_AXIS; i <= Z_AXIS; i++) current_position[i] = destination[i];
@@ -1798,7 +1806,7 @@ inline void gcode_G28() {
1798 1806
           homeY = code_seen(axis_codes[Y_AXIS]),
1799 1807
           homeZ = code_seen(axis_codes[Z_AXIS]);
1800 1808
 
1801
-    home_all_axis = !homeX && !homeY && !homeZ; // No parameters means home all axes
1809
+    home_all_axis = !(homeX || homeY || homeZ) || (homeX && homeY && homeZ);
1802 1810
 
1803 1811
     #if Z_HOME_DIR > 0                      // If homing away from BED do Z first
1804 1812
 
@@ -1849,7 +1857,7 @@ inline void gcode_G28() {
1849 1857
         line_to_destination();
1850 1858
         feedrate = 0.0;
1851 1859
         st_synchronize();
1852
-        endstops_hit_on_purpose();
1860
+        endstops_hit_on_purpose(); // clear endstop hit flags
1853 1861
 
1854 1862
         current_position[X_AXIS] = destination[X_AXIS];
1855 1863
         current_position[Y_AXIS] = destination[Y_AXIS];
@@ -1857,6 +1865,7 @@ inline void gcode_G28() {
1857 1865
           current_position[Z_AXIS] = destination[Z_AXIS];
1858 1866
         #endif
1859 1867
       }
1868
+
1860 1869
     #endif // QUICK_HOME
1861 1870
 
1862 1871
     // Home X
@@ -2005,7 +2014,7 @@ inline void gcode_G28() {
2005 2014
   feedrate = saved_feedrate;
2006 2015
   feedmultiply = saved_feedmultiply;
2007 2016
   previous_millis_cmd = millis();
2008
-  endstops_hit_on_purpose();
2017
+  endstops_hit_on_purpose(); // clear endstop hit flags
2009 2018
 }
2010 2019
 
2011 2020
 #if defined(MESH_BED_LEVELING) || defined(ENABLE_AUTO_BED_LEVELING)

Loading…
Отказ
Запис