How to use msgs in ros
Hi dear I want to write a program that is tell me how many msgs that one node has published How can I write this program I wrot this program but it's not worked
#include "ros/ros.h"
#include "std_msgs/String.h"
int i=0;
void chatterCallback(const std_msgs::String::ConstPtr& msg)
{
//ROS_INFO("I heard: [%s]", msg->data.c_str());
i++;
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "lisiner");
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe("chater", 1000, chatterCallback);
ros::Rate timeloop(5);
while(ros::ok())
{
ROS_INFO("%d",i);
timeloop.sleep();
}
return 0;
}