Dear Toby;

Thanks for your answer here is a smallest version of my code.

#include <libplayerc++/playerc++.h>
#include <iostream>
#include <math.h>
#include <fstream>
#include <cstdlib>
#include <time.h>

using namespace PlayerCc;

PlayerClient robot("localhost", 6665);
PlayerClient robot1("localhost", 6666);
Position2dProxy position(&robot, 0);
Position2dProxy position1(&robot1, 0);
SonarProxy sonar(&robot, 0);

//These parameters for PSO Decision Making

double constrictionfactor = 0.7298, lowestlearning=0, highestlearning=2.05, step=1;
double best_pos[2][10000], best_pos1[2][10000], best_pos2[2][10000], best_pos3[2][10000], best_pos4[2][10000], best_pos5[2][10000];
double global_best_pos[2][10000];
double learning_coeff_1[2], learning_coeff_2[2], fitness[31][31], grid_fitness[31][31], velocity[2][10000], pos[3][10000];
double gbest[10000];
double pbest_can=0, pbest1_can=0, pbest2_can=0, pbest3_can=0, pbest4_can=0, pbest5_can=0;
double pbest[10000], pbest1[10000], pbest2[10000], pbest3[10000], pbest4[10000], pbest5[10000];
int stop=0;
int count=0;
/
/These parameters for Artifical Potential Function

double newspeed,speed,newturnrate,b,distance,a;
const double max_speed=0.6;
double grad[2], attraction[2], total_repulsion[2];

//Functions used

double Potential_Navigation(double desired_x, double desired_y);
double CalculateNorm(double a,double b);

//For random inital position generation and random learning vectors

time_t seconds;
time_t seconds1;

