Legacy Forum: Preserving Nearly 20 Years of Community History - A Time Capsule of Discussions, Memories, and Shared Experiences.

Usage USB2Dynamixel Bus Interfaces with C

Bioloid robot kit from Korean company Robotis; CM5 controller block, AX12 servos..
4 postsPage 1 of 1
4 postsPage 1 of 1

Usage USB2Dynamixel Bus Interfaces with C

Post by markus » Sat Apr 05, 2008 9:31 pm

Post by markus
Sat Apr 05, 2008 9:31 pm

Hallo,

i bought the USB2Dynamixel interface from http://www.huvrobotics.com.
Now i try to connect to a AX12 from a linux pc with C.

I installed the D2XX Driver from http://www.ftdichip.com and wrote a little program to test in C.


Code: Select all
#include <stdio>
#include <stdlib>
#include <string>
#include "ftd2xx.h"

int main (int argc, char * const argv[])
{
    FT_STATUS   ftStatus;
    FT_HANDLE ftHandle;
   
    char deviceid[] = "A4004t6d";
   
    ftStatus = FT_OpenEx(deviceid, FT_OPEN_BY_SERIAL_NUMBER, &ftHandle);
    if( ftStatus != FT_OK ){
         printf("Error FT_OpenEx(%d)\n", ftStatus);
         return -1;
    }

    printf("Opened device %s\n", deviceid);
   
    ftStatus = FT_SetBaudRate(ftHandle, 1000000);
    if( ftStatus != FT_OK ){
      printf("Error FT_SetBaudRate(%d)\n", ftStatus);
    }
   
    ftStatus = FT_SetDataCharacteristics(ftHandle, FT_BITS_8, FT_STOP_BITS_1, FT_PARITY_NONE);
    if( ftStatus != FT_OK ){
      printf("Error FT_SetDataCharacteristics(%d)\n", ftStatus);
    }

    ftStatus = FT_SetFlowControl(ftHandle, FT_FLOW_NONE, 0, 0);
    if( ftStatus != FT_OK ){
      printf("Error FT_SetFlowControl(%d)\n", ftStatus);
    }   

    // (FT_HANDLE ftHandle, DWORD dwReadTimeout, DWORD dwWriteTimeout)
    ftStatus = FT_SetTimeouts(ftHandle,1000,1000);
    if( ftStatus != FT_OK ){
      printf("Error FT_SetTimeouts(%d)\n", ftStatus);
    } 

    DWORD buff[] = { 0xff, 0xff, 0x9, 0x2, 0x1, 0xf3 };
    DWORD written;
    DWORD len = 6;
    ftStatus = FT_Write(ftHandle, buff, len, &written);
   
    if( ftStatus != FT_OK ){
      printf("Error FT_Write(%d)\n", ftStatus);
    } 
   
    printf("Bytes written: %i\n", written);

    DWORD EventDWord;
    DWORD TxBytes, RxBytes;
    DWORD BytesReceived;
    char RxBuffer[256];
    FT_GetStatus(ftHandle,&RxBytes,&TxBytes,&EventDWord);
    printf("RxBytes: %i\n", RxBytes);
    printf("TxBytes: %i\n", TxBytes);
    if (RxBytes > 0) {
      ftStatus = FT_Read(ftHandle,RxBuffer,RxBytes,&BytesReceived);
      if (ftStatus == FT_OK) {
        for(int i=0; i<RxBytes; i++){
          printf("0x%x ", RxBuffer[i]);
        }
        printf("\n");
      }
      else {
        printf("Error FT_Read(%d)\n", ftStatus);
      }
    } 

    FT_Close(ftHandle);
    return 0;
}


This should pring the AX12 with ID 9, but i get no response:
Opened device A4004t6d
Bytes written: 6
RxBytes: 0
TxBytes: 0


Is anyone else using this board with C/C++?

Thanks for help
Markus
Hallo,

i bought the USB2Dynamixel interface from http://www.huvrobotics.com.
Now i try to connect to a AX12 from a linux pc with C.

I installed the D2XX Driver from http://www.ftdichip.com and wrote a little program to test in C.


Code: Select all
#include <stdio>
#include <stdlib>
#include <string>
#include "ftd2xx.h"

