ROS and Arduino Learning (3) Subscription and Publishing

ROS and Arduino Learning (2) Subscription and Publishing

Tutorial Level:HelloWorld

Next Tutorial:

This section describes how to publish and subscribe to messages in arduino. He communicates with ROS through the serial port for node communication.

Tips 1 Subscribe

 

ros::Subscriber<std_msgs::Empty> sub("WWWW",&hhhhh);

 

 Where WWW is the name of the topic, and hhhhh is the name of the function called after receiving the message. sub is the name of the instantiated subscription object, or something else.

nh.subscribe(sub);

 

Among them, nh stands for handle, and each node has a handle. This node uses the sub subscription object to subscribe to topics in the world.

 

Tips 2 released

 

ros::Publisher chatter("chat",&str_msg);

 

 Where "chat" is the topic name, and str_msg is the message content. chatter is the name of the instantiated publish object.

 

nh.advertise(chatter)

 

 Among them, nh stands for handle, and each node has a handle. This node uses the chatter publish object to publish messages to topics in the world.

 

chatter.publish(&str_msg);

 

 make an announcement

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324787005&siteId=291194637