当前位置:网站首页>ROS2——功能包(六)
ROS2——功能包(六)
2022-07-05 06:35:00 【我与nano】
ROS2机器人操作系统
前言
每个机器人可能有很多功能,比如移动控制、视觉感知、自主导航等,如果我们把这些功能的源码都放到一起当然也是可以的,但是当我们想把其中某些功能分享给别人时,就会发现代码都混合到了一起,很难拆分出来。
一、功能包是什么

举个例子,我们手上有很多红豆、绿豆、黄豆,假设都放在一个袋子里,如果只想把黄豆都拿出来,是不是得在五颜六色的豆子里一颗一颗都找出来,数量越多,你就越头疼;如果我们把不同颜色的豆子放在不同的三个袋子里,需要拿出某种豆子的时候,不就立刻可以找出来了么。
功能包就是这个原理,我们把不同功能的代码划分到不同的功能包中,尽量降低他们之间的耦合关系,当需要在ROS社区中分享给别人的时候,只需要说明这个功能包该如何使用,别人很快就可以用起来了。
所以功能包的机制,是提高ROS中软件复用率的重要方法之一。
二、功能包的具体使用
1.创建功能包
我们可以使用这个指令:
ros2 pkg create --build-type <build-type> <package_name>
ros2命令中:
**pkg:**表示功能包相关的功能;
**create:**表示创建功能包;
build-type:表示新创建的功能包是C++还是Python的,如果使用C++或者C,那这里就跟ament_cmake,如果使用Python,就跟ament_python;
**package_name:**新建功能包的名字。
比如在终端中分别创建C++和Python版本的功能包:
cd ~/dev_ws/src
ros2 pkg create --build-type ament_cmake learning_pkg_c # C++
ros2 pkg create --build-type ament_python learning_pkg_python # Python

2.编译功能包
在创建好的功能包中,我们可以继续完成代码的编写,之后需要编译和配置环境变量,才能正常运行:
cd ~/dev_ws/src
colcon build # 编译工作空间所有功能包
source install/local_setup.bash
3.功能包的结构
C++功能包
首先看下C++类型的功能包,其中必然存在两个文件:package.xml和CMakerLists.txt。
package.xml文件的主要内容如下,包含功能包的版权描述,和各种依赖的声明。
CMakeLists.txt文件是编译规则,C++代码需要编译才能运行,所以必须要在该文件中设置如何编译,使用CMake语法。
Python功能包
C++功能包需要将源码编译成可执行文件,但是Python语言是解析型的,不需要编译,所以会有一些不同,但也会有这两个文件:package.xml和setup.py。
package.xml文件的主要内容和C++版本功能包一样,包含功能包的版权描述,和各种依赖的声明。
setup.py文件里边也包含一些版权信息,除此之外,还有“entry_points”配置的程序入口
边栏推荐
- Paper reading report
- 5. Oracle TABLESPACE
- How to answer when you encounter a jet on CSDN?
- Vscode editor
- 5.Oracle-錶空間
- What is linting
- Cloud native related technology learning
- PHY驱动调试之 --- MDIO/MDC接口22号和45号条款(一)
- Getting started with typescript
- Pycahrm reports an error: indentation error: unindent does not match any outer indentation
猜你喜欢

AE tutorial - path growth animation

cgroup_ memcg

Design specification for mobile folding screen

【高德地图POI踩坑】AMap.PlaceSearch无法使用

ADG5412FBRUZ-RL7应用 双电源模拟开关和多路复用器IC

Interval problem acwing 906 Interval grouping

Volcano resource reservation feature

Game theory acwing 892 Steps Nim game

Stack acwing 3302 Expression evaluation

Skywalking all
随机推荐
ollvm编译出现的问题纪录
[algorithm post interview] interview questions of a small factory
RecyclerView的应用
微信小程序路由再次跳轉不觸發onload
Technical conference arrangement
Find the combination number acwing 888 Find the combination number IV
Install opencv -- CONDA to establish a virtual environment and add the kernel of this environment in jupyter
Bit of MySQL_ OR、BIT_ Count function
The “mode“ argument must be integer. Received an instance of Object
Vscode editor
7. Oracle table structure
5.Oracle-錶空間
How to correctly ask questions in CSDN Q & A
What is linting
'mongoexport 'is not an internal or external command, nor is it a runnable program or batch file.
Vant weapp swippecell set multiple buttons
Use ffmpeg to rotate, flip up and down, and flip horizontally
PHY驱动调试之 --- MDIO/MDC接口22号和45号条款(一)
摄像头的MIPI接口、DVP接口和CSI接口
Modnet matting model reproduction