236 字
1 分钟
ros2——service 终端命令

Service 命令#

ros2 service -h
usage: ros2 service [-h] [--include-hidden-services]
Call `ros2 service <command> -h` for more detailed usage. ...
Various service related sub-commands
options:
-h, --help show this help message and exit
--include-hidden-services
Consider hidden services as well
Commands:
call Call a service
find Output a list of available services of a given type
list Output a list of available services
type Output a service's type

list 输出活动服务列表#

ros2 service list
ros2 service list -t

find 找出某种类型的服务#

ros2 service find <type_name>

示例:

ros2 service find std_srvs/srv/Empty
ros2 service find std_srvs/srv/Empty
/clear
/reset

type 输出服务的接口类型#

ros2 service type <service_name>

示例:

ros2 service type /clear
std_srvs/srv/Empty

call 调用服务#

ros2 service call -h
usage: ros2 service call [-h] [-r N]
service_name
service_type
[values]
Call a service
positional arguments:
values Values to fill the
service request with
in YAML format (e.g.
'{a: 1, b: 2}'),
otherwise the
service request will
be published with
default values
options:
-h, --help show this help
message and exit
-r N, --rate N Repeat the call at a
specific rate in Hz

示例:

/spawn [turtlesim/srv/Spawn]
ros2 interface show turtlesim/srv/Spawn
float32 x
float32 y
float32 theta
string name # Optional. A unique name will be created and returned if this is empty
---
string name
ros2 service call /spawn turtlesim/srv/Spawn "{x: 1.5, y: 2.6}"
ros2——service 终端命令
https://blog.wangmasterai.com/posts/ros2系列/服务-service/terminal/
作者
WangMaster
发布于
2026-09-26
许可协议
CC BY-NC-SA 4.0

分享文章

生成精美分享图或复制链接,与更多人分享本文。

继续阅读

沿着主题读

基于共同的标签与分类

换条路线

从其他文章中稳定抽取