Robot's source code

Dependencies:   mbed

Revision:
74:88be86f83d17
Parent:
39:09c04fd42c94
Child:
109:53918ba98306
diff -r d8e1b543fbe3 -r 88be86f83d17 AX12/AX12.cpp
--- a/AX12/AX12.cpp	Sat Apr 11 10:36:56 2015 +0000
+++ b/AX12/AX12.cpp	Mon Apr 13 16:53:19 2015 +0000
@@ -34,19 +34,19 @@
 
 }
 
-// Set the mode of the servo
+// set the mode of the servo
 //  0 = Positional (0-300 degrees)
 //  1 = Rotational -1 to 1 speed
-int AX12::SetMode(int mode) {
+int AX12::setMode(int mode) {
 
     if (mode == 1) { // set CR
-        SetCWLimit(0);
-        SetCCWLimit(0);
-        SetCRSpeed(0.0);
+        setCWLimit(0);
+        setCCWLimit(0);
+        setCRSpeed(0.0);
     } else {
-        SetCWLimit(0);
-        SetCCWLimit(300);
-        SetCRSpeed(0.0);
+        setCWLimit(0);
+        setCCWLimit(300);
+        setCRSpeed(0.0);
     }
     return(0);
 }
@@ -55,7 +55,7 @@
 // if flag[0] is set, were blocking
 // if flag[1] is set, we're registering
 // they are mutually exclusive operations
-int AX12::SetGoal(int degrees, int flags) {
+int AX12::setGoal(int degrees, int flags) {
 
     char reg_flag = 0;
     char data[2];
@@ -68,7 +68,7 @@
     // 1023 / 300 * degrees
     short goal = (1023 * degrees) / 300;
 #ifdef AX12_DEBUG
-    logger.printf("SetGoal to 0x%x\n",goal);
+    logger.printf("setGoal to 0x%x\n",goal);
 #endif
 
     data[0] = goal & 0xff; // bottom 8 bits
@@ -84,9 +84,22 @@
     return(rVal);
 }
 
+int AX12::setMaxTorque(int maxTorque)
+{
+    char data[2];
+    
+    data[0] = maxTorque & 0xFF;
+    data[1] = maxTorque >> 8;
+    
+    // write the packet, return the error code
+    int rVal = write(_ID, 0x22, 2, data);
 
-// Set continuous rotation speed from -1 to 1
-int AX12::SetCRSpeed(float speed) {
+    return(rVal);
+}
+
+
+// set continuous rotation speed from -1 to 1
+int AX12::setCRSpeed(float speed) {
 
     // bit 10     = direction, 0 = CCW, 1=CW
     // bits 9-0   = Speed
@@ -94,7 +107,7 @@
 
     int goal = (0x3ff * abs(speed));
 
-    // Set direction CW if we have a negative speed
+    // set direction CW if we have a negative speed
     if (speed < 0) {
         goal |= (0x1 << 10);
     }
@@ -109,7 +122,7 @@
 }
 
 
-int AX12::SetCWLimit (int degrees) {
+int AX12::setCWLimit (int degrees) {
 
     char data[2];
 
@@ -117,7 +130,7 @@
     short limit = (1023 * degrees) / 300;
 
 #ifdef AX12_DEBUG
-    logger.printf("SetCWLimit to 0x%x\n",limit);
+    logger.printf("setCWLimit to 0x%x\n",limit);
 #endif
 
     data[0] = limit & 0xff; // bottom 8 bits
@@ -128,7 +141,7 @@
 
 }
 
-int AX12::SetCCWLimit (int degrees) {
+int AX12::setCCWLimit (int degrees) {
 
     char data[2];
 
@@ -136,7 +149,7 @@
     short limit = (1023 * degrees) / 300;
 
 #ifdef AX12_DEBUG
-    logger.printf("SetCCWLimit to 0x%x\n",limit);
+    logger.printf("setCCWLimit to 0x%x\n",limit);
 #endif
 
     data[0] = limit & 0xff; // bottom 8 bits
@@ -147,13 +160,13 @@
 }
 
 
-int AX12::SetID (int CurrentID, int NewID) {
+int AX12::setID (int CurrentID, int NewID) {
 
     char data[1];
     data[0] = NewID;
 
 #ifdef AX12_DEBUG
-    logger.printf("Setting ID from 0x%x to 0x%x\n",CurrentID,NewID);
+    logger.printf("setting ID from 0x%x to 0x%x\n",CurrentID,NewID);
 #endif
 
     return (write(CurrentID, AX12_REG_ID, 1, data));
@@ -161,13 +174,13 @@
 }
 
 
-int AX12::SetBaud (int baud) {
+int AX12::setBaud (int baud) {
 
     char data[1];
     data[0] = baud;
 
 #ifdef AX12_DEBUG
-    logger.printf("Setting Baud rate to %d\n",baud);
+    logger.printf("setting Baud rate to %d\n",baud);
 #endif
 
     return (write(0xFE, AX12_REG_BAUD, 1, data));
@@ -239,10 +252,10 @@
 }
 
 
-float AX12::GetPosition(void) {
+float AX12::getPosition(void) {
 
 #ifdef AX12_DEBUG
-    logger.printf("\nGetPosition(%d)",_ID);
+    logger.printf("\ngetPosition(%d)",_ID);
 #endif
 
     char data[2];
@@ -255,10 +268,10 @@
 }
 
 
-float AX12::GetTemp (void) {
+float AX12::getTemp (void) {
 
 #ifdef AX12_DEBUG
-    logger.printf("\nGetTemp(%d)",_ID);
+    logger.printf("\ngetTemp(%d)",_ID);
 #endif
 
     char data[1];
@@ -268,10 +281,10 @@
 }
 
 
-float AX12::GetVolts (void) {
+float AX12::getVolts (void) {
 
 #ifdef AX12_DEBUG
-    logger.printf("\nGetVolts(%d)",_ID);
+    logger.printf("\ngetVolts(%d)",_ID);
 #endif
 
     char data[1];