int main(int argc, char **argv) { //Initiate ROS ros::init(argc, argv, "subscribe_and_publish"); // Create the vector of topics that will be used to store the list of current topics ros::master::V_TopicInfo topics; ros::master::getTopics(topics); // Create the string that will be searched for in the topics: std::string searchString = "/vrpn_client_node/"; //Create an object of class SubscribeAndPublish that will take care of everything SubscribeAndPublish SAPObject("testingishere"); SubscribeAndPublish SAPObject2("testingishere2"); // Will I need a while ros::ok() loop? ros::master::TopicInfo testing; int i=0; std::string topicToCreate; // Here we need to create a vector of SubPubs, so that we can create many objects std::vector<SubscribeAndPublish> SubPubVector; //for (i=0;i<topics.size();i++){ for (i=(topics.size()-1);i>0;i--){ ROS_INFO("we are at %d", i); testing = topics.at(i); std::size_t pos = testing.name.find(searchString); if (pos != std::string::npos){ // Need to create a Subscribe and Publish // The topics we are looking for in this case will look something like: // /vrpn_client_node/Ardrone/pose // Generically, they could look like anything in the searchString topicToCreate = (testing.name.substr(pos+searchString.length()));// The pos is there in case the search string doesn't start at the beginning of the topic name ROS_INFO("We are going to create %s", topicToCreate.c_str()); SubscribeAndPublish SAPObject(topicToCreate); SubPubVector.push_back(SAPObject); } // end if } // end for ros::spin(); return 0; }
int main(int argc, char **argv) { ros::init(argc, argv, "Odometry_publisher"); ros::NodeHandle nh_private("~"); std::string talker_topic = ""; if(!nh_private.getParam("talker_topic", talker_topic)){ talker_topic = "/talker_boost_serial"; } SubscribeAndPublish SAPObject(talker_topic); SAPObject.current_time = ros::Time::now(); SAPObject.last_time = ros::Time::now(); ros::spin(); }