当前位置:网站首页>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”配置的程序入口
边栏推荐
- ethtool 原理介绍和解决网卡丢包排查思路(附ethtool源码下载)
- Inclusion exclusion principle acwing 890 Divisible number
- 在新线程中使用Handler
- [QT] QT multithreading development qthread
- Cloud native related technology learning
- Vant Weapp SwipeCell设置多个按钮
- Cookie、Session、JWT、token四者间的区别与联系
- Application of recyclerview
- Preemption of CFS scheduling
- how to understand the “model independent.“
猜你喜欢

在本地搭建一个微服务集群环境,学习自动化部署

All English in the code

Bit of MySQL_ OR、BIT_ Count function

International Open Source firmware Foundation (osff) organization

Knapsack problem acwing 9 Group knapsack problem

cgroup_ memcg

PHY驱动调试之 --- MDIO/MDC接口22号和45号条款(一)

TCP's understanding of three handshakes and four waves

Vant Weapp SwipeCell設置多個按鈕

Orin installs CUDA environment
随机推荐
About vscode, "code unreachable" will be displayed when calling sendline series functions with pwntools“
4.Oracle-重做日志文件管理
Vant weave swipecell sets multiple buttons
The problem of Chinese garbled code in the vscode output box can be solved once for life
Vant Weapp SwipeCell设置多个按钮
The “mode“ argument must be integer. Received an instance of Object
Redis-02. Redis command
confidential! Netease employee data analysis internal training course, white whoring! (attach a data package worth 399 yuan)
Database mysql all
1. Create Oracle database manually
Written examination notes
Rehabilitation type force deduction brush question notes D1
‘mongoexport‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件。
UTC, GPS time and Tai
2022 winter vacation training game 5
How to answer when you encounter a jet on CSDN?
Speedtree01 generator properties
Edge calculation data sorting
Technology blog learning website
vim