当前位置:网站首页>ROS create workspace process
ROS create workspace process
2022-07-18 23:15:00 【The earth was pried away by the fulcrum】
This article takes porting code as an example . The goal is to make a platform SDK Medium ROS The code part is picked out and transplanted to the workspace you created . Record the general process .
Catalog
2、 Compile workspace ( Optional )
3、 Set the environment variable ( Optional )
5、 Write source code 、 modify CMakeLists.txt file
1、 Create a workspace
mkdir -p pantilt_ws/src
cd pantilt_ws/src
catkin_init_workspacepantilt_ws Folders are workspaces created ,src The folder is created later Function pack Source code .catkin_init_workspace Command is used to initialize the workspace , The order will be in src Generate one in the folder CMakeLists.txt The file of .
2、 Compile workspace ( Optional )
This step is not necessary here , It can be put to the end . This step is only used here to explain that you can compile when the workspace is empty , in addition , To show how the workspace will change after running this command .
cd pantilt_ws
catkin_makecatkin_make In the workspace pantilt_ws In the middle of devel、build These two folders :

devel: Development space , Place executable files in the development process
build: Intermediate files generated during compilation
These two files and their contents are self generated by relevant instructions in the development process , We don't care .
3、 Set the environment variable ( Optional )
If steps are not performed 2, Go straight to step 4 that will do . After compiling the workspace, you need to add the workspace to the environment variable , You can use the following instructions , Put the workspace devel Under folder setup.bash The path of the file is added to the environment variable .
source devel/setup.bashThe inconvenience of doing this is that you have to re run each time source once , We can add the following path directly to ~/.bashrc In file
open ~/.bashrc file
gedit ~/.bashrcAdd a path
source ~/Desktop/pantilt_ws/devel/setup.bashSave and exit .
4、 Create Feature Pack
The function package must be placed in the workspace src Under the folder , In addition, all source code must be placed in the function package . Create a template for the Feature Pack :
catkin_create_pkg <package_name> [depend1] [depend2] [depend3] catkin_create_pkg The command is followed by the name of the Feature Pack , Function report name followed by dependency .
Here I create a file called pantilt_ctl Function pack :
cd pantilt_ws/src
catkin_create_pkg pantilt_ctl std_msgs rospy roscpp message_generation message_runtimeAfter the creation is successful pantilt_ws/src There will be one more pantilt_ctl And a folder named CMakeLists.txt The file of

stay pantilt_ctl A new folder will be created include and src Folders and CMakeLists.txt and package.xml file .

package.xml The beginning of the document is mainly to use xml The function of language recording is reported name 、 edition 、 Description and open source agreement Etc , then package.xml It also includes Function package dependency Information . When creating the function package std_msg/roscpp/rospy The dependency package will be written here , If there are additional dependent function packages, you can manually add them .

