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

Revision history [back]

click to hide/show revision 1
initial version

Hi,

Do I need to use different nodeHandle with the subscriber for the publisher?

No, you can subscribe and publish with the same node handler.

Can I put the following line things into the main function and use the callback function for the publisher?

in the case that you want to publish the coming message with same rate or you want to publish it whenever you receive it, one solution is to declare a global publisher (outside main() ):

ros::Publisher endPose_pub;

then inside the main, you can define it as

endPose_pub = nh.advertise<geometry_msgs::PoseStamped>("pose", 100, popub_callback);

then you can use the publisher inside the callback and publish your message.