Browse Source

Added servo actuated enstop coding to allow G28 command to engage and retract a servo to specified angles.

Gord Christmas 11 years ago
parent
commit
f4f30c9d64
2 changed files with 31 additions and 3 deletions
  1. 9
    1
      Marlin/Configuration.h
  2. 22
    2
      Marlin/Marlin_main.cpp

+ 9
- 1
Marlin/Configuration.h View File

470
 // leaving it undefined or defining as 0 will disable the servo subsystem
470
 // leaving it undefined or defining as 0 will disable the servo subsystem
471
 // If unsure, leave commented / disabled
471
 // If unsure, leave commented / disabled
472
 //
472
 //
473
-// #define NUM_SERVOS 3
473
+//#define NUM_SERVOS 3 // Servo index starts with 0
474
+
475
+// Servo Endstops
476
+// 
477
+// This allows for servo actuated endstops, primary usage is for the Z Axis to eliminate calibration or bed height changes.
478
+// Use M206 command to correct for switch height offset to actual nozzle height. Store that setting with M500.
479
+// 
480
+//#define SERVO_ENDSTOPS {-1, -1, 0} // Servo index for X, Y, Z. Disable with -1
481
+//#define SERVO_ENDSTOP_ANGLES {0,0, 0,0, 70,0} // X,Y,Z Axis Extend and Retract angles
474
 
482
 
475
 #include "Configuration_adv.h"
483
 #include "Configuration_adv.h"
476
 #include "thermistortables.h"
484
 #include "thermistortables.h"

+ 22
- 2
Marlin/Marlin_main.cpp View File

351
   #if (NUM_SERVOS >= 5)
351
   #if (NUM_SERVOS >= 5)
352
     #error "TODO: enter initalisation code for more servos"
352
     #error "TODO: enter initalisation code for more servos"
353
   #endif
353
   #endif
354
+
355
+  // Set position of Servo Endstops that are defined
356
+  #ifdef SERVO_ENDSTOPS
357
+  for(int8_t i = 0; i < 3; i++)
358
+  {
359
+    if(servo_endstops[i] > -1) {
360
+      servos[servo_endstops[i]].write(servo_endstop_angles[i * 2 + 1]);
361
+    }
362
+  }
363
+  #endif
354
 }
364
 }
355
 
365
 
356
 void setup()
366
 void setup()
664
 static void homeaxis(int axis) {
674
 static void homeaxis(int axis) {
665
 #define HOMEAXIS_DO(LETTER) \
675
 #define HOMEAXIS_DO(LETTER) \
666
   ((LETTER##_MIN_PIN > -1 && LETTER##_HOME_DIR==-1) || (LETTER##_MAX_PIN > -1 && LETTER##_HOME_DIR==1))
676
   ((LETTER##_MIN_PIN > -1 && LETTER##_HOME_DIR==-1) || (LETTER##_MAX_PIN > -1 && LETTER##_HOME_DIR==1))
667
-
668
   if (axis==X_AXIS ? HOMEAXIS_DO(X) :
677
   if (axis==X_AXIS ? HOMEAXIS_DO(X) :
669
       axis==Y_AXIS ? HOMEAXIS_DO(Y) :
678
       axis==Y_AXIS ? HOMEAXIS_DO(Y) :
670
       axis==Z_AXIS ? HOMEAXIS_DO(Z) :
679
       axis==Z_AXIS ? HOMEAXIS_DO(Z) :
671
       0) {
680
       0) {
681
+
682
+    // Engage Servo endstop if enabled
683
+    #ifdef SERVO_ENDSTOPS[axis] > -1
684
+      servos[servo_endstops[axis]].write(servo_endstop_angles[axis * 2]);
685
+    #endif
686
+
672
     current_position[axis] = 0;
687
     current_position[axis] = 0;
673
     plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
688
     plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
674
     destination[axis] = 1.5 * max_length(axis) * home_dir(axis);
689
     destination[axis] = 1.5 * max_length(axis) * home_dir(axis);
691
     destination[axis] = current_position[axis];
706
     destination[axis] = current_position[axis];
692
     feedrate = 0.0;
707
     feedrate = 0.0;
693
     endstops_hit_on_purpose();
708
     endstops_hit_on_purpose();
709
+
710
+    // Retract Servo endstop if enabled
711
+    #ifdef SERVO_ENDSTOPS[axis] > -1
712
+      servos[servo_endstops[axis]].write(servo_endstop_angles[axis * 2 + 1]);
713
+    #endif
694
   }
714
   }
695
 }
715
 }
696
 #define HOMEAXIS(LETTER) homeaxis(LETTER##_AXIS)
716
 #define HOMEAXIS(LETTER) homeaxis(LETTER##_AXIS)
2281
     }
2301
     }
2282
   }
2302
   }
2283
   return false;
2303
   return false;
2284
-}
2304
+}

Loading…
Cancel
Save