ROS1 与 ROS2 使用区别 【命令】

ROS1 与 ROS2 使用区别

  • [1 介绍](#1 介绍)
  • [2 整体区别](#2 整体区别)
    • [2.1 目录结构](#2.1 目录结构)
    • [2.2 工作空间](#2.2 工作空间)
    • [2.3 依赖初始化](#2.3 依赖初始化)
    • [2.4 功能包](#2.4 功能包)
    • [2.5 运行](#2.5 运行)
    • [2.6 查看节点信息](#2.6 查看节点信息)
    • [2.7 查看话题](#2.7 查看话题)
    • [2.8 访问服务](#2.8 访问服务)
    • [2.9 调用动作](#2.9 调用动作)
    • [2.10 录包播包](#2.10 录包播包)
    • [2.11 rqt](#2.11 rqt)
    • [2.12 rviz](#2.12 rviz)
    • [2.13 parameters](#2.13 parameters)
    • [2.14 ROS Interface](#2.14 ROS Interface)
    • [2.15 ROS Launch](#2.15 ROS Launch)
  • [3 ROS2 命令树](#3 ROS2 命令树)
  • [4 细节区别](#4 细节区别)
    • [ros2 core](#ros2 core)
  • [5 其他](#5 其他)
  • 参考

1 介绍

2 整体区别

2.1 目录结构

目录 ROS1 ROS2
src/ 源代码目录 源代码目录
build/ 编译输出目录 编译输出目录
install/ 安装后的文件目录 安装后的文件目录
devel/ 开发环境相关文件目录
log/ 编译时的日志目录

2.2 工作空间

ROS (ROS 1) ROS2 描述
mkdir -p ~/catkin_ws/src cd ~/catkin_ws/src catkin_init_workspace - 初始化工作空间的代码目录
cd ~/catkin_ws cd ~/dev_ws 切换到工作空间目录
catkin_make colcon build 编译整个工作空间
source devel/setup.sh source install/local_setup.sh 使当前工作空间生效

2.3 依赖初始化

ROS (ROS 1) ROS2 rosdep ROS2 rosdepc 描述
sudo pip3 install rosdepc 安装rosdepc
sudo rosdep init sudo rosdep init sudo rosdepc init 初始化rosdep or rosdepc
rosdep update rosdep update rosdepc update 更新rosdep or rosdepc
cd ~/dev_ws cd ~/dev_ws 切换到工作空间目录
rosdep* install -i --from-path src --rosdistro humble -y rosdepc install -i --from-path src --rosdistro humble -y 使用rosdep or rosdepc 安装依赖
  • rosdep 与 rosdepc
    rosdepc,c指的是Chirna中国,主要用于和rosdep区分。rosdepc 是小鱼提供的? 只动了名称和源地址,将其地址修改为国内gitee地址。
    rosdepc 可能是为了解决国内用户在使用rosdep时可能遇到的网络问题而设计的。rosdepc使用了国内的源,这可能使得在国内使用时更加稳定和快速。

2.4 功能包

ROS (ROS 1) ROS2 描述
cd ~/catkin_ws cd ~/dev_ws/src 切换到工作空间目录
catkin_create_pkg <name> <dependencies> `ros2 pkg create --build-type [ament_cmake ament_python] <package_name>`
rospack list-names ros2 pkg list 列出可用的功能包
rospack list ros2 pkg executables 列出可执行的程序
rospack find <package> ros2 pkg prefix <package_name> 列出功能包路径
ros2 pkg xml 打印功能包的清单内容

2.5 运行

ROS (ROS 1) ROS2 描述
rosrun <package> <executable> <args> ros2 run <package_name> <executable_name> <argv> 运行节点或可执行文件

2.6 查看节点信息

ROS (ROS 1) ROS2 描述
rosnode list ros2 node list 列出当前所有节点
rosnode info <node> ros2 node info <node_name> 查看指定节点信息

2.7 查看话题

ROS (ROS 1) ROS2 描述
rostopic list ros2 topic list 列出所有话题
rostopic echo <topic_name> ros2 topic echo <topic_name> 打印指定话题
rostopic pub <topic_name> <message_type> <values> ros2 topic pub <topic_name> <message_type> <values> 发布话题
rostopic hz <topic_name> ros2 topic hz <topic_name> 查询话题的发布频率
rostopic type <topic_name> ros2 topic type <topic_name> 查看话题的类型
rostopic bw <topic> ros2 topic bw <topic> 查看话题的带宽

2.8 访问服务

ROS (ROS 1) ROS2 描述
rosservice list ros2 service list 列出所有服务
rosservice type <service_name> ros2 service type <service_name> 查看服务类型
rosservice find <service_type> ros2 service find <service_type> 查找指定类型的服务
rosservice call <service_name> <service_type> <values> ros2 service call <service_name> <service_type> <values> 调用服务

2.9 调用动作

ROS ROS2 描述
- ros2 action list 列出所有动作
- ros2 action info <action_name> 查看动作信息
- ros2 action send_goal <action_name> <action_type> <goal> 发送动作

2.10 录包播包

ROS (ROS 1) ROS2 描述
rosbag record <topics...> ros2 bag record <topics...> 录制话题
rosbag play <bag_path> ros2 bag play <bag_path> 播放
rosbag info <bag_path> ros2 bag info <bag_path> 查看bag包信息

2.11 rqt

ROS (ROS 1) ROS2 描述
rqt_graph rqt_graph 显示节点拓扑
rqt_console ros2 run rqt_console rqt_console 查看所有日志消息
rqt_plot rqt 二维数值绘图
rosrun rqt_reconfigure rqt_reconfigure rqt 参数动态配置

2.12 rviz

ROS (ROS 1) ROS2 描述
rosrun rviz rviz ros2 run rviz2 rviz2 启动rviz

2.13 parameters

param 参数是节点所需的配置设置,可以是整数,浮点数,布尔值,字符串或列表。在 ros2 中参数是基于 service 构建的。依旧用表格的方式描述 ROS1 和 ROS2 中参数设计的差异。注:ROS2 的参数是存储在节点中的,ROS1 的参数是存储在 ROS Master 中的,所有在使用的时候一般会有一个节点名称的差距。

命令 ROS1 ROS2 含义
delete rosparam delete /parameter_name ros2 param delete /node_name /parameter_name 删除参数
dump rosparam dump file [namespace] ros2 param dump /node_name 保存参数
get rosparam get /parameter_name ros2 param get /node_name /parameter_name 获取参数
list rosparam list ros2 param list [node_name] 查看参数列表
set rosparam set /parameter_name value ros2 param set /node_name /parameter_name value 设置参数

2.14 ROS Interface

interface 是 ROS2 中将 ROS1 中的 rosmsg 和 rossrv 命令合并以后的命令,使用起来更为统一且简洁。先看看 rosmsg 和 rossrv

  • rosmsg
shell 复制代码
$ rosmsg -v
rosmsg is a command-line tool for displaying information about ROS Message types.

Commands:
    rosmsg show    Show message description
    rosmsg info    Alias for rosmsg show
    rosmsg list    List all messages
    rosmsg md5    Display message md5sum
    rosmsg package    List messages in a package
    rosmsg packages    List packages that contain messages

Type rosmsg <command> -h for more detailed usage
  • rossrv
shell 复制代码
$ rossrv -h
rossrv is a command-line tool for displaying information about ROS Service types.

Commands:
    rossrv show    Show service description
    rossrv info    Alias for rossrv show
    rossrv list    List all services
    rossrv md5    Display service md5sum
    rossrv package    List services in a package
    rossrv packages    List packages that contain services

Type rossrv <command> -h for more detailed usage
  • ros2 interface
shell 复制代码
$ ros2 interface -h
usage: ros2 interface [-h] Call `ros2 interface <command> -h` for more detailed usage. ...

Show information about ROS interfaces

optional arguments:
  -h, --help            show this help message and exit

Commands:
  list      List all interface types available
  package   Output a list of available interface types within one package
  packages  Output a list of packages that provide interfaces
  proto     Output an interface prototype
  show      Output the interface definition

  Call `ros2 interface <command> -h` for more detailed usage.
  • 简单打印
shell 复制代码
rockchip@ubuntu:~$ ros2 interface show std_msgs/msg/Int8
# This was originally provided as an example message.
# It is deprecated as of Foxy
# It is recommended to create your own semantically meaningful message.
# However if you would like to continue using this please use the equivalent in example_msgs.

int8 data
rockchip@ubuntu:~$ ros2 interface show std_srvs/srv/Empty
---
rockchip@ubuntu:~$ ros2 interface show turtlesim/action/RotateAbsolute
# The desired heading in radians
float32 theta
---
# The angular displacement in radians to the starting position
float32 delta
---
# The remaining rotation in radians
float32 remaining

2.15 ROS Launch

在 ROS1 中 lauch 使用 xml 格式定义,使用的内容相对比较有限。然而在 ROS2 中 launch 重新设计,采用 Python 脚本的形式进行启动,大致模板可以使用如下:

shell 复制代码
from launch import LaunchDescription
from launch_ros.actions import Node


def generate_launch_description():
    return LaunchDescription([
        Node(
            package="turtlesim",
            executable="turtlesim_node",
            name="sim",
        )
    ])

LaunchDescription 中传入了一个 Node 的数组,Node代表了所有的节点信息。参数的含义和使用列举如下:

参数名称 含义 类型 举例
package 包名 str turtlesim
executable 可执行文件的名称 str turtlesim_node
name 节点名称 str sim
namespace 工作空间名称 str turtlesim1
parameters 参数列表 path 或 Map(key, value) {"background_r": 0}"./sim.yaml"
remappings 映射名称 tuple ('/turtlesim1/turtle1/pose', '/turtlesim1/turtle1/pose_remap')

假设我们将之前的模板内容写入到 turtlesim_start.launch.py 中,在加载 ros 环境后,只需执行如下命令即可运行 launch 文件

shell 复制代码
ros2 launch turtlesim_start.launch.py

终端大致打印内容如下:

shell 复制代码
[INFO] [launch]: All log files can be found below /Users/askeynil/.ros/log/2020-09-02-19-33-18-140633-AskeyNildeMacBook-Pro.local-22416
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [turtlesim_node-1]: process started with pid [22418]
[turtlesim_node-1] [INFO] [1599046399.308158593] [sim]: Starting turtlesim with node name /_ros2cli_daemon_1
[turtlesim_node-1] [INFO] [1599046399.342564206] [sim]: Spawning turtle [turtle1] at x=[5.544445], y=[5.544445], theta=[0.000000]

3 ROS2 命令树

shell 复制代码
ros2
├── action
│   ├── cancel         # 取消action
│   ├── send_goal      # 发送action目标
│   └── show           # 显示action信息
│
├── bag
│   ├── compress       # 压缩bag文件
│   ├── decompress     # 解压缩bag文件
│   ├── info           # 显示bag文件信息
│   ├── play           # 播放bag文件
│   ├── record         # 记录bag文件
│   └── replay         # 回放bag文件
│
├── component
│   ├── kill           # 杀死组件
│   ├── list           # 列出组件
│   ├── load           # 加载组件
│   ├── restart        # 重启组件
│   ├── set            # 设置组件参数
│   ├── status         # 显示组件状态
│   ├── unset          # 删除组件参数
│   └── info           # 显示组件信息
│
├── daemon
│   ├── start          # 启动daemon
│   ├── stop           # 停止daemon
│   ├── status         # 显示daemon状态
│   └── restart        # 重启daemon
│
├── doctor
│   ├── check          # 检查ROS 2诊断信息
│   └── info           # 显示ROS 2诊断信息
│
├── extension
│   ├── call           # 调用扩展功能
│   ├── list           # 列出扩展功能
│   ├── load           # 加载扩展功能
│   ├── show           # 显示扩展功能信息
│   └── unload         # 卸载扩展功能
│
├── interface
│   ├── list           # 列出接口
│   └── show           # 显示接口信息
│
├── lifecycle
│   ├── change_state   # 更改生命周期状态
│   ├── get_state      # 获取生命周期状态
│   └── set_state      # 设置生命周期状态
│
├── logging
│   ├── get_logger_level     # 获取logger级别
│   ├── set_level            # 设置logger级别
│   └── set_logger_level     # 设置logger级别
│
├── msg
│   └── show           # 显示消息定义
│
├── node
│   ├── cleanup        # 清理节点
│   ├── info           # 显示节点信息
│   ├── kill           # 杀死节点
│   ├── list           # 列出节点
│   ├── log            # 记录节点信息
│   ├── monitor        # 监控节点
│   ├── send_message   # 发送节点间消息
│   ├── set            # 设置节点参数
│   ├── unset          # 删除节点参数
│   └── wait           # 等待节点
│
├── param
│   ├── delete         # 删除参数
│   ├── describe       # 显示参数描述
│   ├── dump           # 导出参数
│   ├── get            # 获取参数
│   ├── list           # 列出参数
│   ├── load           # 导入参数
│   └── set            # 设置参数
│
├── qos
│   ├── get            # 获取QoS配置
│   └── set            # 设置QoS配置
│
├── run
│   ├── launch         # 运行launch文件
│   └── python         # 运行Python脚本
│
├── service
│   ├── call           # 调用服务
│   ├── find           # 查找服务
│   ├── info           # 显示服务信息
│   ├── list           # 列出服务
│   └── type           # 显示服务类型
│
├── srv
│   └── show           # 显示服务定义
│
├── topic
│   ├── bw             # 显示主题带宽
│   ├── echo           # 回显主题数据
│   ├── find           # 查找主题
│   ├── hz             # 显示主题频率
│   ├── info           # 显示主题信息
│   ├── list           # 列出主题
│   ├── pub            # 发布主题数据
│   ├── type           # 显示主题类型
│   └── relay          # 中继主题
│
├── type
│   ├── export         # 导出类型
│   ├── import         # 导入类型
│   ├── list           # 列出类型
│   └── show           # 显示类型定义
│
├── pkg
│   ├── create         # 创建package
│   ├── describe       # 显示package描述
│   ├── executables    # 列出可执行文件
│   ├── list           # 列出packages
│   ├── paths          # 显示package路径
│   ├── prefix         # 显示package前缀
│   └── xml            # 显示package XML
│
├── rosbag2_migration
│   ├── check          # 检查ROS 1 bag文件
│   ├── info           # 显示ROS 1 bag文件信息
│   ├── merge          # 合并ROS 1 bag文件
│   ├── migrate        # 迁移ROS 1 bag文件
│   └── split          # 分离ROS 1 bag文件
│
├── security
│   ├── create_key     # 创建密钥
│   ├── create_permission    # 创建权限
│   ├── grant_permission     # 授予权限
│   ├── info           # 显示安全信息
│   ├── revoke_permission    # 撤销权限
│   └── set_permission  # 设置权限
│
└── version             # 显示ROS 2版本信息

4 细节区别

ros2 core

在ROS1中,roscore是主节点。其他节点依赖于它。但在ROS2中,不再有"主节点"(和"从节点")。roscore退出了,取而代之的是DDS(Data Distribution Service)。

在ROS1中,roscore驱动的是客户端/服务器(或从节点/主节点)架构。对于ROS2,DDS驱动的是分布式架构。

  • ros2 humble
shell 复制代码
rockchip@ubuntu:~/ros2_humble$ roscore
-bash: roscore: command not found
rockchip@ubuntu:~/ros2_humble$ ros2core
-bash: ros2core: command not found
rockchip@ubuntu:~/ros2_humble$ ros2 core
usage: ros2 [-h] [--use-python-default-buffering] Call `ros2 <command> -h` for more detailed usage. ...
ros2: error: argument Call `ros2 <command> -h` for more detailed usage.: invalid choice: 'core' (choose from 'action', 'bag', 'component', 'daemon', 'doctor', 'extension_points', 'extensions', 'interface', 'launch', 'lifecycle', 'multicast', 'node', 'param', 'pkg', 'run', 'security', 'service', 'test', 'topic', 'trace', 'wtf')
rockchip@ubuntu:~/sen/ros2_humble$

5 其他

环境变量打印

shell 复制代码
printenv | grep -i ROS

参考

1、使用命令行工具进行内省

2、ROS2 Humble 学习【openEuler】

3、Where is roscore in ROS2?

4、ROS指令大全(含ROS1和ROS2)

5、ROS2常用指令学习笔记(适用于humble)

6、ROS2 CLI Tools

7、ROS2 与 ROS1命令行对比

8、ROS(机器人操作系统)底层原理及代码剖析

9、ROS机器人开发实践

10、理解ROS节点

11、机器人操作系统(ROS)浅析2015年.pdf

12、ROS学习4. ROS命令行工具

13、【学习笔记】ROS2纯小白 - Beginner:Client libraries(一):工作空间与包

相关推荐
InHand云飞小白41 分钟前
智能制造中的5G工业路由器应用实践:从痛点到方案
5g·机器人·智能路由器·制造·工业路由器·工业物联网·5g路由器
J_Xiong01171 小时前
【WAM篇】19:Dream2Flow——用现成视频模型“做梦“,把 3D 物体流变成开放世界的机器人指令
机器人·wam
J_Xiong01171 小时前
【WAM篇】16:3DFlowAction——把光流从平面提升到立体,用“3D 流世界模型“驱动跨本体操作
机器人·wam
J_Xiong01173 小时前
【WAM篇】01:UniPi——把“决策“变成“拍一段视频“的奠基之作
机器人·wam
视图猿人3 小时前
ROS2 JAZZY+Gazebo harmonic小车机器人建模、激光雷达使用、图像传感器使用、构建导航地图、SLAM自动导航仿真
c++·机器人
Axis tech4 小时前
Xsens如何融入机器人控制、训练工作流?
机器人
lqqjuly4 小时前
机器人状态估计与 SLAM—概率推理到 simultaneous Localization and Mapping
算法·机器人
物联通信量讯说4 小时前
物联网卡用于机器人 / 无人设备,企业应该怎么选?
物联网·机器人·无人机
物联网软硬件开发-轨物科技4 小时前
【轨物方案】告别人工运维痛点!光伏清洁检测一体化机器人,开启电站智能运维新时代
运维·机器人
J_Xiong01174 小时前
【WAM篇】15:Dreamitate——让“工具“当桥梁,把人类演示变成机器人动作
机器人·wam