< >
Home » ROS2入门教程 » ROS2入门教程-actions简介

ROS2入门教程-actions简介

ROS2入门教程-actions简介

说明:

  • 介绍ros2 actions(动作)

概念:

  • 动作是ROS 2中用于长时间运行任务的通信类型之一。
  • 它们由三部分组成:目标,结果和反馈。
  • 动作基于话题题和服务。
  • 它们的功能与服务相似,但动作是可抢占的(可以在执行时将其取消)。
  • 与返回单个响应的服务相反,它们还提供稳定的反馈。
  • 操作使用客户端-服务器模型,类似于发布者-订阅者模型(在主题教程中进行了描述)。
  • “动作客户端”节点将目标发送到“动作服务器”节点,该节点确认该目标并返回反馈和结果流。

请输入图片描述

  • 新开终端启动turtlesim :
ros2 run turtlesim turtlesim_node
  • 新开终端,启动键盘控制
ros2 run turtlesim turtle_teleop_key
  • G|B|V|C|D|E|R|T 实现旋转,按F键盘取消
  • 效果:
[INFO] [1595310037.225549705] [turtlesim]: Rotation goal completed successfully
[INFO] [1595310040.088940404] [turtlesim]: Rotation goal completed successfully
[INFO] [1595310085.881033542] [turtlesim]: Rotation goal canceled
[INFO] [1595310098.424963756] [turtlesim]: Rotation goal completed successfully
[INFO] [1595310112.329536575] [turtlesim]: Rotation goal completed successfully
  • 查看有哪些actions服务器
/turtlesim
  Subscribers:
    /parameter_events: rcl_interfaces/msg/ParameterEvent
    /turtle1/cmd_vel: geometry_msgs/msg/Twist
  Publishers:
    /parameter_events: rcl_interfaces/msg/ParameterEvent
    /rosout: rcl_interfaces/msg/Log
    /turtle1/color_sensor: turtlesim/msg/Color
    /turtle1/pose: turtlesim/msg/Pose
  Service Servers:
    /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
    /turtlesim/describe_parameters: rcl_interfaces/srv/DescribeParameters
    /turtlesim/get_parameter_types: rcl_interfaces/srv/GetParameterTypes
    /turtlesim/get_parameters: rcl_interfaces/srv/GetParameters
    /turtlesim/list_parameters: rcl_interfaces/srv/ListParameters
    /turtlesim/set_parameters: rcl_interfaces/srv/SetParameters
    /turtlesim/set_parameters_atomically: rcl_interfaces/srv/SetParametersAtomically
  Service Clients:

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

ros2 action list命令:

  • 查看action列表
$ ros2 action list
/turtle1/rotate_absolute
  • 查看列表,并显示动作类型
ros2 action list -t
/turtle1/rotate_absolute [turtlesim/action/RotateAbsolute]

ros2 action info命令:

  • 查看动作信息
  • 格式:ros2 action info /turtle1/rotate_absolute
  • 例子:
$ ros2 action info /turtle1/rotate_absolute
Action: /turtle1/rotate_absolute
Action clients: 1
    /teleop_turtle
Action servers: 1
    /turtlesim

ros2 interface show命令:

  • 查看动作消息接口定义
  • 格式:ros2 interface show turtlesim/action/RotateAbsolute.action
$ ros2 interface show turtlesim/action/RotateAbsolute.action
# 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

ros2 action send_goal命令:

  • 发送动作目标信息
  • 格式:ros2 action send_goal <action_name> <action_type>
  • 例子:
$ ros2 action send_goal /turtle1/rotate_absolute turtlesim/action/RotateAbsolute "{theta: 1.57}"
Waiting for an action server to become available...
Sending goal:
     theta: 1.57

Goal accepted with ID: a4907217d3e045bf8ba44f0a76b98a0f

Result:
    delta: 0.7680015563964844

Goal finished with status: SUCCEEDED
  • 例子2:
ros2 action send_goal /turtle1/rotate_absolute turtlesim/action/RotateAbsolute "{theta: 0}" --feedback
Waiting for an action server to become available...
Sending goal:
     theta: 0.0

Goal accepted with ID: 7574e756e4e54c9984c8f3814cc4d15f

Feedback:
    remaining: 1.5791785717010498

Feedback:
    remaining: 1.563178539276123

Feedback:
    remaining: 1.5471785068511963

Feedback:
    remaining: 1.5311784744262695

Feedback:
    remaining: 1.5151784420013428

Feedback:
    remaining: 1.499178409576416

Feedback:
    remaining: 1.4831783771514893

Feedback:
    remaining: 1.4671783447265625

Feedback:
    remaining: 1.4511783123016357

Feedback:
    remaining: 1.435178279876709

Feedback:
    remaining: 1.4191782474517822

Feedback:
    remaining: 1.4031782150268555

