瀏覽代碼

Merge pull request #1992 from thinkyhead/too_many_probes

Stow Z probe on M402 without extra raise
Scott Lahteine 10 年之前
父節點
當前提交
1f039cde61
共有 1 個文件被更改,包括 54 次插入34 次删除
  1. 54
    34
      Marlin/Marlin_main.cpp

+ 54
- 34
Marlin/Marlin_main.cpp 查看文件

@@ -1268,13 +1268,14 @@ inline void set_destination_to_current() { memcpy(destination, current_position,
1268 1268
 
1269 1269
       // Engage Z Servo endstop if enabled
1270 1270
       if (servo_endstops[Z_AXIS] >= 0) {
1271
+        Servo *srv = &servo[servo_endstops[Z_AXIS]];
1271 1272
         #if SERVO_LEVELING
1272
-          servo[servo_endstops[Z_AXIS]].attach(0);
1273
+          srv->attach(0);
1273 1274
         #endif
1274
-        servo[servo_endstops[Z_AXIS]].write(servo_endstop_angles[Z_AXIS * 2]);
1275
+        srv->write(servo_endstop_angles[Z_AXIS * 2]);
1275 1276
         #if SERVO_LEVELING
1276 1277
           delay(PROBE_SERVO_DEACTIVATION_DELAY);
1277
-          servo[servo_endstops[Z_AXIS]].detach();
1278
+          srv->detach();
1278 1279
         #endif
1279 1280
       }
1280 1281
 
@@ -1320,7 +1321,7 @@ inline void set_destination_to_current() { memcpy(destination, current_position,
1320 1321
 
1321 1322
   }
1322 1323
 
1323
-  static void stow_z_probe() {
1324
+  static void stow_z_probe(bool doRaise=true) {
1324 1325
 
1325 1326
     #ifdef SERVO_ENDSTOPS
1326 1327
 
@@ -1328,19 +1329,21 @@ inline void set_destination_to_current() { memcpy(destination, current_position,
1328 1329
       if (servo_endstops[Z_AXIS] >= 0) {
1329 1330
 
1330 1331
         #if Z_RAISE_AFTER_PROBING > 0
1331
-          do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] + Z_RAISE_AFTER_PROBING); // this also updates current_position
1332
-          st_synchronize();
1332
+          if (doRaise) {
1333
+            do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] + Z_RAISE_AFTER_PROBING); // this also updates current_position
1334
+            st_synchronize();
1335
+          }
1333 1336
         #endif
1334 1337
 
1338
+        // Change the Z servo angle
1339
+        Servo *srv = &servo[servo_endstops[Z_AXIS]];
1335 1340
         #if SERVO_LEVELING
1336
-          servo[servo_endstops[Z_AXIS]].attach(0);
1341
+          srv->attach(0);
1337 1342
         #endif
1338
-
1339
-        servo[servo_endstops[Z_AXIS]].write(servo_endstop_angles[Z_AXIS * 2 + 1]);
1340
-
1343
+        srv->write(servo_endstop_angles[Z_AXIS * 2 + 1]);
1341 1344
         #if SERVO_LEVELING
1342 1345
           delay(PROBE_SERVO_DEACTIVATION_DELAY);
1343
-          servo[servo_endstops[Z_AXIS]].detach();
1346
+          srv->detach();
1344 1347
         #endif
1345 1348
       }
1346 1349
 
@@ -1524,19 +1527,25 @@ static void homeaxis(AxisEnum axis) {
1524 1527
     current_position[axis] = 0;
1525 1528
     sync_plan_position();
1526 1529
 
1527
-    // Engage Servo endstop if enabled
1528
-    #if defined(SERVO_ENDSTOPS) && !defined(Z_PROBE_SLED)
1530
+    #if SERVO_LEVELING && !defined(Z_PROBE_SLED)
1529 1531
 
1530
-      #if SERVO_LEVELING
1531
-        if (axis == Z_AXIS) deploy_z_probe(); else
1532
-      #endif
1533
-        {
1534
-          if (servo_endstops[axis] > -1)
1535
-            servo[servo_endstops[axis]].write(servo_endstop_angles[axis * 2]);
1536
-        }
1532
+      // Deploy a probe if there is one, and homing towards the bed
1533
+      if (axis == Z_AXIS) {
1534
+        if (axis_home_dir < 0) deploy_z_probe();
1535
+      }
1536
+      else
1537 1537
 
1538
-    #endif // SERVO_ENDSTOPS && !Z_PROBE_SLED
1538
+    #endif
1539 1539
 
1540
+    #ifdef SERVO_ENDSTOPS
1541
+      {
1542
+        // Engage Servo endstop if enabled
1543
+        if (servo_endstops[axis] > -1)
1544
+          servo[servo_endstops[axis]].write(servo_endstop_angles[axis * 2]);
1545
+      }
1546
+    #endif
1547
+
1548
+    // Set a flag for Z motor locking
1540 1549
     #ifdef Z_DUAL_ENDSTOPS
1541 1550
       if (axis == Z_AXIS) In_Homing_Process(true);
1542 1551
     #endif
@@ -1614,14 +1623,22 @@ static void homeaxis(AxisEnum axis) {
1614 1623
     endstops_hit_on_purpose(); // clear endstop hit flags
1615 1624
     axis_known_position[axis] = true;
1616 1625
 
1617
-    // Retract Servo endstop if enabled
1618
-    #ifdef SERVO_ENDSTOPS
1619
-      if (servo_endstops[axis] > -1)
1620
-        servo[servo_endstops[axis]].write(servo_endstop_angles[axis * 2 + 1]);
1626
+    #if SERVO_LEVELING && !defined(Z_PROBE_SLED)
1627
+
1628
+      // Deploy a probe if there is one, and homing towards the bed
1629
+      if (axis == Z_AXIS) {
1630
+        if (axis_home_dir < 0) stow_z_probe();
1631
+      }
1632
+      else
1633
+
1621 1634
     #endif
1622 1635
 
1623
-    #if SERVO_LEVELING && !defined(Z_PROBE_SLED)
1624
-      if (axis == Z_AXIS) stow_z_probe();
1636
+    #ifdef SERVO_ENDSTOPS
1637
+      {
1638
+        // Retract Servo endstop if enabled
1639
+        if (servo_endstops[axis] > -1)
1640
+          servo[servo_endstops[axis]].write(servo_endstop_angles[axis * 2 + 1]);
1641
+      }
1625 1642
     #endif
1626 1643
 
1627 1644
   }
@@ -2998,7 +3015,7 @@ inline void gcode_M42() {
2998 3015
     current_position[E_AXIS] = E_current = st_get_position_mm(E_AXIS);
2999 3016
 
3000 3017
     // 
3001
-    // OK, do the inital probe to get us close to the bed.
3018
+    // OK, do the initial probe to get us close to the bed.
3002 3019
     // Then retrace the right amount and use that in subsequent probes
3003 3020
     //
3004 3021
 
@@ -3107,12 +3124,14 @@ inline void gcode_M42() {
3107 3124
       plan_buffer_line(X_probe_location, Y_probe_location, Z_start_location, current_position[E_AXIS], homing_feedrate[Z_AXIS]/60, active_extruder);
3108 3125
       st_synchronize();
3109 3126
 
3127
+      // Stow between
3110 3128
       if (deploy_probe_for_each_reading) {
3111 3129
         stow_z_probe();
3112 3130
         delay(1000);
3113 3131
       }
3114 3132
     }
3115 3133
 
3134
+    // Stow after
3116 3135
     if (!deploy_probe_for_each_reading) {
3117 3136
       stow_z_probe();
3118 3137
       delay(1000);
@@ -4064,13 +4083,14 @@ inline void gcode_M226() {
4064 4083
     if (code_seen('S')) {
4065 4084
       servo_position = code_value();
4066 4085
       if ((servo_index >= 0) && (servo_index < NUM_SERVOS)) {
4086
+        Servo *srv = &servo[servo_index];
4067 4087
         #if SERVO_LEVELING
4068
-          servo[servo_index].attach(0);
4088
+          srv->attach(0);
4069 4089
         #endif
4070
-        servo[servo_index].write(servo_position);
4090
+        srv->write(servo_position);
4071 4091
         #if SERVO_LEVELING
4072 4092
           delay(PROBE_SERVO_DEACTIVATION_DELAY);
4073
-          servo[servo_index].detach();
4093
+          srv->detach();
4074 4094
         #endif
4075 4095
       }
4076 4096
       else {
@@ -4374,12 +4394,12 @@ inline void gcode_M303() {
4374 4394
  */
4375 4395
 inline void gcode_M400() { st_synchronize(); }
4376 4396
 
4377
-#if defined(ENABLE_AUTO_BED_LEVELING) && (defined(SERVO_ENDSTOPS) || defined(Z_PROBE_ALLEN_KEY)) && not defined(Z_PROBE_SLED)
4397
+#if defined(ENABLE_AUTO_BED_LEVELING) && !defined(Z_PROBE_SLED) && (defined(SERVO_ENDSTOPS) || defined(Z_PROBE_ALLEN_KEY))
4378 4398
 
4379 4399
   #ifdef SERVO_ENDSTOPS
4380 4400
     void raise_z_for_servo() {
4381 4401
       float zpos = current_position[Z_AXIS], z_dest = Z_RAISE_BEFORE_HOMING;
4382
-      if (!axis_known_position[Z_AXIS]) z_dest += zpos;
4402
+      z_dest += axis_known_position[Z_AXIS] ? -zprobe_zoffset : zpos;
4383 4403
       if (zpos < z_dest)
4384 4404
         do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], z_dest); // also updates current_position
4385 4405
     }
@@ -4402,7 +4422,7 @@ inline void gcode_M400() { st_synchronize(); }
4402 4422
     #ifdef SERVO_ENDSTOPS
4403 4423
       raise_z_for_servo();
4404 4424
     #endif
4405
-    stow_z_probe();
4425
+    stow_z_probe(false);
4406 4426
   }
4407 4427
 
4408 4428
 #endif

Loading…
取消
儲存