当前位置:网站首页>Programming implementation of subscriber node of ROS learning 3 subscriber

Programming implementation of subscriber node of ROS learning 3 subscriber

2022-07-05 08:45:00 m0_ forty-six million ninety-three thousand eight hundred and t

One 、 Overview of topic subscription process

The general idea of subscribing to topics and publishing topics is the same

1. Subscriber creation

2. compile

3. Configure environment variables

4. Execute the subscription topic file

Two 、 The specific process

2.1 Subscriber creation

In the corresponding workspace Src Create .cpp or .py file

The document consists of at least four parts

1. initialization ROS node

2. Subscribe to required topics , Register callback function ( Subscribing to a topic is like responding to an interruption , You don't know when the topic you subscribe to will come , So it needs to be like a response terminal , Wait until the topic comes , Call the callback function immediately after the topic comes , Therefore, the callback function should be written as short as possible . It is mainly about printing messages or simply processing messages )

3. Loop waiting for topic messages , Once the message is received, it enters the callback function

4. Complete the message processing in the callback function

Pay attention to this , Callback functions cannot be too complex , Otherwise, just run your functions when the program is running , Don't respond until the next topic message .

2.2 compile

If it is .cpp Files need to be compiled , If it is .py Files don't need to be , The specific compilation process can be seen ROS Study 2 Post topics (ROS Study 2- Post topics _m0_46093829 The blog of -CSDN Blog

1. Set Compilation Rules

2. In the workspace catkin_make

3、 ... and 、 Configure environment variables

source devel/setup.bash

Four 、 Execute the subscription topic file

rosrun Folder name Topic name

原网站

版权声明
本文为[m0_ forty-six million ninety-three thousand eight hundred and t]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140540130765.html