Can I call ROS “ros::init(…)” within the player (Player/Stage) driver?
I am trying to write a Player driver that will publish messages on ROS.
Player driver does not create an executable file and hence I am not sure how to call ROS initialize within the player driver.
The main function of player driver looks like this...
void PlayerDriver::Main()
{
int argc; // Player Main() method does not take argument
char **argv; // What to do with argc and argv??
geometry_msgs::Point commandInput;
ros::init(argc, argv, "Command");
ros::NodeHandle n;
ros::Publisher command_pub = n.advertise<geometry_msgs::Point>("servocommand", 1000);
ros::Rate loop_rate(1);
while (ros::ok())
{
ros::spinOnce();
ProcessMessages();
//Do some stuff
commandInput.x = globalVel.v;
commandInput.y = globalVel.w;
commandInput.z = 0.0;
command_pub.publish(commandInput);
//Do some stuff
loop_rate.sleep();
}
}
The Player driver compiles and creates a shared library and I have a cfg file. It is called by "player playerdriver.cfg" and works fine, gets connected to a Player Client but it does not publish messages on ROS.
As the Player Main() method does not take arguments, I believe this is where I am doing some mistake. Any suggestions are welcome.
Thanks @allenh1 for the reply. I saw your example, Robot class. I think here the Player is a client. I am trying to create a Player server. Do you think I can create a class as you have suggested? I have had no problem integrating a player client with ROS publisher/subscriber.
Hm. When you say player server, what exactly do you mean?
Player server (also known as Player Plugin). Please see following link http://psurobotics.org/wiki/index.php?title=Writing_a_Player_Plugin
Oh. I think I see what you're doing now. You're writing a Player, ROS driver to publish ros messages into player, right?
What I am trying to write is this "Simulated Robot with Player driver" which will allow a player client to subscribe with Position2d. The client can send Position2d msgs to simulated robot. Now, I want to put ROS Publisher in this "simulated player robot". Hope I was able explained my problem.