robot arm demo team / AX-12A

Fork of AX-12A by Jonathan Pickett

Files at this revision

API Documentation at this revision

Comitter:
henryrawas
Date:
Thu Dec 31 17:47:43 2015 +0000
Parent:
6:a702043b1420
Child:
8:b6979be5a0a7
Commit message:
fixes

Changed in this revision

AX12.cpp Show annotated file Show diff for this revision Revisions of this file
AX12.h Show annotated file Show diff for this revision Revisions of this file
--- a/AX12.cpp	Tue Dec 29 23:31:19 2015 +0000
+++ b/AX12.cpp	Thu Dec 31 17:47:43 2015 +0000
@@ -13,6 +13,7 @@
     _LastTemperature = 0;
     _LastVoltage = 0;
     _LastError = 0;
+    _LastLoad = 0;
 }
 
 /*****/
@@ -156,6 +157,34 @@
     }
 }
 
+/*****/
+
+float AX12::GetLoad(void)
+{
+    _LastError = statusValid;
+    CommBuffer data;
+    StatusCode s = _pbus->Read(_ID, ctPresentLoadL, 2, data); 
+    if( s == statusValid )
+    {
+        int16_t value = data[0] | (data[1] << 8);
+        _LastLoad = (float)(value & 0x03ff);
+        return _LastLoad;
+    }
+    else
+    {
+        // try again one time
+        s = _pbus->Read(_ID, ctPresentLoadL, 2, data); 
+        if( s == statusValid )
+        {
+            int16_t value = data[0] | (data[1] << 8);
+            _LastLoad = (float)(value & 0x03ff);
+            return _LastLoad;
+        }
+        _LastError = s;
+        return 0.0f;
+    }
+}
+
 StatusCode AX12::TorqueEnable(bool enable)
 {
     _LastError = statusValid;
@@ -179,6 +208,9 @@
         case NM_Voltage:
             return true;
             
+        case NM_Load:
+            return true;
+
         default:
             return false;
     }
@@ -197,6 +229,9 @@
         case NM_Voltage:
             return GetSupplyVoltage();
             
+        case NM_Load:
+            return GetLoad();
+            
         default:
             return 0.0f;
     }
@@ -215,6 +250,9 @@
         case NM_Voltage:
             return _LastVoltage;
             
+        case NM_Load:
+            return _LastLoad;
+
         default:
             return 0.0f;
     }
--- a/AX12.h	Tue Dec 29 23:31:19 2015 +0000
+++ b/AX12.h	Thu Dec 31 17:47:43 2015 +0000
@@ -104,6 +104,9 @@
     // gets the servo power supply voltage
     float GetSupplyVoltage(void);
     
+    // gets the servo load
+    float GetLoad(void);
+    
     // enables/disables holding torque 
     StatusCode TorqueEnable( bool );
 
@@ -141,6 +144,9 @@
     // last read voltage
     float _LastVoltage;
     
+    // last read load
+    float _LastLoad;
+    
     unsigned char _LastError;
     
 };