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
 
487
 
488
 #if HAS_SERVOS
488
 #if HAS_SERVOS
489
   Servo servo[NUM_SERVOS];
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
 #endif
495
 #endif
491
 
496
 
492
 #ifdef CHDK
497
 #ifdef CHDK
760
      *
765
      *
761
      */
766
      */
762
     for (int i = 0; i < 3; i++)
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
   #endif // HAS_SERVO_ENDSTOPS
771
   #endif // HAS_SERVO_ENDSTOPS
767
 
772
 
1825
     #if ENABLED(HAS_SERVO_ENDSTOPS)
1830
     #if ENABLED(HAS_SERVO_ENDSTOPS)
1826
 
1831
 
1827
       // Engage Z Servo endstop if enabled
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
     #elif ENABLED(Z_PROBE_ALLEN_KEY)
1836
     #elif ENABLED(Z_PROBE_ALLEN_KEY)
1831
       feedrate = Z_PROBE_ALLEN_KEY_DEPLOY_1_FEEDRATE;
1837
       feedrate = Z_PROBE_ALLEN_KEY_DEPLOY_1_FEEDRATE;
1921
     #if ENABLED(HAS_SERVO_ENDSTOPS)
1927
     #if ENABLED(HAS_SERVO_ENDSTOPS)
1922
 
1928
 
1923
       // Retract Z Servo endstop if enabled
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
         #if Z_RAISE_AFTER_PROBING > 0
1932
         #if Z_RAISE_AFTER_PROBING > 0
1927
           if (doRaise) {
1933
           if (doRaise) {
1931
         #endif
1937
         #endif
1932
 
1938
 
1933
         // Change the Z servo angle
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
     #elif ENABLED(Z_PROBE_ALLEN_KEY)
1943
     #elif ENABLED(Z_PROBE_ALLEN_KEY)
2288
 
2294
 
2289
     #if ENABLED(HAS_SERVO_ENDSTOPS)
2295
     #if ENABLED(HAS_SERVO_ENDSTOPS)
2290
       // Engage an X, Y (or Z) Servo endstop if enabled
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
         if (_Z_SERVO_SUBTEST) endstops.z_probe_enabled = true;
2299
         if (_Z_SERVO_SUBTEST) endstops.z_probe_enabled = true;
2294
       }
2300
       }
2295
     #endif
2301
     #endif
2419
 
2425
 
2420
     // Retract X, Y (or Z) Servo endstop if enabled
2426
     // Retract X, Y (or Z) Servo endstop if enabled
2421
     #if ENABLED(HAS_SERVO_ENDSTOPS)
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
         // Raise the servo probe before stow outside ABL context.
2429
         // Raise the servo probe before stow outside ABL context.
2424
         // This is a workaround to allow use of a Servo Probe without
2430
         // This is a workaround to allow use of a Servo Probe without
2425
         // ABL until more global probe handling is implemented.
2431
         // ABL until more global probe handling is implemented.
2438
         #if ENABLED(DEBUG_LEVELING_FEATURE)
2444
         #if ENABLED(DEBUG_LEVELING_FEATURE)
2439
           if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("> SERVO_ENDSTOPS > Stow with servo.move()");
2445
           if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("> SERVO_ENDSTOPS > Stow with servo.move()");
2440
         #endif
2446
         #endif
2441
-        servo[servo_endstop_id[axis]].move(servo_endstop_angle[axis][1]);
2447
+        STOW_SERVO_ENDSTOP(axis);
2442
         if (_Z_SERVO_SUBTEST) endstops.enable_z_probe(false);
2448
         if (_Z_SERVO_SUBTEST) endstops.enable_z_probe(false);
2443
       }
2449
       }
2444
 
2450
 
5673
     if (code_seen('S')) {
5679
     if (code_seen('S')) {
5674
       servo_position = code_value_int();
5680
       servo_position = code_value_int();
5675
       if (servo_index >= 0 && servo_index < NUM_SERVOS)
5681
       if (servo_index >= 0 && servo_index < NUM_SERVOS)
5676
-        servo[servo_index].move(servo_position);
5682
+        MOVE_SERVO(servo_index, servo_position);
5677
       else {
5683
       else {
5678
         SERIAL_ERROR_START;
5684
         SERIAL_ERROR_START;
5679
         SERIAL_ERROR("Servo ");
5685
         SERIAL_ERROR("Servo ");
6680
 
6686
 
6681
           offset_vec.apply_rotation(planner.bed_level_matrix.transpose(planner.bed_level_matrix));
6687
           offset_vec.apply_rotation(planner.bed_level_matrix.transpose(planner.bed_level_matrix));
6682
 
6688
 
6689
+          // Adjust the current position
6683
           current_position[X_AXIS] += offset_vec.x;
6690
           current_position[X_AXIS] += offset_vec.x;
6684
           current_position[Y_AXIS] += offset_vec.y;
6691
           current_position[Y_AXIS] += offset_vec.y;
6685
           current_position[Z_AXIS] += offset_vec.z;
6692
           current_position[Z_AXIS] += offset_vec.z;

Loading…
Cancel
Save