Feedback:
    remaining: 1.3871781826019287

Feedback:
    remaining: 1.371178150177002

Feedback:
    remaining: 1.3551781177520752

Feedback:
    remaining: 1.3391780853271484

Feedback:
    remaining: 1.3231780529022217

Feedback:
    remaining: 1.307178020477295

Feedback:
    remaining: 1.2911779880523682

Feedback:
    remaining: 1.2751779556274414

Feedback:
    remaining: 1.2591779232025146

Feedback:
    remaining: 1.243177890777588

Feedback:
    remaining: 1.2271778583526611

Feedback:
    remaining: 1.2111778259277344

Feedback:
    remaining: 1.1951777935028076

Feedback:
    remaining: 1.1791777610778809

Feedback:
    remaining: 1.163177728652954

Feedback:
    remaining: 1.1471776962280273

Feedback:
    remaining: 1.1311776638031006

Feedback:
    remaining: 1.1151776313781738

Feedback:
    remaining: 1.099177598953247

Feedback:
    remaining: 1.0831775665283203

Feedback:
    remaining: 1.0671775341033936

Feedback:
    remaining: 1.0511775016784668

Feedback:
    remaining: 1.03517746925354

Feedback:
    remaining: 1.0191774368286133

Feedback:
    remaining: 1.0031774044036865

Feedback:
    remaining: 0.9871774315834045

Feedback:
    remaining: 0.9711774587631226

Feedback:
    remaining: 0.9551774859428406

Feedback:
    remaining: 0.9391775131225586

Feedback:
    remaining: 0.9231775403022766

Feedback:
    remaining: 0.9071775674819946

Feedback:
    remaining: 0.8911775946617126

Feedback:
    remaining: 0.8751776218414307

Feedback:
    remaining: 0.8591776490211487

Feedback:
    remaining: 0.8431776762008667

Feedback:
    remaining: 0.8271777033805847

Feedback:
    remaining: 0.8111777305603027

Feedback:
    remaining: 0.7951777577400208

Feedback:
    remaining: 0.7791777849197388

Feedback:
    remaining: 0.7631778120994568

Feedback:
    remaining: 0.7471778392791748

Feedback:
    remaining: 0.7311778664588928

Feedback:
    remaining: 0.7151778936386108

Feedback:
    remaining: 0.6991779208183289

Feedback:
    remaining: 0.6831779479980469

Feedback:
    remaining: 0.6671779751777649

Feedback:
    remaining: 0.6511780023574829

Feedback:
    remaining: 0.6351780295372009

Feedback:
    remaining: 0.619178056716919

Feedback:
    remaining: 0.603178083896637

Feedback:
    remaining: 0.587178111076355

Feedback:
    remaining: 0.571178138256073

Feedback:
    remaining: 0.555178165435791

Feedback:
    remaining: 0.539178192615509

Feedback:
    remaining: 0.523178219795227

Feedback:
    remaining: 0.5071782469749451

Feedback:
    remaining: 0.4911782443523407

Feedback:
    remaining: 0.47517824172973633

Feedback:
    remaining: 0.45917823910713196

Feedback:
    remaining: 0.4431782364845276

Feedback:
    remaining: 0.4271782338619232

Feedback:
    remaining: 0.41117823123931885

Feedback:
    remaining: 0.3951782286167145

Feedback:
    remaining: 0.3791782259941101

Feedback:
    remaining: 0.36317822337150574

Feedback:
    remaining: 0.34717822074890137

Feedback:
    remaining: 0.331178218126297

Feedback:
    remaining: 0.3151782155036926

Feedback:
    remaining: 0.29917821288108826

Feedback:
    remaining: 0.2831782102584839

Feedback:
    remaining: 0.2671782076358795

Feedback:
    remaining: 0.25117820501327515

Feedback:
    remaining: 0.23517820239067078

Feedback:
    remaining: 0.2191781997680664

Feedback:
    remaining: 0.20317819714546204

Feedback:
    remaining: 0.18717819452285767

Feedback:
    remaining: 0.1711781919002533

Feedback:
    remaining: 0.15517818927764893

Feedback:
    remaining: 0.13917818665504456

Feedback:
    remaining: 0.12317818403244019

Feedback:
    remaining: 0.10717818140983582

Feedback:
    remaining: 0.09117817878723145

Feedback:
    remaining: 0.07517817616462708

Feedback:
    remaining: 0.059178177267313004

Feedback:
    remaining: 0.04317817836999893

Feedback:
    remaining: 0.02717817761003971

Feedback:
    remaining: 0.011178177781403065

Result:
    delta: -1.5680004358291626

Goal finished with status: SUCCEEDED
  • 显示每次的反馈

纠错,疑问,交流: 请进入讨论区点击加入Q群

获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号


标签: ros2入门教程