< >
Home » ROS2入门教程 » ROS2入门教程-创建Action

ROS2入门教程-创建Action

说明:

  • 介绍如何在ROS2包中定义一个动作Action

步骤:

  • 创建新包
mkdir -p action_ws/src
cd action_ws/src
ros2 pkg create action_tutorials_interfaces
  • 在.action文件中,用以下形式定义Actions
# Request
---
# Result
---
# Feedback
  • 定义一个新Action “Fibonacci” 来计算斐波那契数列,创建新目录
cd action_tutorials_interfaces
mkdir action
  • 创建Fibonacci.action,包含以下内容
int32 order
---
int32[] sequence
---
int32[] partial_sequence
  • 在CMakeLists.txt,添加以下内容
find_package(rosidl_default_generators REQUIRED)

rosidl_generate_interfaces(${PROJECT_NAME}
  "action/Fibonacci.action"
)
  • 在package.xml,添加所需的依赖项
<buildtool_depend>rosidl_default_generators</buildtool_depend>

<depend>action_msgs</depend>

<member_of_group>rosidl_interface_packages</member_of_group>
  • 构建包
# Change to the root of the workspace
cd ~/action_ws
# Build
colcon build
  • 检查我们的操作是否成功构建
# Source our workspace
# On Windows: call install/setup.bat
. install/setup.bash
# Check that our action definition exists
ros2 interface show action_tutorials_interfaces/action/Fibonacci

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

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


标签: ros2入门教程