当前位置:网站首页>ROS learning 4 custom message
ROS learning 4 custom message
2022-07-05 08:45:00 【m0_ forty-six million ninety-three thousand eight hundred and t】
One 、ROS Message structure built in
ros It provides us with many message structures ; Thank the blogger for sorting out the commonly used ROS Message type API Commonly used ROS Message type API Organize quick check _ Jiangzhu fisherman and woodcutter laugh at Chunfeng's blog -CSDN Blog
How can we see which data types this message structure can support ? have access to roscd Structure name Open the folder where the message structure is located .
for example :
For example, we open one of them msg File to check its data type
Two 、 Custom message
Then we know how to check ros After the customized message , Then if ros Customized messages can't meet our needs , How can we build our own news by ourselves ? An overview of the answer process is as follows :
1. Customize the message data and its type .msg file
2. stay package.xml Add Feature Pack dependencies to
3. stay CMakeList.txt Add compilation options to
4. Compile and generate relevant files
The specific process is as follows :
2.1 Customize the message data and its type .msg file
First, under the corresponding workspace and corresponding function package , Create a msg Folder , All definitions related to messages should be placed in this msg Under the folder . Then create... In this folder .msg file
For example, I want to release a pair person Description of gender and age , Then my data and its types are as follows :
2.2 Set Compilation Rules
2.2.1 First, you need to add relevant compilation dependencies
stay package.xml Add the following two dependencies , See the following for the added position
<build_depend>message_generation</build_depend># Compile dependencies , Dynamic production messgae Dependence
<exec_depend>message_runtime</exec_depend># Operational dependency
2.2.2 stay CMakeList.txt Add relevant Compilation Rules in
1. stay find_pack Add message_generation Function pack
2. Add your own .msg Configuration items for compiling files into related files , Add location as follows
add_message_files(FILES Person.msg)# Yours .msg An interface to the file
generate_messages(DEPENDCIES std_msgs)# Compile your .msg Files are needed ros Which message structures in
3. stay catkin_package Open all the dependencies you need , Some have been annotated, you can untie it , What you don't have needs to be added by yourself
For example, you are 2.2.1 Time to add dependencies :message_runtime And above 2.2.2 in generate_messages(DEPENDCIES std_msgs) Need to use std_msgs. So you need to untie CATKIN_DEPENDS And add message_runtime
3、 ... and 、 compile
Under workspace ,catkin_make once
Four 、 How to call a custom message
And call ros The information provided is the same , Write publisher and subscriber files , Then define the Compilation Rules , Then compile , And finally add environment variables .
However, when compiling rules, you need to pay attention to adding 6 Line code :
add_executable(person_publisher src/person_publisher.cpp)
target_link_libraries(person_publisher${catkin_LIBRARIES})
add_dependencies(person_publisher${PROJECT_NAME}_generate_messages_cpp)
add_executable(person_subscriber src/person_subscriber.cpp)
target_link_libraries(person_subscribier${catkin_LIBRARIES})
add_dependencies(person_subscribier${PROJECT_NAME}_generate_messages_cpp)
Be careful : Because what is called is a custom message , Therefore, in addition to the description of the compiled code file , In addition to its link dependency library, it is also necessary to generate dependencies between dynamically generated executable files and dynamically generated files of publishers and subscribers of topics . namely
add_dependencies(person_subscribier${PROJECT_NAME}_generate_messages_cpp)
5、 ... and 、 About CMakeLists.txt and package.xml
The details are as follows: package.xml and CMakeLists.txt What is added to is actually CMakeLists.txt It is written in . I put CMakeLists.txt The contents of the file are stuck , You can look at it . Let's talk about it in detail package.xml and CMakeLists.txt.
################################################
## Declare ROS messages, services and actions ##
################################################
## To declare and build messages, services or actions from within this
## package, follow these steps:
## * Let MSG_DEP_SET be the set of packages whose message types you use in
## your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...).
## * In the file package.xml:
## * add a build_depend tag for "message_generation"
## * add a build_depend and a exec_depend tag for each package in MSG_DEP_SET
## * If MSG_DEP_SET isn't empty the following dependency has been pulled in
## but can be declared for certainty nonetheless:
## * add a exec_depend tag for "message_runtime"
## * In this file (CMakeLists.txt):
## * add "message_generation" and every package in MSG_DEP_SET to
## find_package(catkin REQUIRED COMPONENTS ...)
## * add "message_runtime" and every package in MSG_DEP_SET to
## catkin_package(CATKIN_DEPENDS ...)
## * uncomment the add_*_files sections below as needed
## and list every .msg/.srv/.action file to be processed
## * uncomment the generate_messages entry below
## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)
5.1 package.xml
package.xml File package list , It must be included in any compliance catkin In the root directory of the standardized package . This file defines the various properties of the package , For example, package name , Version number , author , Maintainers and others catkin Package dependency .
For details, see :ROS Catkin Tutorial of package.xml_lcc816 The blog of -CSDN Blog
The package can have six types of dependencies :
- Build rely on Specify the packages needed to build this package . In this case, some files from these packages are required during construction , For example, header files from these packages are included at compile time , Need to link libraries from these packages or need any other resources when building ( Especially when these bags are in CMake Medium find_package() when ). In the cross compilation scheme , Build dependencies should apply to the target architecture .
- Build Export dependency Specify that this package be built as the package on which the library depends . For example, you include the dependent header file in the header file to be exported , This is the case ( Especially when these packages are in CMake Medium catkin_package() Declared as (CATKIN_)DEPENDS when ).
- Execution rely on Specify the package needed to run the code in this package . This is the case when the dependencies in this package have shared libraries ( Especially when these packages are in CMake Medium catkin_package() Declared as (CATKIN_)DEPENDS when ).
- Test rely on Specify only for unit tests other Dependencies . Don't specify the build and run-time dependencies that have already been mentioned .
- Build Tool dependence Specify the build system tools that this package needs to build itself . Usually , The only building tool needed is catkin. In the cross compilation scheme , Build tool dependencies should apply to the architecture that performs compilation .
- Documentation tools rely on Specify the tools that the package uses to generate documents .
Above 6 The three dependencies use the following 6 Labels specify :
<depend>
<buildtool_depend>
<build_depend>
<build_export_depend>
<exec_depend>
<test_depend>
<doc_depend>
5.2 CMakeLists.txt
CMakeLists.txt Yes, it is CMake Build system ROS The input file of the package . Any compatible CMake All packages contain one or more CMakeLists.txt file , Used to describe how to build and install code .catkin The project adopts standard vanilla CMakeLists.txt file , With some additional constraints .
For detailed description, see :ROS Catkin Tutorial of CMakeLists.txt_lcc816 The blog of -CSDN Blog
thank ROS Learning notes ( 3、 ... and ): Programming of customized topics _wwwlyj123321 The blog of -CSDN Blog _ros Topic programming , About package.xml and CMakeLists.txt I found it from this blog .
边栏推荐
猜你喜欢
Yolov4 target detection backbone
Bluebridge cup internet of things basic graphic tutorial - GPIO input key control LD5 on and off
Redis实现高性能的全文搜索引擎---RediSearch
Old Wang's esp8266 and old Wu's ws2818 light strip
MATLAB小技巧(28)模糊綜合評價
Mathematical modeling: factor analysis
猜谜语啦(11)
Daily question - input a date and output the day of the year
Classification of plastic surgery: short in long long long
Guess riddles (7)
随机推荐
kubeadm系列-00-overview
U8g2 drawing
ECMAScript6介绍及环境搭建
287. Looking for repeats - fast and slow pointer
C language data type replacement
Run menu analysis
猜谜语啦(10)
ORACLE进阶(三)数据字典详解
Matlab tips (28) fuzzy comprehensive evaluation
Lori remote control commissioning record
资源变现小程序添加折扣充值和折扣影票插件
Apaas platform of TOP10 abroad
L298N module use
2022.7.4-----leetcode.1200
[matlab] matlab reads and writes Excel
PIP installation
Guess riddles (11)
猜谜语啦(7)
[formation quotidienne - Tencent Selection 50] 557. Inverser le mot III dans la chaîne
12、动态链接库,dll