Bladeren bron

Merge pull request #1992 from thinkyhead/too_many_probes

Stow Z probe on M402 without extra raise
Scott Lahteine 10 jaren geleden
bovenliggende
commit
1f039cde61
1 gewijzigde bestanden met toevoegingen van 54 en 34 verwijderingen
  1. 54
    34
      Marlin/Marlin_main.cpp

+ 54
- 34
Marlin/Marlin_main.cpp Bestand weergeven

1268
 
1268
 
1269
       // Engage Z Servo endstop if enabled
1269
       // Engage Z Servo endstop if enabled
1270
       if (servo_endstops[Z_AXIS] >= 0) {
1270
       if (servo_endstops[Z_AXIS] >= 0) {
1271
+        Servo *srv = &servo[servo_endstops[Z_AXIS]];
1271
         #if SERVO_LEVELING
1272
         #if SERVO_LEVELING
1272
-          servo[servo_endstops[Z_AXIS]].attach(0);
1273
+          srv->attach(0);
1273
         #endif
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
         #if SERVO_LEVELING
1276
         #if SERVO_LEVELING
1276
           delay(PROBE_SERVO_DEACTIVATION_DELAY);
1277
           delay(PROBE_SERVO_DEACTIVATION_DELAY);
1277
-          servo[servo_endstops[Z_AXIS]].detach();
1278
+          srv->detach();
1278
         #endif
1279
         #endif
1279
       }
1280
       }
1280
 
1281
 
1320
 
1321
 
1321
   }
1322
   }
1322
 
1323
 
1323
-  static void stow_z_probe() {
1324
+  static void stow_z_probe(bool doRaise=true) {
1324
 
1325
 
1325
     #ifdef SERVO_ENDSTOPS
1326
     #ifdef SERVO_ENDSTOPS
1326
 
1327
 
1328
       if (servo_endstops[Z_AXIS] >= 0) {
1329
       if (servo_endstops[Z_AXIS] >= 0) {
1329
 
1330
 
1330
         #if Z_RAISE_AFTER_PROBING > 0
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
         #endif
1336
         #endif
1334
 
1337
 
1338
+        // Change the Z servo angle
1339
+        Servo *srv = &servo[servo_endstops[Z_AXIS]];
1335
         #if SERVO_LEVELING
1340
         #if SERVO_LEVELING
1336
-          servo[servo_endstops[Z_AXIS]].attach(0);
1341
+          srv->attach(0);
1337
         #endif
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
         #if SERVO_LEVELING
1344
         #if SERVO_LEVELING
1342
           delay(PROBE_SERVO_DEACTIVATION_DELAY);
1345
           delay(PROBE_SERVO_DEACTIVATION_DELAY);
1343
-          servo[servo_endstops[Z_AXIS]].detach();
1346
+          srv->detach();
1344
         #endif
1347
         #endif
1345
       }
1348
       }
1346
 
1349
 
1524
     current_position[axis] = 0;
1527
     current_position[axis] = 0;
1525
     sync_plan_position();
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
     #ifdef Z_DUAL_ENDSTOPS
1549
     #ifdef Z_DUAL_ENDSTOPS
1541
       if (axis == Z_AXIS) In_Homing_Process(true);
1550
       if (axis == Z_AXIS) In_Homing_Process(true);
1542
     #endif
1551
     #endif
1614
     endstops_hit_on_purpose(); // clear endstop hit flags
1623
     endstops_hit_on_purpose(); // clear endstop hit flags
1615
     axis_known_position[axis] = true;
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
     #endif
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
     #endif
1642
     #endif
1626
 
1643
 
1627
   }
1644
   }
2998
     current_position[E_AXIS] = E_current = st_get_position_mm(E_AXIS);
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
     // Then retrace the right amount and use that in subsequent probes
3019
     // Then retrace the right amount and use that in subsequent probes
3003
     //
3020
     //
3004
 
3021
 
3107
       plan_buffer_line(X_probe_location, Y_probe_location, Z_start_location, current_position[E_AXIS], homing_feedrate[Z_AXIS]/60, active_extruder);
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
       st_synchronize();
3125
       st_synchronize();
3109
 
3126
 
3127
+      // Stow between
3110
       if (deploy_probe_for_each_reading) {
3128
       if (deploy_probe_for_each_reading) {
3111
         stow_z_probe();
3129
         stow_z_probe();
3112
         delay(1000);
3130
         delay(1000);
3113
       }
3131
       }
3114
     }
3132
     }
3115
 
3133
 
3134
+    // Stow after
3116
     if (!deploy_probe_for_each_reading) {
3135
     if (!deploy_probe_for_each_reading) {
3117
       stow_z_probe();
3136
       stow_z_probe();
3118
       delay(1000);
3137
       delay(1000);
4064
     if (code_seen('S')) {
4083
     if (code_seen('S')) {
4065
       servo_position = code_value();
4084
       servo_position = code_value();
4066
       if ((servo_index >= 0) && (servo_index < NUM_SERVOS)) {
4085
       if ((servo_index >= 0) && (servo_index < NUM_SERVOS)) {
4086
+        Servo *srv = &servo[servo_index];
4067
         #if SERVO_LEVELING
4087
         #if SERVO_LEVELING
4068
-          servo[servo_index].attach(0);
4088
+          srv->attach(0);
4069
         #endif
4089
         #endif
4070
-        servo[servo_index].write(servo_position);
4090
+        srv->write(servo_position);
4071
         #if SERVO_LEVELING
4091
         #if SERVO_LEVELING
4072
           delay(PROBE_SERVO_DEACTIVATION_DELAY);
4092
           delay(PROBE_SERVO_DEACTIVATION_DELAY);
4073
-          servo[servo_index].detach();
4093
+          srv->detach();
4074
         #endif
4094
         #endif
4075
       }
4095
       }
4076
       else {
4096
       else {
4374
  */
4394
  */
4375
 inline void gcode_M400() { st_synchronize(); }
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
   #ifdef SERVO_ENDSTOPS
4399
   #ifdef SERVO_ENDSTOPS
4380
     void raise_z_for_servo() {
4400
     void raise_z_for_servo() {
4381
       float zpos = current_position[Z_AXIS], z_dest = Z_RAISE_BEFORE_HOMING;
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
       if (zpos < z_dest)
4403
       if (zpos < z_dest)
4384
         do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], z_dest); // also updates current_position
4404
         do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], z_dest); // also updates current_position
4385
     }
4405
     }
4402
     #ifdef SERVO_ENDSTOPS
4422
     #ifdef SERVO_ENDSTOPS
4403
       raise_z_for_servo();
4423
       raise_z_for_servo();
4404
     #endif
4424
     #endif
4405
-    stow_z_probe();
4425
+    stow_z_probe(false);
4406
   }
4426
   }
4407
 
4427
 
4408
 #endif
4428
 #endif

Laden…
Annuleren
Opslaan