hisyam fs / Mbed 2 deprecated Test_all

Dependencies:   mbed ADS1115 StepperMotor SRF05 TPA81new

Revision:
1:ef90d942ce78
Parent:
0:79e2a8171b16
--- a/Dynamixel.cpp	Tue Aug 18 09:15:09 2015 +0000
+++ b/Dynamixel.cpp	Wed Aug 19 05:36:55 2015 +0000
@@ -78,16 +78,58 @@
     // 0 to 1023 (0x3FF)
     uint8_t elements = 9;
     uint8_t packetBuffer[elements];
+    uint16_t checkSum = 0;
     if (m_link.writeable() ) {
         packetBuffer[0] = 0xff;
         packetBuffer[1] = 0xff;
-        packetBuffer[2] = m_motorID;   // ID
-        packetBuffer[3] = 0x05;   // Length
-        packetBuffer[4] = WRITE_DATA;               // Instruction
-        packetBuffer[5] = ADDRESS_GOAL_POSITION;    // Parameter 1: Starting address
+        packetBuffer[2] = m_motorID;                    // ID
+        packetBuffer[3] = 0x05;                         // Length
+        packetBuffer[4] = WRITE_DATA;                   // Instruction
+        packetBuffer[5] = ADDRESS_GOAL_POSITION;        // Parameter 1: Starting address
         packetBuffer[6] = (uint8_t) position & 0xff;    // Parameter 2: First value to be writen
         packetBuffer[7] = (uint8_t) (position >> 8);    // Parameter 3: Second value to be writen
-        packetBuffer[8] = ~(packetBuffer[2] + packetBuffer[3] + packetBuffer[4] + packetBuffer[5] + packetBuffer[6] + + packetBuffer[7]) & 0xff;   // Check sum
+        checkSum = packetBuffer[2] + packetBuffer[3] + packetBuffer[4] + packetBuffer[5] + packetBuffer[6] + packetBuffer[7];
+        packetBuffer[8] = (uint8_t) (~checkSum & 0xff); // Check sum
+
+        /*
+        for (int i = 0; i<= elements; i++) {
+            pc.printf("%c ", packetBuffer[i]);
+        }
+        pc.printf("\n");
+        */
+        m_txEnable = 1;       // Enable Tx / Disable Rx
+        for (int i = 0; i<= elements; i++) {
+            m_link.putc(packetBuffer[i]);
+        }
+        wait_ms(2);         // fix this!!!
+        m_txEnable = 0;       // Disable Tx / Enable Rx
+    } else {
+        //pc.printf("Dynamixel not writeable\n");
+    }
+    wait_ms(10);
+    pc.printf("\n Status packet:\n");
+    while ( m_link.readable() ) {
+        pc.printf("0x%x\t", m_link.getc());  // Read status packet if available
+    }
+}
+
+void Dynamixel::setSpeed(uint16_t speed)
+{
+    // 0 to 1023 (0x3FF)
+    uint8_t elements = 9;
+    uint8_t packetBuffer[elements];
+    uint16_t checkSum = 0;
+    if (m_link.writeable() ) {
+        packetBuffer[0] = 0xff;
+        packetBuffer[1] = 0xff;
+        packetBuffer[2] = m_motorID;                    // ID
+        packetBuffer[3] = 0x05;                         // Length
+        packetBuffer[4] = WRITE_DATA;                   // Instruction
+        packetBuffer[5] = ADDRESS_MOVING_SPEED;         // Parameter 1: Starting address
+        packetBuffer[6] = (uint8_t) speed & 0xff;       // Parameter 2: First value to be writen
+        packetBuffer[7] = (uint8_t) (speed >> 8);       // Parameter 3: Second value to be writen
+        checkSum = packetBuffer[2] + packetBuffer[3] + packetBuffer[4] + packetBuffer[5] + packetBuffer[6] + packetBuffer[7];
+        packetBuffer[8] = (uint8_t) (~checkSum & 0xff); // Check sum
 
         /*
         for (int i = 0; i<= elements; i++) {