Bläddra i källkod

Merge pull request #506 from codexmas/ServoEndstops

Servo Enstops working!
ErikZalm 12 år sedan
förälder
incheckning
3dea417c25
4 ändrade filer med 39 tillägg och 5 borttagningar
  1. 9
    1
      Marlin/Configuration.h
  2. 26
    2
      Marlin/Marlin_main.cpp
  3. 2
    0
      Marlin/Servo.cpp
  4. 2
    2
      Marlin/pins.h

+ 9
- 1
Marlin/Configuration.h Visa fil

@@ -470,7 +470,15 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th
470 470
 // leaving it undefined or defining as 0 will disable the servo subsystem
471 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 483
 #include "Configuration_adv.h"
476 484
 #include "thermistortables.h"

+ 26
- 2
Marlin/Marlin_main.cpp Visa fil

@@ -177,6 +177,10 @@ float extruder_offset[2][EXTRUDERS] = {
177 177
 #endif
178 178
 uint8_t active_extruder = 0;
179 179
 int fanSpeed=0;
180
+#ifdef SERVO_ENDSTOPS
181
+  int servo_endstops[] = SERVO_ENDSTOPS;
182
+  int servo_endstop_angles[] = SERVO_ENDSTOP_ANGLES;
183
+#endif
180 184
 #ifdef BARICUDA
181 185
 int ValvePressure=0;
182 186
 int EtoPPressure=0;
@@ -351,6 +355,16 @@ void servo_init()
351 355
   #if (NUM_SERVOS >= 5)
352 356
     #error "TODO: enter initalisation code for more servos"
353 357
   #endif
358
+
359
+  // Set position of Servo Endstops that are defined
360
+  #ifdef SERVO_ENDSTOPS
361
+  for(int8_t i = 0; i < 3; i++)
362
+  {
363
+    if(servo_endstops[i] > -1) {
364
+      servos[servo_endstops[i]].write(servo_endstop_angles[i * 2 + 1]);
365
+    }
366
+  }
367
+  #endif
354 368
 }
355 369
 
356 370
 void setup()
@@ -664,11 +678,16 @@ static void axis_is_at_home(int axis) {
664 678
 static void homeaxis(int axis) {
665 679
 #define HOMEAXIS_DO(LETTER) \
666 680
   ((LETTER##_MIN_PIN > -1 && LETTER##_HOME_DIR==-1) || (LETTER##_MAX_PIN > -1 && LETTER##_HOME_DIR==1))
667
-
668 681
   if (axis==X_AXIS ? HOMEAXIS_DO(X) :
669 682
       axis==Y_AXIS ? HOMEAXIS_DO(Y) :
670 683
       axis==Z_AXIS ? HOMEAXIS_DO(Z) :
671 684
       0) {
685
+
686
+    // Engage Servo endstop if enabled
687
+    #ifdef SERVO_ENDSTOPS[axis] > -1
688
+      servos[servo_endstops[axis]].write(servo_endstop_angles[axis * 2]);
689
+    #endif
690
+
672 691
     current_position[axis] = 0;
673 692
     plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
674 693
     destination[axis] = 1.5 * max_length(axis) * home_dir(axis);
@@ -691,6 +710,11 @@ static void homeaxis(int axis) {
691 710
     destination[axis] = current_position[axis];
692 711
     feedrate = 0.0;
693 712
     endstops_hit_on_purpose();
713
+
714
+    // Retract Servo endstop if enabled
715
+    #ifdef SERVO_ENDSTOPS[axis] > -1
716
+      servos[servo_endstops[axis]].write(servo_endstop_angles[axis * 2 + 1]);
717
+    #endif
694 718
   }
695 719
 }
696 720
 #define HOMEAXIS(LETTER) homeaxis(LETTER##_AXIS)
@@ -2281,4 +2305,4 @@ bool setTargetedHotend(int code){
2281 2305
     }
2282 2306
   }
2283 2307
   return false;
2284
-}
2308
+}

+ 2
- 0
Marlin/Servo.cpp Visa fil

@@ -41,6 +41,8 @@
41 41
  detach()    - Stops an attached servos from pulsing its i/o pin.
42 42
 
43 43
 */
44
+#include "Configuration.h" 
45
+
44 46
 #ifdef NUM_SERVOS
45 47
 #include <avr/interrupt.h>
46 48
 #include <Arduino.h>

+ 2
- 2
Marlin/pins.h Visa fil

@@ -391,7 +391,7 @@
391 391
       #define SERVO2_PIN         5
392 392
     #endif
393 393
 
394
-    #if NUM_SERVOS > 2
394
+    #if NUM_SERVOS > 3
395 395
       #define SERVO3_PIN         4
396 396
     #endif
397 397
   #endif
@@ -1846,4 +1846,4 @@
1846 1846
                         HEATER_BED_PIN, FAN_PIN,                  \
1847 1847
                         _E0_PINS _E1_PINS _E2_PINS             \
1848 1848
                         analogInputToDigitalPin(TEMP_0_PIN), analogInputToDigitalPin(TEMP_1_PIN), analogInputToDigitalPin(TEMP_2_PIN), analogInputToDigitalPin(TEMP_BED_PIN) }
1849
-#endif
1849
+#endif

Laddar…
Avbryt
Spara