也是节点node之间的一种通讯方式
每个节点自己实现了action 客户端 或服务端。
客户端发起请求,action(后台中心)转发给 服务端节点
服务端node处理、执行action动作
客户端节点发起请求(询问动作执行的结果)
服务端node 响应请求 分两步
- (1.通过topic 持续返回当前执行的状态
- 2.动作执行结束了, 返回服务的响应报文。)
和服务的区别:
- 可以抢占
- 稳定周期反馈, 过程的结果(进度)。服务只有一个反馈
Actions are built on topics and services. Their functionality is similar to services, except actions are preemptable 抢占(you can cancel them while executing). They also provide steady feedback, (稳定的反馈,而服务,只返回一个结果)as opposed to services which return a single response.
可以看到下图: 开始action(服务通讯), 请求结果(服务通讯), feedback( topic通讯)
Actions are like services that allow you to execute long running tasks, provide regular feedback, and are cancelable.
行动通讯,和服务通讯一样,可以执行 耗时间的任务,周期的提供反馈结果。同时任务可以取消。
A robot system would likely use actions for navigation. An action goal could tell a robot to travel to a position. While the robot navigates to the position, it can send updates along the way (i.e. feedback), and then a final result message once it’s reached its destination.
很自然,行动通讯,可以用在机器人导航、轨迹跟踪!。设定一个target的, 一路tracking过去。期间返回当前状态变量。
常用命令:
ros2 action list -t
/turtle1/rotate_absolute [turtlesim/action/RotateAbsolute]
前面是action name , 后面是action type的内容
ros2 action info <action name xx> (查看action 是谁是客户端,谁是服务端)
Action: /turtle1/rotate_absolute action name
Action clients: 1
/teleop_turtle
Action servers: 1
/turtlesim
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 (这个是topic : feedback)
ros2 action send_goal <action_name> <action_type> <values>
<values>
need to be in YAML format.
ros2 action send_goal /turtle1/rotate_absolute turtlesim/action/RotateAbsolute "{theta: 1.57}"
看一下rqt_graph, action request 没显示,因为,之前请求了action goal
归纳:
ros2 topic pub <node name> <message> <value>
ros2 service call <service name> <servie type >< value>
ros2 action send_goal <action name> <action type> <value>
至此, ROS 核心的概念,就这么多。