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

Home made motion sensor for AX/RX servos

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

Home made motion sensor for AX/RX servos

Post by sprince09 » Mon Jul 27, 2009 7:01 pm

Post by sprince09
Mon Jul 27, 2009 7:01 pm

Hey all,

I'm working on creating a motion sensor for the Robotis AX/RX servos for one of my projects, and I've run up against a wall with how to set up my communications. I would like to emulate the communication protocol that the AX/RX servos use so that I can run the sensor from the same communication bus as the rest of the servo network, but I can't seem to get my AVR (atmega 168 @ 20.0 MHz) to behave properly. For testing purposes, I currently have the AVR hooked up to my computer over a serial port, and I've been dancing around with it trying to send and receive packets of data. I'm using an interrupt based receive function on the AVR, and right now I'm just trying to have it echo back data packets to me as I send them. The code I have seems to work properly for single characters, but fails with multiple characters. Here's the relevant code:

Code: Select all

volatile unsigned char packet[255] = {0};
volatile unsigned char p_index = 0;

int main(void){
    initialize();
   
    //main loop
    //do nothing, just wait for incoming packets to be handled by interrupt vector
    for(;;);
}

ISR(USART_RX_vect)
{
    //interrupt based UART reciever
    //store recieved value in packet[] and increment packet index
    cli();
    TCNT2 = 0;
    packet[p_index++] = UDR0;
    sei();
}

ISR(TIMER2_COMPA_vect){
   //called when TNCT2 > timeout, indicating that a packet has finished
   //being recieved, and now needs to be parsed
   cli();
   if(p_index > 0) read_packet();
   sei();
}

void read_packet(void){
        //echos back a data packet received on UART0
       int i;
      for(i = 0; i < p_index; i++) uart_tx(packet[i]);

    //clear old packet and reset index
    p_index = 0;
    for(i = 0; i < 255; i++) packet[i] = 0;
}



To summarize, what I've tried to do with this code is:
- Wait for a character to arrive in the RX buffer of the AVR
- Store the received character in global array and reset a timer
- If the timer count exceeds a timeout value (set by me), the packet[] array
gets echoed back to the computer from the AVR (this only works for 1
character at a time)
- Reset packet[] array and p_index after an echo has been sent


I guess what I'm really asking is if anyone has tried to implement their own sensors or anything that are compatible with the AX/RX series of servos, and if they have, could they explain how they managed their communications?

*EDIT*
I get the proper number of characters echoed back to me from the AVR, but their values are incorrect. That's my main problem.
Hey all,

I'm working on creating a motion sensor for the Robotis AX/RX servos for one of my projects, and I've run up against a wall with how to set up my communications. I would like to emulate the communication protocol that the AX/RX servos use so that I can run the sensor from the same communication bus as the rest of the servo network, but I can't seem to get my AVR (atmega 168 @ 20.0 MHz) to behave properly. For testing purposes, I currently have the AVR hooked up to my computer over a serial port, and I've been dancing around with it trying to send and receive packets of data. I'm using an interrupt based receive function on the AVR, and right now I'm just trying to have it echo back data packets to me as I send them. The code I have seems to work properly for single characters, but fails with multiple characters. Here's the relevant code:

Code: Select all

volatile unsigned char packet[255] = {0};
volatile unsigned char p_index = 0;

int main(void){
    initialize();
   
    //main loop
    //do nothing, just wait for incoming packets to be handled by interrupt vector
    for(;;);
}

ISR(USART_RX_vect)
{
    //interrupt based UART reciever
    //store recieved value in packet[] and increment packet index
    cli();
    TCNT2 = 0;
    packet[p_index++] = UDR0;
    sei();
}

ISR(TIMER2_COMPA_vect){
   //called when TNCT2 > timeout, indicating that a packet has finished
   //being recieved, and now needs to be parsed
   cli();
   if(p_index > 0) read_packet();
   sei();
}

void read_packet(void){
        //echos back a data packet received on UART0
       int i;
      for(i = 0; i < p_index; i++) uart_tx(packet[i]);

    //clear old packet and reset index
    p_index = 0;
    for(i = 0; i < 255; i++) packet[i] = 0;
}



To summarize, what I've tried to do with this code is:
- Wait for a character to arrive in the RX buffer of the AVR
- Store the received character in global array and reset a timer
- If the timer count exceeds a timeout value (set by me), the packet[] array
gets echoed back to the computer from the AVR (this only works for 1
character at a time)
- Reset packet[] array and p_index after an echo has been sent


I guess what I'm really asking is if anyone has tried to implement their own sensors or anything that are compatible with the AX/RX series of servos, and if they have, could they explain how they managed their communications?

*EDIT*
I get the proper number of characters echoed back to me from the AVR, but their values are incorrect. That's my main problem.
sprince09
Newbie
Newbie
Posts: 4
Joined: Mon Jul 27, 2009 6:42 pm

Post by Bullit » Tue Jul 28, 2009 3:20 am

Post by Bullit
Tue Jul 28, 2009 3:20 am

Some good reference code is
Dave Hylands stuff

Look under AVR and IMU
Some good reference code is
Dave Hylands stuff

Look under AVR and IMU
Bullit
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 291
Joined: Wed May 31, 2006 1:00 am
Location: Near robot

Post by sprince09 » Tue Jul 28, 2009 1:53 pm

Post by sprince09
Tue Jul 28, 2009 1:53 pm

Perfect, that's exactly the kind of thing I was looking for. Thanks!
Perfect, that's exactly the kind of thing I was looking for. Thanks!
sprince09
Newbie
Newbie
Posts: 4
Joined: Mon Jul 27, 2009 6:42 pm


3 postsPage 1 of 1
3 postsPage 1 of 1