当前位置:网站首页>ROS2 series of knowledge (4): understand the concept of [service]
ROS2 series of knowledge (4): understand the concept of [service]
2022-08-01 01:07:00 【Mr. Anhui】
Humble Hawksbill (humble) — ROS 2 Documentation: Humble documentation
前言
ROS2There are nine basic concept,分别是:Node、topic、service、actions、rqt、launch、record-play、backdata、parameter;本文着重讲述service概念.
一、背景知识
服务是 ROS Another way of communication nodes in the graph.服务基于调用和响应模型,而不是主题的发布者-订阅者模型.Although the theme allows nodes to subscribe to the data flow and continuously updated,But the service only in special call them when the client provides the data.也就是说,If the service is similar to the theme,Will be running on empty most of the time,浪费资源.
二、开启 演示方式
启动两个 turtlesim 节点,/turtlesim 和 /teleop_turtle.
打开一个新终端并运行:
ros2 run turtlesim turtlesim_node
打开另一个终端并运行:
ros2 run turtlesim turtle_teleop_key
三、According to the service item
打开一个终端,执行:
ros2 service list
会显示:
You will see the two nodes have the same six service,With parameters in name.几乎 ROS 2 Each node has the infrastructure of service,These infrastructure services are based on these services.The next tutorial has more about the content of the parameter.在本教程中,Services will be omitted parameters.
现在,Let's focus on specific turtlesim 的服务,
- /clear、
- /kill、
- /reset、
- /spawn、
- /turtle1/set_pen、
- /turtle1/teleport_absolute 和
- /turtle1/teleport_relative.
You may recall in the use of turtlesim 和 rqt 教程中使用 rqt And some of these services interact.
四、服务的种类
Services have describe the structure of the service request and response data types.The definition of service type is similar to the topic type,In addition to the service type has two parts:A message for the request,One for the response.
To find out the type of service,请使用以下命令:
ros2 service type <service_name>
我们来看看turtlesim的/clear服务.在新终端中,输入命令:
ros2 service type /clear
将返回:
std_srvs/srv/Empty
Empty Type said service call when making a request not to send data,When the response is received not receive data.
五、See all accessible services
To view all the type of activity service,可以在 list 命令后附加 --show-types 选项,缩写为 -t:
ros2 service list -t
返回结果
/clear [std_srvs/srv/Empty]
/kill [turtlesim/srv/Kill]
/reset [std_srvs/srv/Empty]
/spawn [turtlesim/srv/Spawn]
...
/turtle1/set_pen [turtlesim/srv/SetPen]
/turtle1/teleport_absolute [turtlesim/srv/TeleportAbsolute]
/turtle1/teleport_relative [turtlesim/srv/TeleportRelative]
...
六、ros2 服务查找
If you want to find a particular type of all services,可以使用命令:
ros2 service find <type_name>
例如,You can find all like this Empty 类型的服务:
ros2 service find std_srvs/srv/Empty
Which will return:
/clear
/reset
七、ros2界面展示
You can from the command line to invoke the service,But first you need to know the structure of the input parameters.
ros2 interface show <type_name>
要在 /clear Run this command in the type of service,请为 Empty:
ros2 interface show std_srvs/srv/Empty
会返回:
---
这里【---】Will request structure(上)With the response structure(下)分开.但是,As you know before,Empty Type does not send or receive any data.所以,很自然,It is the structure of the blank.
Let us use a send and receive data types to introspect a service,比如 /spawn.从 ros2 service list -t 的结果,我们知道 /spawn 的类型是 turtlesim/srv/Spawn.
要查看 /spawn Call and request the parameters in the,请运行以下命令:
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
--- Line at the top of the information to tell us call /spawn 所需的参数. x、y 和 theta Determine the location of the generated a turtle,The name is obviously optional.
在这种情况下,You don't need to know the bank information below,But it can help you understand the response data types from call.
八 ros2 服务调用
Now that you know what is the service type、How to find the service type and how to find the structure of the type parameter,You can use the following ways to invoke the service:
ros2 service call <service_name> <service_type> <arguments>
<arguments> 部分是可选的.例如,You know that empty type service without any parameters:
ros2 service find std_srvs/srv/Empty
This command will remove the turtles to draw any line of turtles simulation window.
Let us now by calling /spawn And the input parameters to generate a new turtle.Input in the command line service call <arguments> 需要采用 YAML 语法. 输入命令:
ros2 service call /spawn turtlesim/srv/Spawn "{x: 2, y: 2, theta: 0.2, name: ''}"
You will get what is happening this method style view,Then the service response:
requester: making request: turtlesim.srv.Spawn_Request(x=2.0, y=2.0, theta=0.2, name='')
response:
turtlesim.srv.Spawn_Response(name='turtle2')
您的 turtlesim Window will be updated immediately newly generated a turtle:
九 总结
节点可以使用 ROS 2 中的服务进行通信.与主题不同 - A one-way communication mode,Node released for use with one or more subscriber information - Service is the request of the client request to the node/Response model to provide service,Service process requests and generate a response.
You usually don't want to use the service to continuous call;Theme or action will be more suitable.
Understanding services — ROS 2 Documentation: Humble documentation
边栏推荐
猜你喜欢
2022年最新重庆建筑八大员(电气施工员)模拟题库及答案
Key Points Estimation and Point Instance
One line of code to solve CoreData managed object properties change in SwiftUI problem of animation effects
Redis五种数据类型简介
pycaret源码分析:下载数据集\Lib\site-packages\pycaret\datasets.py
欧拉系统(euleros):升级Mysql
Carefully summarize thirteen suggestions to help you create more suitable MySQL indexes
Kyoto University:Masaki Waga | 黑箱环境中强化学习的动态屏蔽
zeno使用方法笔记
RTL8762DK RTC(五)
随机推荐
500 miles
[微服务]分布式事务解决方案-Seata
MYSQL-批量插入数据
LeetCode每日一练 —— 环形链表问题(面试四连问)
Named Entity Recognition - Model: BERT-MRC
SC7A20 (Silan Micro-Accelerometer) Example
MYSQL逻辑架构
MYSQL查询截取优化分析
MYSQL事务
Pylint检查规则中文版
你需要知道的 TCP 四次挥手
RTL8762DK WDG(六)
类和对象:中
sqlserver无法远程连接
GDB source code analysis series of articles five: dynamic library delay breakpoint implementation mechanism
ROS2系列知识(4): 理解【服务】的概念
Force buckle 2326, 197
Keil nRF52832下载失败
OSD读取SAP CRM One Order应用日志的优化方式
Carefully summarize thirteen suggestions to help you create more suitable MySQL indexes