Made changes to individually control servo speeds

Dependents:   VariableSpeedServo

Fork of Servo by Jasper Denkers

Revision:
3:774dd54867f2
Parent:
2:466f005a4dd5
Child:
4:8bdb46e629b9
--- a/Servo.h	Sun Oct 11 20:50:48 2015 +0000
+++ b/Servo.h	Mon Oct 12 14:56:58 2015 +0000
@@ -1,6 +1,8 @@
 /* mbed Servo Library without using PWM pins
  * Copyright (c) 2010 Jasper Denkers
  *
+ * Changes and additions made by David Garrison, October 2015 to add ability to independently control each servo's speed
+ *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
  * in the Software without restriction, including without limitation the rights
@@ -25,28 +27,37 @@
 
 #include "mbed.h"
 
-/** Class to control a servo on any pin, without using pwm
+/** Class to control servos on any pin, without using pwm 
+ * Tested on Nucleo -L152RE @40MHz MCU clock and the 
+ *  st disco -f746ng RUNNING AT 216mhZ.
  *
  * Example:
  * @code
- * // Keep sweeping servo from left to right
+ *
+ * // Keep sweeping two servos from left to right
  * #include "mbed.h"
  * #include "Servo.h"
  * 
- * Servo Servo1(p20);
+ *int main()
+ *{
  *
- * Servo1.Enable(1500,20000);
+ *   Servo Servo1(D12);            // create new instance of servo with output pin number
+ *   Servo Servo2(D10);
+ *   Servo1.Enable(1500,50,10);    // Start position ; in us (1500 = center), servo refresh rate in Hz (analog servos = 50 Hz), servo movement speed range from 1-50, 1 slowest, about 20 seconds/180 degrees
+ *   Servo2.Enable(1500,50,10);
+ *   while(1) {
  *
- * while(1) {
- *     for (int pos = 1000; pos < 2000; pos += 25) {
- *         Servo1.SetPosition(pos);  
- *         wait_ms(20);
- *     }
- *     for (int pos = 2000; pos > 1000; pos -= 25) {
- *         Servo1.SetPosition(pos); 
- *         wait_ms(20); 
- *     }
- * }
+ *       Servo1.SetPosition(2300);
+ *       Servo2.SetPosition(2300);
+ *       wait(2.5);
+ *
+ *
+ *       Servo1.SetPosition(700);
+ *       Servo2.SetPosition(700);
+ *       wait(2.5);
+ *   }
+ *
+ *}
  * @endcode
  */
 
@@ -65,8 +76,8 @@
      */
     void SetPosition(int NewPos);
     
-    /** speed oonversion from arbitary range of 1-50 to us to set Speed Ticker rate.
-    * @param int 1-50
+    /** speed oonversion from arbitary range of 1-50 to us to set Ticker Speed rate.
+    * used in Enable function
     */
     int SpeedConvert (int _speed);  
     
@@ -81,11 +92,16 @@
     
     /** Disable the servo. After disabling the servo won't get any signal anymore
      *
+     */     
+     void Disable();
+     
+     /** determines direction of servo's move, called by Ticker Speed
      */
      void Update();
+     
      int speed;
      int CurrentPosition;
-    void Disable();
+    
 
 private:
     void StartPulse();
@@ -93,8 +109,6 @@
     int Position;
     int Period; 
     int NewPosition;
-    //int speed; 
-    //int CurrentPosition;    
     DigitalOut ServoPin;
     Ticker Pulse;
     Ticker Speed;