ROS2-Beginner:7-理解行为

背景

行为ROS2中的一种通信类型,用于长时间的运行任务。由三个部分组成:目标,反馈以及结果。

行为建立在话题和服务之上的。他们的功能类似于服务,但可以取消操作。他们还提供了稳定的反馈,而不是返回单一的响应的服务。

行为使用了一个客户端-服务器模型,类似于发布者和订阅者。一个行为客户端节点发送一个目标给到一个行为服务器节点,服务器节点会告知收到目标并返回一些反馈以及结果。

 任务

1、打开turtlesim_node

ros2 run turtlesim turtlesim_node

ros2 run turtlesim turtle_teleop_key

2、ros2 node info

查看节点的信息

ros2 node info /turtlesim

/turtlesim的action /turtle1/rotate_absolute是在Action Servers下。

节点/teteop_turtle有action名字/turtle1/rotate_absolute在Action Clents,它发送目标到该action名字上,运行如下,查看

/teleop_turtle
  Subscribers:
    /parameter_events: rcl_interfaces/msg/ParameterEvent
  Publishers:
    /parameter_events: rcl_interfaces/msg/ParameterEvent
    /rosout: rcl_interfaces/msg/Log
    /turtle1/cmd_vel: geometry_msgs/msg/Twist
  Service Servers:
    /teleop_turtle/describe_parameters: rcl_interfaces/srv/DescribeParameters
    /teleop_turtle/get_parameter_types: rcl_interfaces/srv/GetParameterTypes
    /teleop_turtle/get_parameters: rcl_interfaces/srv/GetParameters
    /teleop_turtle/list_parameters: rcl_interfaces/srv/ListParameters
    /teleop_turtle/set_parameters: rcl_interfaces/srv/SetParameters
    /teleop_turtle/set_parameters_atomically: rcl_interfaces/srv/SetParametersAtomically
  Service Clients:

  Action Servers:

  Action Clients:
    /turtle1/rotate_absolute: turtlesim/action/RotateAbsolute

4 ros2 action list

查看ros graph中的所有action,运行如下命令:

ros2 action list

会返回如下:

4.1 ros2 action list -t

查看具体action的类型

5、ros2 action info

查看具体action的客户端和服务端

节点/teleop_turtle有一个action的客户端;

节点/turtlesim有一个action的服务器

6、ros2 interface show

在自己发送或执行行动目标之前,还需要一条信息,那就是行动类型的结构。

查看action的细节

ros2 interface show turtlesim/action/RotateAbsolute

第一个theta为目标goal;第二个delta为:结果;第三个remaining为反馈;

7、ros2 action send_goal

从命令行中发送一个goal

ros2 action send_goal <action_name> <action_type> <values>

<values>需要yaml的格式

ros2 action send_goal /turtle1/rotate_absolute turtlesim/action/RotateAbsolute "{theta: 1.57}"

所有的goal有一个唯一的ID,如上所示,看到result,有一个域名字为delta,它是离起始位置的位移。

为了看发送目标的反馈,添加--feedback到命令ros2 action send_goal:

ros2 action send_goal /turtle1/rotate_absolute turtlesim/action/RotateAbsolute "{theta: -1.57}" --feedback

 

 

总结

操作类似于允许您执行长时间运行的任务、提供定期反馈并且可以取消的服务。

机器人系统可能会使用动作进行导航。一个动作目标可以告诉机器人移动到一个位置。当机器人导航到该位置时,它可以沿途发送更新(即反馈),然后在到达目的地后发送最终结果消息。

 

posted on 2023-06-01 18:05  gary_123  阅读(56)  评论(0)    收藏  举报

导航