目标:在 ROS 2 包中定义一个动作。
教程级别:中级
时间:5 分钟
目录
背景
先决条件
任务
1. 创建一个接口包
2. 定义一个动作
3. 构建动作
摘要
下一步
相关内容
背景
您之前已经在了解动作教程中学习了有关动作的内容。就像其他通信类型及其各自的接口(主题/msg 和服务/srv)一样,您也可以在您的包中自定义动作。本教程将向您展示如何定义和构建一个动作,您可以在下一个教程中编写的动作服务器和动作客户端中使用它。
先决条件
您应该安装 ROS 2 和 colcon。
您应该知道如何设置工作区并创建包。
记得首先配置你的 ROS 2 安装环境。
任务
1. 创建一个接口包
mkdir -p ~/ros2_ws/src # you can reuse an existing workspace with this naming convention
cxy@ubuntu2404-cxy:~$ cd ~/ros2_ws/src
cxy@ubuntu2404-cxy:~/ros2_ws/src$ ros2 pkg create --license Apache-2.0 custom_action_interfaces
going to create a new package
package name: custom_action_interfaces
destination directory: /home/cxy/ros2_ws/src
package format: 3
version: 0.0.0
description: TODO: Package description
maintainer: ['cxy <cxy@todo.todo>']
licenses: ['Apache-2.0']
build type: ament_cmake
dependencies: []
creating folder ./custom_action_interfaces
creating ./custom_action_interfaces/package.xml
creating source and include folder
creating folder ./custom_action_interfaces/src
creating folder ./custom_action_interfaces/include/custom_action_interfaces
creating ./custom_action_interfaces/CMakeLists.txt
2.定义一个动作
行动定义在 .action
形式的文件中: