#include "ros/ros.h" #include "std_msgs/String.h" void chatterCallback(const std_msgs::String::ConstPtr& msg)/*Comment0*/ { ROS_INFO("I heard [%s]",msg->data.c_str()); } int main(int argc,char **argv) { ros::init(argc,argv,"example1_b"); ros::NodeHandle n; ros::Subscriber sub = n.subcribe("message",1000,chatterCallback);/*Comment1*/ ros::spin(); return 0; } /*___________________________Comment0__________________________________ **This function will be called every time the node receives a message and we can consume or process the data. This instance **, we output the received data in the command line window. _______________________________________________________________________ */ /*___________________________Comment1__________________________________ **Create a subscriber and get the message data named message from the topic. set buffer to 1000 **, the callback function for processing the message is messageCallback: **ros::spin() line is when the node starts to read the topic and the message arrives, the callback function messageCallback is called **The loop used. When the user presses Ctrl+c, the node exits the loop and the loop ends. _______________________________________________________________________ */
Ros creates subscriber node source code comments___20180422
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=324630539&siteId=291194637
Recommended
Ranking