# 【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 测试所有节点的连接状态

```shell
rosnode ping --all
```

```shell
xu736946693@ubuntu:~/Desktop/ROS-exercise/src$ rosnode ping --all
Will ping the following nodes:
 * /server
 * /rosout

pinging /server with a timeout of 3.0s
xmlrpc reply from http://ubuntu:40279/  time=6.225109ms
pinging /rosout with a timeout of 3.0s
xmlrpc reply from http://ubuntu:39377/  time=5.535603ms
```

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

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

* 注意**斜杠**

### 1.2 rosnode list

```shell
rosnode list
```

* 列出活动节点列表

### 1.3 rosnode info

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

* 查看某个节点信息

```shell
xu736946693@ubuntu:~/Desktop/ROS-exercise/src$ rosnode info /server
--------------------------------------------------------------------------------
Node [/server]
Publications:
 * /rosout [rosgraph_msgs/Log]

Subscriptions: None

Services:
 * /AddInt
 * /server/get_loggers
 * /server/set_logger_level


contacting node http://ubuntu:40279/ ...
Pid: 3729
Connections:
 * topic: /rosout
    * to: /rosout
    * direction: outbound (59927 - 127.0.0.1:41752) [11]
    * transport: TCPROS
```

### 1.4 rosnode machine

#### 1.4.1 列出所有设备

```shell
rosnode machine
```

```shell
xu736946693@ubuntu:~/Desktop/ROS-exercise/src$ rosnode machine
ubuntu
```

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

```shell
rosnode machine <machine-name>
```

```shell
xu736946693@ubuntu:~/Desktop/ROS-exercise/src$ rosnode machine ubuntu
/rosout
/server
```

### 1.5 rosnode kill

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

```shell
rosnode kill --all
```

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

```shell
rosnode kill
```

```shell
xu736946693@ubuntu:~/Desktop/ROS-exercise/src$ rosnode kill
1. /rosout
2. /server

Please enter the number of the node you wish to kill.
> 2
killing /server
killed
```

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

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

### 1.6 rosnode cleanup

```shell
rosnode cleanup
```

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

## 2.rostopic

### 2.1 rostopic echo

```shell
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

```shell
rostopic list
```

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

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

### 2.3 rostopic info

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

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

### 2.4 rostopic type

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

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

### 2.5 rostopic find

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

* 根据消息类型寻找话题

### 2.6 rostopic bw

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

* 显示某个话题的带宽

### 2.7 rostopic delay

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

* 显示带有header的话题延迟

### 2.8 rostopic hz

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

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

## 3.rosmsg

### 3.1 rosmsg show

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

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

`-r`：Display the raw msg definition.

```shell
xu736946693@ubuntu:~/Desktop/ROS-exercise/src$ rosmsg show -r std_msgs/String
string data
```

### 3.2 rosmsg packages

```shell
rosmsg packages
```

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

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

### 3.3 rosmsg package

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

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

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

### 3.4 rosmsg users

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

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

## 4.rosservice

### 4.1 rosservice args

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

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

### 4.2 rosservice list

```shell
rosservice list
```

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

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

### 4.3 rosservice info

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

* 打印有关服务的信息

### 4.4 rosservice find

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

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

### 4.5 rosservice type

```shell
rosservice type <service-type>
```

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

## 5. rossrv

### 5.1 rossrv show

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

* 显示某个服务的定义

### 5.2 rossrv packages

```shell
rossrv packages
```

* 列出包含服务的所有包

### 5.3 rossrv package

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

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

## 6.rosparam

### 6.1 rosparam list

```shell
rosparam list
```

* 列出所有参数

### 6.2 rosparam set

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

* 设置参数

### 6.3 rosparam get

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

* 获取参数的值

### 6.4 rosparam delete

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

* 删除参数

### 6.5 rosparam load

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

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

### 6.6 rosparam dump

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

* 将参数写出到外部文件


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hanxu.gitbook.io/blogs/ros/ros-jiao-cheng-ros-chang-yong-ming-ling.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
