# 【ROS教程】ROS常用命令

@[TOC](https://github.com/UnderTurrets/notes/blob/master/ROS/%E6%96%87%E7%AB%A0%E7%9B%AE%E5%BD%95/README.md)

***

## 1.rosnode

### 1.1 rosnode ping

#### 1.1.1 测试所有节点的连接状态

```powershell
rosnode ping --all
```

![在这里插入图片描述](https://cdn.jsdelivr.net/gh/UnderTurrets/ImageHosting/ROS/assets%E3%80%90ROS%E6%95%99%E7%A8%8B%E3%80%91ROS%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/bc9b6293a76e4a2198bda9a0fbdf96fb.png)

#### 1.1.2 测试到某个节点的连接状态

```powershell
rosnode ping /<node-name>
```

* 注意**斜杠**

### 1.2 rosnode list

```powershell
rosnode list
```

* 列出活动节点列表

### 1.3 rosnode info

```powershell
rosnode info /<node-name>
```

* 查看某个节点信息

![在这里插入图片描述](https://cdn.jsdelivr.net/gh/UnderTurrets/ImageHosting/ROS/assets%E3%80%90ROS%E6%95%99%E7%A8%8B%E3%80%91ROS%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/d2fd03dad3c5497dbcd64faf1a908150.png)

### 1.4 rosnode machine

#### 1.4.1 列出所有设备

```powershell
rosnode machine
```

![在这里插入图片描述](https://cdn.jsdelivr.net/gh/UnderTurrets/ImageHosting/ROS/assets%E3%80%90ROS%E6%95%99%E7%A8%8B%E3%80%91ROS%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/d72ee36a7bb34dd1bb18f530a51a8a4d.png)

#### 1.4.2 查看指定设备上的运行节点

```powershell
rosnode machine <machine-name>
```

![在这里插入图片描述](https://cdn.jsdelivr.net/gh/UnderTurrets/ImageHosting/ROS/assets%E3%80%90ROS%E6%95%99%E7%A8%8B%E3%80%91ROS%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/773356c279e748259045268fbde72cc1.png)

### 1.5 rosnode kill

#### 1.5.1 结束所有节点进程

```powershell
rosnode kill --all
```

#### 1.5.2 列出所有节点并选择要结束进程的那个节点

```powershell
rosnode kill
```

![在这里插入图片描述](https://cdn.jsdelivr.net/gh/UnderTurrets/ImageHosting/ROS/assets%E3%80%90ROS%E6%95%99%E7%A8%8B%E3%80%91ROS%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/be01e4a98c674eb1ada5003b0acc4e21.png)

#### 1.5.3 结束一个节点进程

```powershell
rosnode kill /<node-name>
```

### 1.6 rosnode cleanup

```powershell
rosnode cleanup
```

* 清理不可连接的节点进程

## 2.rostopic

### 2.1 rostopic echo

```powershell
rostopic echo /<topic-name>
```

* 监听某个话题的消息并显示
* 可选参数

`--offset`：Display time in messages as offset from current time (e.g. to calculate lag/latency). `-c`：Clear the screen after each message is published. Cannot be used with -p. `-b`：Display messages in a bag file:

### 2.2 rostopic list

```powershell
rostopic list
```

* 列出所有活动状态下的主题
* 可选参数：

`-b`：List topics in a bag file. `-p`：List only publishers. `-s`：List only subscribers.

### 2.3 rostopic info

```powershell
rostopic info /<topic-name>
```

* 列出某个话题的有关信息

### 2.4 rostopic type

```powershell
rostopic type /<topic-name>
```

* 列出某个话题所发布的消息类型

### 2.5 rostopic find

```powershell
rostopic find <package-name>/<message-name>
```

* 根据消息类型寻找话题

### 2.6 rostopic bw

```powershell
rostopic bw /<topic-name>
```

* 显示某个话题的带宽

### 2.7 rostopic delay

```powershell
rostopic delay /<topic-name>
```

* 显示带有header的话题延迟

### 2.8 rostopic hz

```powershell
rostopic hz /<topic-name>
```

* 显示某个话题的发布频率

## 3.rosmsg

### 3.1 rosmsg show

```powershell
rosmsg show /<message-type>
```

* 显示某个消息类型的定义
* 可选参数

`-r`：Display the raw msg definition.

![在这里插入图片描述](https://cdn.jsdelivr.net/gh/UnderTurrets/ImageHosting/ROS/assets%E3%80%90ROS%E6%95%99%E7%A8%8B%E3%80%91ROS%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/7d6d3d2ae33c49b6a62a7a97502d1ffb.png)

### 3.2 rosmsg packages

```powershell
rosmsg packages
```

* 列出包含消息的所有包
* 可选参数

`-s`：Display all packages on a single line. Useful for backtick invocations.

### 3.3 rosmsg package

```powershell
rosmsg package /<package-name>
```

* 列出某个包下的所有消息类型
* 可选参数

`-s`：Display all packages on a single line. Useful for backtick invocations.

### 3.4 rosmsg users

```powershell
rosmsg users /<message-type>
```

* 寻找所有使用了某个消息类型的源代码文件

## 4.rosservice

### 4.1 rosservice args

```powershell
rosservice args /<service-name>
```

* 显示某个服务中的请求的参数

### 4.2 rosservice list

```powershell
rosservice list
```

* 列出所有活动的服务
* 可选参数：

`-n`：Include the name of the node that implements the service.

### 4.3 rosservice info

```powershell
rosservice info <service-name>
```

* 打印有关服务的信息

### 4.4 rosservice find

```shell
rosservice find <package-name>/<service-type>
```

* 按照某个服务的类型去寻找包含此类型的服务的名称

### 4.5 rosservice type

```powershell
rosservice type <service-type>
```

* 根据服务的名称，给出服务的类型

## 5. rossrv

### 5.1 rossrv show

```powershell
rossrv show <package-name>/<service-name>
```

* 显示某个服务的定义

### 5.2 rossrv packages

```powershell
rossrv packages
```

* 列出包含服务的所有包

### 5.3 rossrv package

```powershell
rossrv package /<package-name>
```

* 列出某个包下的所有服务

## 6.rosparam

### 6.1 rosparam list

```powershell
rosparam list
```

* 列出所有参数

### 6.2 rosparam set

```powershell
rosparam set <parameter-name> [parameter-value]
```

* 设置参数

### 6.3 rosparam get

```powershell
rosparam get <parameter-name>
```

* 获取参数的值

### 6.4 rosparam delete

```powershell
rosparam delete <parameter-name>
```

* 删除参数

### 6.5 rosparam load

```powershell
rosparam load <yaml-file>
```

* 从外部文件加载参数，先准备yaml文件

### 6.6 rosparam dump

```powershell
rosparam dump <yaml-file>
```

* 将参数写出到外部文件
