Hi Rich, thanks for your ideas. I was able to figure out your second idea. That was a great idea to capture the robot's model name.
I didn't notice that indices could be used to represent different device.

But for your first suggestion, I failed. I tried your first suggestion, I came up with these lines:

    PlayerClient        stage(gHostname, 6665);
    PlayerClient        robot(gHostname, port);
    Position2dProxy    pp(&robot,gIndex);
    SonarProxy        ir(&robot, gIndex);
    SimulationProxy    sp(&stage,gIndex);

I then use the port number argument to run the robot. But, it still only run on robot port 6665, not on another robot (port) with the following error message:

playerc error   : connect call on [localhost:6666] failed with error [111:Connection refused]
terminate called after throwing an instance of 'PlayerCc::PlayerError'

I keep the previous switch-case to catch the robot's model name:
switch (port_number){
case 6666: robot = "robot2"; break;

case 6667: robot = "robot3"; break;
default: robot = "robot1";

What's wrong with these lines?

Only for curiosity:
How is this "create two PlayerClient thing" actually work? I knew how to connect them, but then that's it. I don't know what next.
I've found a lot of "create two PlayerClient thing" suggestions for different problems within this mailing list. But, none has actually replied that they managed to do it.

Anyway, thanks again.

On Fri, Apr 29, 2011 at 12:21 PM, Rich Mattes <jpgr87@gmail.com> wrote:
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.


WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network
management toolset available today.  Delivers lowest initial
acquisition cost and overall TCO of any competing solution.
Playerstage-users mailing list


                        .:. ABQORI AULA .:.
       .:. Intelligent System & Robotic Laboratory .:.
      .:. Smart Technology & Robotic Engineering .:.
           .:. Institute of Advanced Technology .:.          
.:. Registered Linux User #483621 Machine #394322 .:.
Skype ID: abqorian