Browse Source

Add macros to move servos

Scott Lahteine 8 years ago
parent
commit
4fbe818163
1 changed files with 17 additions and 10 deletions
  1. 17
    10
      Marlin/Marlin_main.cpp

+ 17
- 10
Marlin/Marlin_main.cpp View File

@@ -487,6 +487,11 @@ static bool send_ok[BUFSIZE];
487 487
 
488 488
 #if HAS_SERVOS
489 489
   Servo servo[NUM_SERVOS];
490
+  #define MOVE_SERVO(I, P) servo[I].move(P)
491
+  #define SERVO_ENDSTOP_EXISTS(I) (servo_endstop_id[I] >= 0)
492
+  #define MOVE_SERVO_ENDSTOP(I, J) MOVE_SERVO(servo_endstop_id[I], servo_endstop_angle[I][J])
493
+  #define DEPLOY_SERVO_ENDSTOP(I) MOVE_SERVO_ENDSTOP(I, 0)
494
+  #define STOW_SERVO_ENDSTOP(I) MOVE_SERVO_ENDSTOP(I, 1)
490 495
 #endif
491 496
 
492 497
 #ifdef CHDK
@@ -760,8 +765,8 @@ void servo_init() {
760 765
      *
761 766
      */
762 767
     for (int i = 0; i < 3; i++)
763
-      if (servo_endstop_id[i] >= 0)
764
-        servo[servo_endstop_id[i]].move(servo_endstop_angle[i][1]);
768
+      if (SERVO_ENDSTOP_EXISTS(i))
769
+        STOW_SERVO_ENDSTOP(i);
765 770
 
766 771
   #endif // HAS_SERVO_ENDSTOPS
767 772
 
@@ -1825,7 +1830,8 @@ static void setup_for_endstop_move() {
1825 1830
     #if ENABLED(HAS_SERVO_ENDSTOPS)
1826 1831
 
1827 1832
       // Engage Z Servo endstop if enabled
1828
-      if (servo_endstop_id[Z_AXIS] >= 0) servo[servo_endstop_id[Z_AXIS]].move(servo_endstop_angle[Z_AXIS][0]);
1833
+      if (SERVO_ENDSTOP_EXISTS(Z_AXIS)
1834
+        DEPLOY_SERVO_ENDSTOP(Z_AXIS);
1829 1835
 
1830 1836
     #elif ENABLED(Z_PROBE_ALLEN_KEY)
1831 1837
       feedrate = Z_PROBE_ALLEN_KEY_DEPLOY_1_FEEDRATE;
@@ -1921,7 +1927,7 @@ static void setup_for_endstop_move() {
1921 1927
     #if ENABLED(HAS_SERVO_ENDSTOPS)
1922 1928
 
1923 1929
       // Retract Z Servo endstop if enabled
1924
-      if (servo_endstop_id[Z_AXIS] >= 0) {
1930
+      if (SERVO_ENDSTOP_EXISTS(Z_AXIS)) {
1925 1931
 
1926 1932
         #if Z_RAISE_AFTER_PROBING > 0
1927 1933
           if (doRaise) {
@@ -1931,7 +1937,7 @@ static void setup_for_endstop_move() {
1931 1937
         #endif
1932 1938
 
1933 1939
         // Change the Z servo angle
1934
-        servo[servo_endstop_id[Z_AXIS]].move(servo_endstop_angle[Z_AXIS][1]);
1940
+        STOW_SERVO_ENDSTOP(Z_AXIS);
1935 1941
       }
1936 1942
 
1937 1943
     #elif ENABLED(Z_PROBE_ALLEN_KEY)
@@ -2288,8 +2294,8 @@ static void homeaxis(AxisEnum axis) {
2288 2294
 
2289 2295
     #if ENABLED(HAS_SERVO_ENDSTOPS)
2290 2296
       // Engage an X, Y (or Z) Servo endstop if enabled
2291
-      if (_Z_SERVO_TEST && servo_endstop_id[axis] >= 0) {
2292
-        servo[servo_endstop_id[axis]].move(servo_endstop_angle[axis][0]);
2297
+      if (_Z_SERVO_TEST && SERVO_ENDSTOP_EXISTS(axis)) {
2298
+        DEPLOY_SERVO_ENDSTOP(axis);
2293 2299
         if (_Z_SERVO_SUBTEST) endstops.z_probe_enabled = true;
2294 2300
       }
2295 2301
     #endif
@@ -2419,7 +2425,7 @@ static void homeaxis(AxisEnum axis) {
2419 2425
 
2420 2426
     // Retract X, Y (or Z) Servo endstop if enabled
2421 2427
     #if ENABLED(HAS_SERVO_ENDSTOPS)
2422
-      if (_Z_SERVO_TEST && servo_endstop_id[axis] >= 0) {
2428
+      if (_Z_SERVO_TEST && SERVO_ENDSTOP_EXISTS(axis)) {
2423 2429
         // Raise the servo probe before stow outside ABL context.
2424 2430
         // This is a workaround to allow use of a Servo Probe without
2425 2431
         // ABL until more global probe handling is implemented.
@@ -2438,7 +2444,7 @@ static void homeaxis(AxisEnum axis) {
2438 2444
         #if ENABLED(DEBUG_LEVELING_FEATURE)
2439 2445
           if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("> SERVO_ENDSTOPS > Stow with servo.move()");
2440 2446
         #endif
2441
-        servo[servo_endstop_id[axis]].move(servo_endstop_angle[axis][1]);
2447
+        STOW_SERVO_ENDSTOP(axis);
2442 2448
         if (_Z_SERVO_SUBTEST) endstops.enable_z_probe(false);
2443 2449
       }
2444 2450
 
@@ -5673,7 +5679,7 @@ inline void gcode_M226() {
5673 5679
     if (code_seen('S')) {
5674 5680
       servo_position = code_value_int();
5675 5681
       if (servo_index >= 0 && servo_index < NUM_SERVOS)
5676
-        servo[servo_index].move(servo_position);
5682
+        MOVE_SERVO(servo_index, servo_position);
5677 5683
       else {
5678 5684
         SERIAL_ERROR_START;
5679 5685
         SERIAL_ERROR("Servo ");
@@ -6680,6 +6686,7 @@ inline void gcode_T(uint8_t tmp_extruder) {
6680 6686
 
6681 6687
           offset_vec.apply_rotation(planner.bed_level_matrix.transpose(planner.bed_level_matrix));
6682 6688
 
6689
+          // Adjust the current position
6683 6690
           current_position[X_AXIS] += offset_vec.x;
6684 6691
           current_position[Y_AXIS] += offset_vec.y;
6685 6692
           current_position[Z_AXIS] += offset_vec.z;

Loading…
Cancel
Save