ros2--功能包
创建功能包
创建C/C++的功能
ros2 pkg create --build-type ament_cmake 功能包的名称ros2 pkg create 功能包名称 --build-type ament_cmake --dependencies rclcpp
c++功能包的配置
创建python的功能包
ros2 pkg create 功能包的名字 --build-type ament_python --dependencies rclpy
ros2 pkg create --build-type ament_python 功能包的名字 --dependencies rclpy
python功能包的结构
eg:
ros2 pkg create test_urdf --build-type ament_python --dependencies rclpy
setup.py:
setup.py是python功能包特有的,C++功能包没有,用于描述这个python包的构建,安装信息。
该文件包含了功能包的元数据,依赖关系,安装脚本等。
packge.xml:
功能同C++,用于指定该功能包的依赖。
test_urdf:
一个包含这个功能包源代码的python包。
resource:
通常用于存放 非代码资源文件。
test:
-
存放 单元测试或集成测试代码,通常使用
pytest
或 ROS 的rostest
。 -
测试文件一般以
test_*.py
命名。
setup.cfg:
Python 项目的 静态配置文件,通常用于定义 setuptools
的默认选项。
python功能包的配置
创建功能包之后:
1,确保依赖了rclpy:
<depend>rclpy</depend>
2,配置程序入口:
entry_points={
'console_scripts': [
'可执行文件名(python文件名)=包名.可执行文件名:main',
],
},
eg:
entry_points={
'console_scripts': [
'interface_node=test_interface.interface_node:main',
],
},
3,配置文件的安装路径:
data_files=[
('share/ament_index/resource_index/packages',
['resource/' + package_name]),
('share/' + package_name, ['package.xml']),
(os.path.join('share',package_name,'launch'),glob(os.path.join('launch','*launch.py')))
],
作用
1,不同的功能包用于存放不同功能的代码(节点),减少代码之间的耦合性;
2,创建功能包不仅仅是创建功能包目录和功能包下的文件,一个很重要的作用是创建的功能包会在CMakeLists.txt中调用ament_package()接口。