Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include <ros/ros.h>
00038 #include <actionlib/server/simple_action_server.h>
00039 #include <actionlib_tutorials/FibonacciAction.h>
00040
00041 class FibonacciAction
00042 {
00043 public:
00044
00045 FibonacciAction(std::string name) :
00046 as_(nh_, name, boost::bind(&FibonacciAction::executeCB, this, _1), false),
00047 action_name_(name)
00048 {
00049
00050 as_.start();
00051 }
00052
00053 ~FibonacciAction(void)
00054 {
00055 }
00056
00057 void executeCB(const actionlib_tutorials::FibonacciGoalConstPtr &goal)
00058 {
00059
00060 ros::Rate r(1);
00061 bool success = true;
00062
00063
00064 feedback_.sequence.clear();
00065 feedback_.sequence.push_back(0);
00066 feedback_.sequence.push_back(1);
00067
00068
00069 ROS_INFO("%s: Executing, creating fibonacci sequence of order %i with seeds %i, %i", action_name_.c_str(), goal->order, feedback_.sequence[0], feedback_.sequence[1]);
00070
00071
00072 for(int i=1; i<=goal->order; i++)
00073 {
00074
00075 if (as_.isPreemptRequested() || !ros::ok())
00076 {
00077 ROS_INFO("%s: Preempted", action_name_.c_str());
00078
00079 as_.setPreempted();
00080 success = false;
00081 break;
00082 }
00083 feedback_.sequence.push_back(feedback_.sequence[i] + feedback_.sequence[i-1]);
00084
00085 as_.publishFeedback(feedback_);
00086
00087 r.sleep();
00088 }
00089
00090 if(success)
00091 {
00092 result_.sequence = feedback_.sequence;
00093 ROS_INFO("%s: Succeeded", action_name_.c_str());
00094
00095 as_.setSucceeded(result_);
00096 }
00097 }
00098
00099 protected:
00100
00101 ros::NodeHandle nh_;
00102 actionlib::SimpleActionServer<actionlib_tutorials::FibonacciAction> as_;
00103 std::string action_name_;
00104
00105 actionlib_tutorials::FibonacciFeedback feedback_;
00106 actionlib_tutorials::FibonacciResult result_;
00107 };
00108
00109
00110 int main(int argc, char** argv)
00111 {
00112 ros::init(argc, argv, "fibonacci");
00113
00114 FibonacciAction fibonacci(ros::this_node::getName());
00115 ros::spin();
00116
00117 return 0;
00118 }