ROS2基本操作1
ROS2在Ubuntu中基本运行操作
- 一、环境
- 二、操作
- 1.创建工作空间
- 2.创建功能包
- 3.修改CMakeList文件
- 4.编译功能包
- 5.运行
- 三、ROS2部分指令
一、环境
系统:Ubuntu22.04
ROS2-humble
二、操作
1.创建工作空间
sudo mkdir -p /ws/src
2.创建功能包
先加入ros2的源
source /opt/ros/setup.bash %ros2的安装路径
创建功能包test_package
ros2 pkg create test_package --build-type ament_cmake --dependencies rclcpp
%以C++形式,以clcpp包为依赖创建功能包
3.修改CMakeList文件
在创建的功能包的目录下找到CMakeList.txt文件,并在其中添加依赖
4.编译功能包
退到工作区目录
cd /ws
编译
colcon build --packages-select test_package %可以colcon build编译整个工作区的所有
5.运行
先配置源
source ./install/setup.bash %工作区间里面会生成setup.bash
运行
ros2 run test_package name %name为定义在CMakeList中的发布者/订阅者名字
三、ROS2部分指令
ros2 interface list %展示ROS2接口
ros2 interface package $name %展示名字为name的包中的消息
ros2 interface show $name %展示名字为name的消息中的数据结构