Provides an interface to an AX-12A servo. Requires the Dynamixel bus protocol library/

Fork of AX-12A by Jonathan Pickett

Revision:
11:8de493bd8922
Parent:
10:e4c9b94b5879
Child:
12:f66c779ca018
--- a/AX12.h	Thu Jan 07 17:31:09 2016 +0000
+++ b/AX12.h	Tue Jan 19 19:48:59 2016 +0000
@@ -77,17 +77,41 @@
     ctPunchH              = 49        // RD/WR
 };
 
+// to reduce time reading values from servo, 
+// we read values as a block from PresentPosition through Moving
+// these are cached until ClearCache call
+enum CachedControlTable
+{
+    cctPresentPositionL    = 36 - 36,
+    cctPresentPositionH    = 37 - 36,
+    cctPresentSpeedL       = 38 - 36,
+    cctPresentSpeedH       = 39 - 36,
+    cctPresentLoadL        = 40 - 36,
+    cctPresentLoadH        = 41 - 36,
+    cctPresentVoltage      = 42 - 36,
+    cctPresentTemperature  = 43 - 36,
+    cctRegisteredInst      = 44 - 36,
+    cctReserved3           = 45 - 36,
+    cctMoving              = 46 - 36
+};
+
+const unsigned char AX12ReadBlockStart  = ctPresentPositionL;
+const unsigned char AX12ReadBlockLength = ctLock - ctPresentPositionL;
+
 class AX12
 {
 
 public:
     AX12(DynamixelBus* pbus, ServoId = 1);
 
+    // clear cache to force actual read from servo
+    void ClearCache();
+    
     // sets the servo ID
     StatusCode SetServoId(char newId);
 
     // returns the status of the servo (connected/not connected + errors)
-    StatusCode Ping();
+    StatusCode Ping(void);
 
     // Sets the goal position of the servo in degrees
     StatusCode SetGoal(float degrees);
@@ -96,7 +120,7 @@
     bool IsMoving(void);
 
     // gets the position of the servo in degrees
-    float GetPosition();
+    float GetPosition(void);
 
     // gets the internal temperature of the servo
     int GetTemperature(void);
@@ -104,6 +128,9 @@
     // gets the servo power supply voltage
     float GetSupplyVoltage(void);
     
+    // Sets the replay delay for dynamixel protocol
+    StatusCode SetReplyDelay(int us);
+
     // gets the servo load
     float GetLoad(void);
     
@@ -123,5 +150,9 @@
     
     unsigned char _LastError;
     
+    unsigned char _ReadCache[AX12ReadBlockLength];
+    bool _HasReadCache;
+
+    StatusCode LoadReadCache();
 };
 #endif