On 04/28/2011 10:57 PM, Abqori Aula wrote:
First of all, I'm sorry for the double post. I didn't know how to reply my own email thread in this mailing list.
I did not see any "reply button" or something like that;

Thank you Rich and Richard for your idea. Yesterday I decided to hard-coded the robot model's name using switch-case.
Which is actually avoid, because I'm simulating a lot number of robots.
switch (port_number){
    case 6666: robot = "robot2"; break;

    case 6667: robot = "robot3"; break;
    default: robot = "robot1"; 
then I call this function
sp.SetPose2d( (char *)string(robot).c_str(),x,y, (o- DTOR(90)));
However, I found out that the SimulationProxy prevented me to run another robot with port other than 6665 (the default).
If I run this command,
./program -p 6666
an error popped out:
playerc error   : got NACK from request
playerc error   : failed to get response

terminate called after throwing an instance of 'PlayerCc::PlayerError'
I tried to change the cfg file by adding more simulation interface:
	name "stage"
	provides ["simulation:0"]

	provides ["6666:simulation:0"]
	provides ["6667:simulation:0"]
	provides ["6668:simulation:0"]
	plugin "libstageplugin"
	worldfile "AMiR.world"
But then I could not run the robot with default port 6665. Instead I was able to run robot with port 6668 only.
So, I thought It might be something related to the definition of simulation proxy within the config file. Or I could be wrong.

Any idea? Thanks.

I don't think Player handles more than one Provides line in a driver block.  Player is probably ignoring the first ones and using the last one.  Either way, you can't provide multiple copies of the same interface on different ports. 

What you can do, however, is create two PlayerClient objects in your code: one that connects to port 6665 all the time for the SimulationProxy, and one that uses the port you specify in the argument. 

You could also keep everything on the same port and use the device indices to differentiate between the robots, like:

        name "stage"
        provides ["position2d:0" "sonar:0"]
        model "robot0"
        name "stage"
        provides ["position2d:1" "sonar:1"]
        model "robot1"
        name "stage"
        provides ["position2d:2" "sonar:2"]
        model "robot2"


Then in your code, you can specify some new argument, like -r 0 (you may have to customize parse_args.h, or just use a flag that's already there like -i ) and use that argument to generate the index name and the model name at runtime:

// Read the robotIndex from the command line, create a position2dproxy & sonarproxy
int robotIndex = argv[0];
PlayerClient robot("localhost", 6665);
Position2dProxy pp(&robot, robotIndex);
SonarProxy ir(&robot, robotIndex);
SimulationProxy sp(&robot, 0);

// Create Robot name, use it in Simulation Proxy
char robotName[16];
sprintf(&robotName, "robot%d", robotIndex);
sp.SetPose2d( robotName, x, y, a);

Hopefully this gives you some ideas on how to approach the problem.