A library for the AX-12+ servo using external ICs instead of the SerialHalf-Duplex class

A library based on the AX-12+ library but using external hardware to convert from full to half duplex as suggested in the AX-12 datasheet. The buffers and NOT gate need to connected as shown below.

640

Don't forget the pull-up resistor!

Revision:
2:3000c6778d1c
Parent:
1:1dd9cd18975d
--- a/AX12.h	Sun Aug 07 13:06:04 2011 +0000
+++ b/AX12.h	Sun Oct 07 08:52:25 2012 +0000
@@ -1,4 +1,20 @@
-/* mbed AX-12+ Servo Library - External hardware version */
+/* Copyright (c) 2012 Martin Smith, MIT License
+ *
+ * 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 to use, copy, modify, merge, publish, distribute, 
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or 
+ * substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
 
 #ifndef MBED_AX12_H
 #define MBED_AX12_H
@@ -17,23 +33,71 @@
 #define TRANSMIT 1
 #define RECEIVE 0
 
-class AX12 {
+/** mbed AX-12+ Servo Library - External hardware version
+ *
+ * Example:
+ * @code
+ * // Move a servo back and forth...
+ * #include "mbed.h"
+ * #include "Servo.h"
+ * 
+ * Serial ax12_bus(p28,p27);
+ * AX12 my_ax12(ax12_bus, p29, 1);
+ * 
+ * int main() {
+ *     while(1) {
+ *         my_ax12.SetGoal(0);      // move to 0
+ *         wait(2);
+ *         my_ax12.SetGoal(300);    // move to 300
+ *         wait(2);
+ *     }
+ * }
+ * @endcode
+ */
+
+class AX12
+{
 
 public:
-    // define which pins are used, and the ID of this instance
-    AX12(PinName tx, PinName rx, PinName dir, int ID);
+    /** define which pins are used, and the ID of this instance
+    */
+    AX12(Serial& bus, PinName dir, int ID);
 
-    // methods for writing and reading registers
+    /** Read info from the specified AX-12 register
+    *
+    * @param ID the ID of the AX-12 servo
+    * @param start the address of the 1st register to be read
+    * @param length the number of bytes to read
+    * @param data where the read data is stored
+    * @returns servo status
+    */
     int read(int ID, int start, int length, char* data);
+
+    /** Write info to the specified AX-12 register
+    *
+    * @param ID the ID of the AX-12 servo
+    * @param start the address of the 1st register to be written to
+    * @param length the number of bytes to write
+    * @param data where the data to be written is stored
+    * @returns servo status
+    */
     int write(int ID, int start, int length, char* data);
 
-    // set goal angle in integer degrees
+    /** Sets the goal position for the servo
+    *
+    * @param degrees the new target position
+    * @returns error code
+    */
     int SetGoal(int degrees);
-    
-    float GetPosition();        // Get current angle, only valid 0-300
+
+    /** Getss the current position for the servo
+    *
+    * @returns current position
+    */
+    float GetPosition();
 
 private :
-    Serial _ax12;
+    Serial& _bus;
     DigitalOut _dir;
     int _ID;
 };