int main (int argc, char * const argv[])
{
    FT_STATUS   ftStatus;
    FT_HANDLE ftHandle;
   
    char deviceid[] = "A4004t6d";
   
    ftStatus = FT_OpenEx(deviceid, FT_OPEN_BY_SERIAL_NUMBER, &ftHandle);
    if( ftStatus != FT_OK ){
         printf("Error FT_OpenEx(%d)\n", ftStatus);
         return -1;
    }

    printf("Opened device %s\n", deviceid);
   
    ftStatus = FT_SetBaudRate(ftHandle, 1000000);
    if( ftStatus != FT_OK ){
      printf("Error FT_SetBaudRate(%d)\n", ftStatus);
    }
   
    ftStatus = FT_SetDataCharacteristics(ftHandle, FT_BITS_8, FT_STOP_BITS_1, FT_PARITY_NONE);
    if( ftStatus != FT_OK ){
      printf("Error FT_SetDataCharacteristics(%d)\n", ftStatus);
    }

    ftStatus = FT_SetFlowControl(ftHandle, FT_FLOW_NONE, 0, 0);
    if( ftStatus != FT_OK ){
      printf("Error FT_SetFlowControl(%d)\n", ftStatus);
    }   

    // (FT_HANDLE ftHandle, DWORD dwReadTimeout, DWORD dwWriteTimeout)
    ftStatus = FT_SetTimeouts(ftHandle,1000,1000);
    if( ftStatus != FT_OK ){
      printf("Error FT_SetTimeouts(%d)\n", ftStatus);
    } 

    DWORD buff[] = { 0xff, 0xff, 0x9, 0x2, 0x1, 0xf3 };
    DWORD written;
    DWORD len = 6;
    ftStatus = FT_Write(ftHandle, buff, len, &written);
   
    if( ftStatus != FT_OK ){
      printf("Error FT_Write(%d)\n", ftStatus);
    } 
   
    printf("Bytes written: %i\n", written);

    DWORD EventDWord;
    DWORD TxBytes, RxBytes;
    DWORD BytesReceived;
    char RxBuffer[256];
    FT_GetStatus(ftHandle,&RxBytes,&TxBytes,&EventDWord);
    printf("RxBytes: %i\n", RxBytes);
    printf("TxBytes: %i\n", TxBytes);
    if (RxBytes > 0) {
      ftStatus = FT_Read(ftHandle,RxBuffer,RxBytes,&BytesReceived);
      if (ftStatus == FT_OK) {
        for(int i=0; i<RxBytes; i++){
          printf("0x%x ", RxBuffer[i]);
        }
        printf("\n");
      }
      else {
        printf("Error FT_Read(%d)\n", ftStatus);
      }
    } 

    FT_Close(ftHandle);
    return 0;
}


This should pring the AX12 with ID 9, but i get no response:
Opened device A4004t6d
Bytes written: 6
RxBytes: 0
TxBytes: 0


Is anyone else using this board with C/C++?

Thanks for help
Markus
markus
Newbie
Newbie
Posts: 2
Joined: Sat Apr 05, 2008 9:12 pm

Post by Bullit » Tue Apr 08, 2008 12:41 am

Post by Bullit
Tue Apr 08, 2008 12:41 am

While I haven't used the huv board explicitly I do use the same chip to communicate with my dynamixels with embedded linux on a gumstix. I use ftdilib which for my solution has proved to have the lowest latency.
http://www.intra2net.com/de/produkte/opensource/ftdi/
I have looked into the D2XX drivers but the source isn't available for embedded projects. From speaking to the folks at ftdi I think the D2XX driver has similar latency to the ftdilib that I use.

From looking at your code it seems to me that you are checking the status before the bytes come in.
Shouldn't you be using some thing like
dwRxSize = 0;
while ((dwRxSize < BUF_SIZE) && (ftStatus == FT_OK))
{
ftStatus = FT_GetQueueStatus(ftHandle[i], &dwRxSize);
}
This is from one of the examples that comes with the d2xx linux driver.
While I haven't used the huv board explicitly I do use the same chip to communicate with my dynamixels with embedded linux on a gumstix. I use ftdilib which for my solution has proved to have the lowest latency.
http://www.intra2net.com/de/produkte/opensource/ftdi/
I have looked into the D2XX drivers but the source isn't available for embedded projects. From speaking to the folks at ftdi I think the D2XX driver has similar latency to the ftdilib that I use.

From looking at your code it seems to me that you are checking the status before the bytes come in.
Shouldn't you be using some thing like
dwRxSize = 0;
while ((dwRxSize < BUF_SIZE) && (ftStatus == FT_OK))
{
ftStatus = FT_GetQueueStatus(ftHandle[i], &dwRxSize);
}
This is from one of the examples that comes with the d2xx linux driver.
Bullit
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 291
Joined: Wed May 31, 2006 1:00 am
Location: Near robot

Post by JonHylands » Tue Apr 08, 2008 2:02 am

Post by JonHylands
Tue Apr 08, 2008 2:02 am

It seems to me like you might be not waiting long enough. Stock AX-12 servos have a response delay of about 500 us before they even start sending back a response...

- Jon
It seems to me like you might be not waiting long enough. Stock AX-12 servos have a response delay of about 500 us before they even start sending back a response...

- Jon
JonHylands
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 512
Joined: Thu Nov 09, 2006 1:00 am
Location: Ontario, Canada

Post by markus » Tue Apr 08, 2008 9:12 am

Post by markus
Tue Apr 08, 2008 9:12 am

It was just a copy&past error.
Replace DWORD buff[] = { 0xff, 0xff, 0x9, 0x2, 0x1, 0xf3 };
trough unsigned char buff[] = { 0xff, 0xff, 0x9, 0x2, 0x1, 0xf3 };

Thanks to all
It was just a copy&past error.
Replace DWORD buff[] = { 0xff, 0xff, 0x9, 0x2, 0x1, 0xf3 };
trough unsigned char buff[] = { 0xff, 0xff, 0x9, 0x2, 0x1, 0xf3 };

Thanks to all
markus
Newbie
Newbie
Posts: 2
Joined: Sat Apr 05, 2008 9:12 pm


4 postsPage 1 of 1
4 postsPage 1 of 1