ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

Create another publisher (class) inside the node like in the C++ tutorial for creating nodes? Should be something like this:

ros::Publisher pub; //When in class this is the member in class definition
pub = nh.advertise<pkg::TopicType>("awesome_topic", 1000 /*Queue*/); //This goes to Constructor 

//Your message somewhere in your main loop...
pkg::TopicType msg; 
/*add data to your msg here*/
msg.field="some data";
pub.publish(msg); //Publish it

See here: http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber%28c%2B%2B%29

Does that solve your question?

Create another publisher (class) inside the node like in the C++ tutorial for creating nodes? Should be something like this:

ros::Publisher pub; //When in class this is the member in class definition
pub = nh.advertise<pkg::TopicType>("awesome_topic", 1000 /*Queue*/); //This goes to Constructor 

//Your message somewhere in //Maybe your main loop...
loop

ros::Rate rate(10);
while(ros:ok())
{
  pkg::TopicType msg; 
 /*add data to your msg here*/
 msg.field="some data";
 pub.publish(msg); //Publish it

  ros::spinOnce();
  rate.sleep(); //limit loop rate
}

See here: http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber%28c%2B%2B%29

Does that solve your question?