int main(void)
{
   
    std::ofstream myfile;
    std::ofstream myfile2;
    myfile.open("Robot1XKonumlarý.txt");
    myfile2.open("Robot1YKonumlarý.txt");   
    FILE *fi;
   
    float a;
    float grid_fitness[30][30];
   
    fi = fopen("output1.txt","r");
   
    while(fscanf(fi,"%f",&a)!=EOF)
    {
        for (int p=0;p<30;p++)
        {
            for (int o=0;o<30;o++)
            {
                fscanf(fi,"%f",&a);
                grid_fitness[o][p]=a;
            }
        }
    }   
   
velocity[0][0]=0.5;
    velocity[1][0]=0.5;
    position.SetMotorEnable (true);
   
    gbest[0]=0;
    //Main loop begins here
    for(int t=0;t<10001;++t)
    {
       
        //This is the stopping criteria for the search
        if(gbest[t-1]>134 && fabs(pos[0][t]-15)<1.5 && fabs(pos[1][t]-5)<1.5)
        {
            stop=stop+1;
        }
       
       
        if(stop>=1)
            break;
       
        std::cout << "Iterasyon:\t" << t << std::endl;

        while(1)
        {       

            robot.Read();
            speed=Potential_Navigation(pos[0][t],pos[1][t]);
   
            //Robot updates its pbest value while moving
           
            int row= (int)floor(position.GetXPos());   
            int col= (int)floor(position.GetYPos());
            if(grid_fitness[row][col]>pbest_can)         
            {                                                       
                best_pos[0][t]=position.GetXPos();
                best_pos[1][t]=position.GetYPos();
                pbest_can=grid_fitness[row][col];
                pbest[t]=pbest_can;
            }
            else
            {
                best_pos[0][t]=best_pos[0][t];
                best_pos[1][t]=best_pos[1][t];
                pbest[t]=pbest[t];
                pbest_can=pbest[t];
            }
            
             robot1.ReadIfWaiting();    //Reading in non-blocking manner
           
            if(position1.GetXSpeed()<=0.1)  
            {           
                int row1=(int)floor(position1.GetXPos());       
                int col1=(int)floor(position1.GetYPos());       
                if(grid_fitness[row1][col1]>pbest1_can)     
                {                                                          
                    best_pos1[0][t]=position1.GetXPos();
                    best_pos1[1][t]=position1.GetYPos();           
                    pbest1_can=grid_fitness[row1][col1];
                    pbest1[t]=pbest1_can;   
                }
                else
                {
                    best_pos1[0][t]=best_pos1[0][t];
                    best_pos1[1][t]=best_pos1[1][t];           
                    pbest1[t]=pbest1[t];
                    pbest1_can=pbest1[t];
                }
               
            }
          
            if(speed<=0.05)
                  break;   
            
        }
   
        //Decision making
        if(pbest[t]>pbest[t-1])
        {
            pbest[t]=pbest[t];
            best_pos[0][t]=best_pos[0][t];
            best_pos[1][t]=best_pos[1][t];
        }
        else
        {
            pbest[t]=pbest[t-1];
            best_pos[0][t]=best_pos[0][t-1];
            best_pos[1][t]=best_pos[1][t-1];
        }
       
        gbest[t]=gbest[t-1];   
        global_best_pos[0][t]=global_best_pos[0][t-1];
        global_best_pos[1][t]=global_best_pos[1][t-1];
       
        if(pbest1[t] > pbest2[t] && pbest1[t] > pbest3[t] && pbest1[t] > pbest4[t] && pbest1[t] > pbest5[t] &&   pbest1[t] > gbest[t] && pbest1[t] > pbest[t])
        {               
            global_best_pos[0][t]=best_pos1[0][t];
            global_best_pos[1][t]=best_pos1[1][t];
            gbest[t]=pbest1[t];
                       
        }           
               
       //Generating learning coefficients
        time(&seconds1);
        srand((unsigned int) seconds1);
        for(int m=0; m<16; m++)
        {
            for (int l=0; l<2; l++)
            {
              learning_coeff_1[l] = lowestlearning +                 double(highestlearning-lowestlearning)*(double(rand())/double(RAND_MAX));
                learning_coeff_2[l] = lowestlearning + double(highestlearning-lowestlearning)*(double(rand())/double(RAND_MAX));

            }
        }
           
        //PSO Update
        for(int k=0; k<2; k++)
        {
            velocity[k][t+1]= constrictionfactor * ( velocity[k][t] + learning_coeff_1[k]*(best_pos[k][t]-pos[k][t]) + learning_coeff_2[k]*                                         (global_best_pos[k][t] - pos[k][t]));                                                                                                                     
            pos[k][t+1]=pos[k][t]+velocity[k][t+1];

        }
}

   





2008/3/28, Toby Collett <tcollett+player@plan9.net.nz>:
Their is no reason that the code you have posted should not work in theory. Can you reduce it to the smallest example set and post your code and config files.

Toby

On 28/03/2008, Burak Akat <burak.akat@gmail.com> wrote:
Hi

I am using Player 2.0.4 and Stage 2.0.3 and I am working a project involving inter-robot communication and exchange of robot's position information between them. For this purpose I am using ReadIfWaiting() command which corresponds to non-blocking reading manner, there is no blocking time in order to synhcronize the information exchange between the robots. The problem is that once the communication traffic between the robot becomes intense program crash and prints error message of like this;

playerc error   : poll call failed with error [0:Success]
playerc error   : recv failed with error [Success]
warning : failed to reconnect
terminate called after throwing an instance of 'PlayerCc::PlayerError

I am using 6 robots. My question is that, is Player can not handle such a type of communication (non-blocking) between the robots or did I do something wrong. Here is a code snippet where I am using ReadIfWaiting() command. Here the main robot is robot the other robot is robot1 and I am taking the odometry information of robot1 if it stops. There are also 4 other robots that I perform actions like this.

PlayerClient robot("localhost", 6665);
PlayerClient robot1("localhost", 6666);
Position2dProxy position(&robot, 0);
Position2dProxy position1(&robot1, 0);

robot.Read();
{
Get the position odometry
}

robot1.ReadIfWaiting();    //Reading in non-blocking manner
           
if(position1.GetXSpeed()<=0.1)
{
Get the position odometry of other robot
}

Hoping to hear you from near future

Best regards

Salih Burak Akat


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Playerstage-users mailing list
Playerstage-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/playerstage-users




--
This email is intended for the addressee only and may contain privileged and/or confidential information
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Playerstage-users mailing list
Playerstage-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/playerstage-users