2

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.

sks
  • 21
  • 2

2 Answers2

0

Look here link. And also go through the Publisher/Subscriber tutorial from ROS. You can start here with the research -> Example publisher.

alap
  • 646
  • 1
  • 11
  • 24
0

Option 1:(Recommended) You can pass the argc and argv value through constructor.

Option 2: You can try this:

int argc = 0;
char **argv = NULL;
ros::init(argc, argv, "node_name");

NB: ROS uses argc & argv to parse remapping arguments from the command line.

sat
  • 91
  • 8