当前位置:网站首页>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”配置的程序入口
边栏推荐
- International Open Source firmware Foundation (osff) organization
- Bit of MySQL_ OR、BIT_ Count function
- 在新线程中使用Handler
- 6-4 search by serial number of linked list
- LSA Type Explanation - lsa-5 (type 5 LSA - autonomous system external LSA) and lsa-4 (type 4 LSA - ASBR summary LSA) explanation
- Cookie、Session、JWT、token四者间的区别与联系
- Application of recyclerview
- Package webapp or H5 pages into apps
- Technical conference arrangement
- Configuration method and configuration file of SolidWorks GB profile library
猜你喜欢

GDB code debugging

2. Addition and management of Oracle data files

Financial risk control practice -- feature derivation based on time series

ethtool 原理介绍和解决网卡丢包排查思路(附ethtool源码下载)

Sre core system understanding

VLAN experiment

Speedtree01 generator properties

inux摄像头(mipi接口)简要说明

. Net core stepping on the pit practice

Client use of Argo CD installation
随机推荐
The “mode“ argument must be integer. Received an instance of Object
ADG5412FBRUZ-RL7应用 双电源模拟开关和多路复用器IC
ethtool 原理介绍和解决网卡丢包排查思路(附ethtool源码下载)
SolidWorks template and design library are convenient for designers to call
What is linting
The differences and connections among cookies, sessions, JWT, and tokens
Some classic recursion problems
H5 module suspension drag effect
微信小程序路由再次跳转不触发onload
How to answer when you encounter a jet on CSDN?
Qt项目中的日志库log4qt使用
7. Oracle table structure
5. Oracle TABLESPACE
UTC, GPS time and Tai
2048 project realization
Rehabilitation type force deduction brush question notes D3
Volcano resource reservation feature
.net core踩坑实践
H5 模块悬浮拖动效果
cgroup_ memcg