这两天学习ROS的ationlib机制,弄了一个demo作为笔记。
在demo中,action的目标是读书。client向server发送要读多少页书(goal);server收到目标后开始执行任务,且向client反馈已经读到了第几页(feedback),并在完成读书任务后告知client;客户端得知server完成任务后,使用ros::shutdown()函数关闭自身节点。
参考了大神的博客:http://www.guyuehome.com/908
一、创建一个package
$ catkin_create_pkg actionlib_demoactionlib actionlib_msgs roscpp
$ cd actionlib_demo/
二、和msg、srv一样,actionlib需要创建action文件
$ mkdir action
$ cd action/
$ vim ReadBook.action
# Define the goal
uint32 total_pages
---
# Define the result
bool is_finish
---
# Define a feedback message
uint32 reading_page
三、编辑CMakelist.txt文件,添加action的编译规则
如下地方:
## Generate actions in the 'action' folder
# add_action_files(
# FILES
# Action1.action
# Action2.action
# )
## Generate added messages and services with any dependencies listed here
# generate_messages(
# DEPENDENCIES
# std_msgs
# )
修改为:
## Generate actions in the 'action' folder
add_