00001 // own class header first: https://stackoverflow.com/a/2762596/8224054 00002 #include "ros1_ros_cpptemplate/subscriber.hpp" 00003 00004 #include <string> 00005 00006 namespace ros1_ros_cpptemplate 00007 { 00008 00009 Subscriber::Subscriber(ros::NodeHandle& node_handle, const std::string& topic_name) 00010 { 00011 // Subscribing should be last after everything else of the class is ready 00012 int queue_size = 10; 00013 subscriber_ = node_handle.subscribe(topic_name, queue_size, &Subscriber::callback, this); 00014 } 00015 00016 Subscriber::~Subscriber() 00017 { 00018 } 00019 00020 void Subscriber::callback(const std_msgs::Int32Ptr& number) 00021 { 00022 ROS_INFO_STREAM("Got number " << number->data << " on " << subscriber_.getTopic()); 00023 } 00024 00025 } // namespace