CMakeLists.txt The file is mainly used to describe the Compilation Rules of the function package during compilation , That is, some compilation instructions , It uses CMake The grammar of .
5、 Write source code 、 modify CMakeLists.txt file
If you write your own code, it's in the function pack pantilt_ctl Of src New under folder cpp Source file , stay include New under folder cpp The header file is enough .
Here, Yuntai will be officially SDK Copy the relevant files in the source code , And make the corresponding class name 、 Modification of path name, etc .
And then there's the modification CMakeLists.txt The content of the document .
For example, I have only one read_write_node.cpp Of ROS Node source file , So you need to CMakeLists.txt Add the following two statements to the file :
add_executable(read_write_node src/read_write_node.cpp)
target_link_libraries(read_write_node ${catkin_LIBRARIES})
add_executable The first parameter is the name of the generated executable , The second parameter is the code that needs to be compiled .
target_link_libraries Set the link library to generate executable files .
For other commands ,CMakeLists.txt There are corresponding comments in the document to explain the function of the command .
for example , If you want to add msg file ( Create... In the feature pack msg Folder , New msg All the papers are here ) If it works , Just add the following statement ;
find_package(catkin REQUIRED COMPONENTS
...
message_generation
)
## Generate messages in the 'msg' folder
add_message_files(
FILES
your_msg_name.msg
)
## Generate added messages and services with any dependencies listed here
generate_messages(
DEPENDENCIES
std_msgs
)
catkin_package(
...
message_runtime
)- find_package Add the dependent function package .
- add_message_files It lists your msg file Name , In this way, the program will find the defined message interface when compiling , Then compile according to this interface , And generate the corresponding header file and put it in devel/include/[your_package_name]/[your_msg_name].h in ,cpp When used in the code, directly add the header file through the following code :
#include "[your_package_name]/[your_msg_name].h"- generate_messages Compilation generation is listed in msg Time dependence , Here is std_msgs.
- catkin_package Add msg Compile time dependencies , namely message_runtime.
Still need to be in package.xml Add function package dependencies to the file :
<build_depend>message_generation</build_depend>
<exec_depend>message_runtime</exec_depend>
build_depend Is a compilation dependency , Dependencies required during program compilation .
exec_depend Is the execution dependency , Dependencies needed when the program runs .
6、 Compile function packs
First go back to the directory of the workspace and execute the compilation
cd pantilt_ws
catkin_makeThen set the environment variable
source pantilt_ws/devel/setup.bash7、 Enable node
Use the command first roscore start-up rosmaster, Then open a new terminal to use rosrun The command enables nodes in the Feature Pack , The grammar is :
rosrun [your_package_name] [you_node_name]rosrun Followed by Function pack Name , The function package name is followed by this Nodes in the function package Name .
Such as :
rosrun pantilt_ctl read_write_node边栏推荐
- 11(2).结构体的存储方式,结构体变量和结构体变量指针作为函数参数传递的问题,指针的优点
- Why is SaaS so important for enterprise digital transformation?
- Dialogue with machines, Ali Dharma academy challenges the new generation of man-machine dialogue Technology
- Learning record: FSMC - extended external SRAM
- Generate multiple databases at the same time based on multiple data sources and zero code, add, delete, modify and check restful API interfaces - mysql, PostgreSQL, Oracle, Microsoft SQL server multip
- 【Flutter--实战】Dart 语言快速入门
- SQL Server locks nolock, updlock, holdlock, readpass
- C # find perfect numbers, output daffodils and use of classes
- 【图片编辑小软件】FastStone Photo Resizer支持批量转换和批量重命名
- Log collection scheme efk
猜你喜欢

sklearn线性回归拟合一次项函数

20220714给AIO-3568J适配OpenHarmony-v3.1-beta(编译Buildroot)

开发到底要不要转行软件测试?一篇足以 最全方位分析

About products | how to plan products?

10分钟自定义搭建行人分析系统,检测跟踪、行为识别、人体属性All-in-One

Pytorch installation (very detailed)

【无标题】

3D point cloud course (II) -- nearest neighbor problem

三维点云课程(三)——聚类

leetcode--242. Valid alphabetic ectopic words
随机推荐
Be diligent in chatting
"Interface automation" software tests the core skills of salary increase and increases salary by 200%
sklearn线性回归完成多次项函数和正弦函数拟合
自定义Hook 和 普通函数、函数组件 的区别
ospf综合实验
Unpacking: what books are Ali technicians reading?
11(2).结构体的存储方式,结构体变量和结构体变量指针作为函数参数传递的问题,指针的优点
Configure SSH login for Huawei switches
单元测试界的高富帅,Pytest框架 (完) 测试报告篇
Concept of Lun
Mysql相关命令
[CVPR2019] On Stabilizing Generative Adversarial Training with Noise
C # network application programming, experiment 1: WPF exercise
【Flutter--实战】Dart 语言快速入门
Private domain operation is very popular. Is private domain operation suitable for all enterprises?
20220714 adapt openharmony-v3.1-beta to aio-3568j (compile builderoot)
mysql忘记密码重置
Profile encryption
The best way to practice Animation: cover transition
三维点云课程(四)——聚类与模型拟合