Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include <ros/ros.h>
00014 #include <actionlib/server/simple_action_server.h>
00015 #include <behavior_tree_core/BTAction.h>
00016
00017 #include <string>
00018
00019 enum Status {RUNNING, SUCCESS, FAILURE};
00020
00021
00022 class BTAction
00023 {
00024 protected:
00025 ros::NodeHandle nh_;
00026
00027 actionlib::SimpleActionServer<behavior_tree_core::BTAction> as_;
00028 std::string action_name_;
00029
00030 behavior_tree_core::BTFeedback feedback_;
00031 behavior_tree_core::BTResult result_;
00032
00033 public:
00034 explicit BTAction(std::string name) :
00035 as_(nh_, name, boost::bind(&BTAction::execute_callback, this, _1), false),
00036 action_name_(name)
00037 {
00038
00039 as_.start();
00040 ROS_INFO("Condition Server Started");
00041 }
00042
00043 ~BTAction(void)
00044 { }
00045 void execute_callback(const behavior_tree_core::BTGoalConstPtr &goal)
00046 {
00047 if (true)
00048 {
00049 set_status(SUCCESS);
00050 }
00051 else
00052 {
00053 set_status(FAILURE);
00054 }
00055 }
00056
00057
00058 void set_status(int status)
00059 {
00060
00061 feedback_.status = status;
00062 result_.status = feedback_.status;
00063
00064 as_.publishFeedback(feedback_);
00065
00066 as_.setSucceeded(result_);
00067
00068 switch (status)
00069 {
00070 case SUCCESS:
00071 ROS_INFO("Condition %s Succeeded", ros::this_node::getName().c_str() );
00072 break;
00073 case FAILURE:
00074 ROS_INFO("Condition %s Failed", ros::this_node::getName().c_str() );
00075 break;
00076 default:
00077 break;
00078 }
00079 }
00080 };
00081
00082 int main(int argc, char** argv)
00083 {
00084 ros::init(argc, argv, "condition");
00085 ROS_INFO(" Enum: %d", RUNNING);
00086 ROS_INFO(" condition Ready for Ticks");
00087 BTAction bt_action(ros::this_node::getName());
00088 ros::spin();
00089 return 0;
00090 }