ROS笔记六(基于Python、Kinetic):自定义动作类型

本文是ROS笔记的第六篇,详细介绍了如何基于Python和Kinetic创建自定义动作类型。内容包括:创建动作源文件,更新构建系统以识别新动作,修改CMakeLists.txt文件参数,并最终进行编译。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前言:

同消息、服务类似,动作的定义包含三个部分:目标、结果、反馈。并且在编译过程中,会被打包为一个消息类型。

1.创建动作类型的源文件:

在my_code包下创建action目录,用于存放动作源文件。下面定义一个满足定时器需求的动作Timer.action:

# This is an action definition file, which has three parts: the goal, the
# result, and the feedback.
#
# Part 1: the goal, to be sent by the client
#
# The amount of time we want to wait
duration time_to_wait
---
# Part 2: the result, to be sent by the server upon completion
#
# How much time we waited
duration time_elapsed
# How many updates we provided along the way
uint32 updates_sent
---
# Part 3: the feedback, to be sent periodically by the server during
# execution.
#
# The amount of time that has elapsed from the start
duration time_elapsed
# The amount of time remaining until we're done
duration time_remaining

2.告知构建系统有新动作的定义:

<build_depend>actionlib</build_depend>
<build_depend>actionlib_msgs</build_depend>
<build_export_depend>actionlib</build_export_depend>
<build_export_depend>actionlib_msgs</build_export_depend>
<exec_depend>actionlib</exec_depend>
<exec_depend>actionlib_msgs</exec_depend>

3.修改CMakeLists.txt文件参数:

修改find_packag()函数:

 catkin_package()添加编译运行依赖:

 add_action_files()添加自定义服务源文件文件名: 

最后,generate_message()添加自定义服务所依赖的消息类型:

 4.编译 :

进入工作空间:

cd ~/catkin_ws

开始编译:

catkin_make

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值