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);
SonarProxy ir(&robot, 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:
case 6666: robot = "robot2"; break;
case 6667: robot = "robot3"; break;
default: robot = "robot1";
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:
provides ["position2d:0" "sonar:0"]
provides ["position2d:1" "sonar:1"]
provides ["position2d:2" "sonar:2"]
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;
PlayerClient robot("localhost", 6665);
Position2dProxy pp(&robot, robotIndex);
SonarProxy ir(&robot, robotIndex);
SimulationProxy sp(&robot, 0);
// Create Robot name, use it in Simulation Proxy
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