ros2与Python入门教程-创建ros2包
ros2与Python入门教程-创建ros2软件包
说明:
- 介绍如何创建ros2软件包
步骤:
- 新建ros2包
cd ~/dev_ws/src
ros2 pkg create --build-type ament_python --node-name python_node python_package
- 效果如下:
~/dev_ws/src$ ros2 pkg create --build-type ament_python --node-name python_node python_package
going to create a new package
package name: python_package
destination directory: /home/ubuntu/dev_ws/src
package format: 3
version: 0.0.0
description: TODO: Package description
maintainer: ['ubuntu <ubuntu@todo.todo>']
licenses: ['TODO: License declaration']
build type: ament_python
dependencies: []
node_name: python_node
creating folder ./python_package
creating ./python_package/package.xml
creating source folder
creating folder ./python_package/python_package
creating ./python_package/setup.py
creating ./python_package/setup.cfg
creating folder ./python_package/resource
creating ./python_package/resource/python_package
creating ./python_package/python_package/__init__.py
creating folder ./python_package/test
creating ./python_package/test/test_copyright.py
creating ./python_package/test/test_flake8.py
creating ./python_package/test/test_pep257.py
creating ./python_package/python_package/python_node.py
- 包的目录结构
~/dev_ws/src/python_package$ tree
.
├── package.xml
├── python_package
│ ├── __init__.py
│ └── python_node.py
├── resource
│ └── python_package
├── setup.cfg
├── setup.py
└── test
├── test_copyright.py
├── test_flake8.py
└── test_pep257.py
3 directories, 9 files
- 编译包
cd ~/dev_ws/
colcon build --packages-select python_package
- 效果:
~/dev_ws$ colcon build --packages-select python_package
Starting >>> python_package
Finished <<< python_package [0.55s]
Summary: 1 package finished [0.75s]
- 运行
. install/setup.bash
ros2 run python_package python_node
- 效果如下:
~/dev_ws$ ros2 run python_package python_node
Hi from python_package.
获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号