Xbee-Xbee communication stops


hi all

i trying run bunch of autonomous robots together. each robot takes in information of preceding robot , follows it. have 3 arduinos mega 2560 , 3 sf xbee shield , series 1 xbee. put arduino, motor controller , xbee stack on each robot , try coordinate them. here problem

my program runs this..... robots named 1,2,3 , how im running them.

the comm loop runs every 75ms , communication initiated 1st robot. robot1 --> robot2 --> robot3 --> robot1 --> robot2 --> robot3 , on.  robot 2 transmits after receives info robot1.

problem reasons unknown me communication stops mean, after robot 1 transmits, robot 2 not receive , not transmit stopping comm loop. dont know why happening. when run it, loop works few seconds , stops. tried doing 2 robots , works 30-40 secs , stops after that.

i have attached program outline. figuring out problem appreciated.

code: [select]

#include "arduino.h"
#include "quadratureencoder.h"
#include "timerone.h"

//declare encoder interrupts , initialize pwm

//define gains , other constants.

       //initialize velocity , time


   //for communication routine
float vdata[4];
char indata[50];
byte index;
bool started=false;
bool ended=false;



void setup()
{
 serial2.begin(9600);

//other startup stuff
// initialize timer interrupt control routine.
 vdata[0]=0;
 vdata[1]=0;
 vdata[2]=0;
 senddata();
} //setup

void loop()
{
       // motor velocity controller
 vel_ctrl();
         
       //run communication loop every 75ms

 if ((millis()-t) > 75){
 comm();
 t=millis();
 }
 delay(5);
} //loop



the comm() function communication received parsed , information transmitted follows.

code: [select]

void comm()
{
 char *data=null;
 int count=0;
   //read serial2 data buffer
 while(serial2.available()>0)
   {
     char inchar = serial2.read();
     if(inchar == '<')
     {
       index=0;
       indata[index]='\0';
       started=true;
       ended=false;
     }
     else if(inchar == '>')
     {
       ended=true;
       break;
     }
     else
     {
       if(index < 49)
       {
         indata[index]=inchar;
         index++;
         indata[index]='\0';
       }
     }
   } //while(serial2.available()>0)
   
   //process data received
 if(started && ended)
   {
     data =strtok(indata,",");
     //convert received data floats , assign them variables
     if(atof(data)==3){
     while(data != null){
         vdata[count]=atof(data);
         data=strtok(null,",");
         count++;
       }
     
   //transmit data if information received robot 3

       senddata();
     }
     vdata[0]=0;
     //reset booleans
     started = false;
     ended= false;
     index=0;
     indata[index]='\0';
   } //if(started && ended)
} //comm



when senddata() called information transmitted.

code: [select]

void senddata()
{
 serial2.print('<');
 serial2.print(1);serial2.print(',');
 serial2.print(posx);serial2.print(',');
 serial2.print(posy);serial2.print(',');
 serial2.print(veld);
 serial2.print('>');
 serial2.print(millis());serial2.print("\n");
} //senddata


how xbees configured? list pan id, , dl values each one.


Arduino Forum > Using Arduino > Networking, Protocols, and Devices (Moderator: fabioc84) > Xbee-Xbee communication stops


arduino

Comments

Popular posts from this blog

Thread: PKI Client 5.00 install (for eToken Pro)

ATmega2560-Arduino Pin Mapping

Crossfader Arduino Tutorial