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

前言:

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

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

猜你喜欢

转载自blog.csdn.net/java0fu/article/details/106147192