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

Revision history [back]

Something like will do the job.

void callback()
{
  static counter = 0;
  counter++;
  std::cout << counter << std::endl;
}


int main()
{
  ros::init(argc, argv, "node_name");

  ros::Subscriber sub = n.subscribe("your_sub_topic", 1, callback);

  ros::spin();

}

Something like will do the job.

void callback()
callback(msg::type & msg)
{
  static counter = 0;
  counter++;
  std::cout << counter << std::endl;
}


int main()
{
  ros::init(argc, argv, "node_name");

  ros::Subscriber sub = n.subscribe("your_sub_topic", 1, callback);

  ros::spin();

}

Something like will do the job.

void callback(msg::type & msg)
{
  static int counter = 0;
  counter++;
  std::cout << counter << std::endl;
}


int main()
{
  ros::init(argc, argv, "node_name");

  ros::Subscriber sub = n.subscribe("your_sub_topic", 1, callback);

  ros::spin();

}