2 #include <sarafun_tree/demo_bt_nodes/ApproachObjectsAction.h>
3 #include <sarafun_tree/demo_bt_nodes/GrabObjectAction.h>
4 #include <sarafun_tree/demo_bt_nodes/FoldingAssemblyAction.h>
5 #include <sarafun_tree/demo_bt_nodes/InsertionWithDeformationAction.h>
6 #include <sarafun_tree/demo_bt_nodes/PlaceAction.h>
7 #include <sarafun_tree/TreeRunner.h>
8 #include <sarafun_tree/LoadTree.h>
9 #include <std_srvs/Empty.h>
11 using namespace sarafun;
16 int TickPeriod_milliseconds = 0;
21 bool initializeTree(std::string tree_description_path)
27 runner =
new TreeRunner(TickPeriod_milliseconds);
30 if(runner->
startTree(tree_description_path))
33 ROS_INFO(
"Tree started successfully!");
39 ROS_ERROR(
"Tree failed to start!");
44 ROS_ERROR(
"Tree already initialized");
66 bool startTreeCallback(sarafun_tree::LoadTree::Request &req, sarafun_tree::LoadTree::Response &ans)
68 ans.success = initializeTree(req.file_path);
75 bool stopTreeCallback(std_srvs::Empty::Request &req, std_srvs::Empty::Response &ans)
79 ROS_ERROR(
"Called the service to stop tree without having started it");
83 ROS_INFO(
"Tree stopped successfully");
90 bool restartTreeCallback(sarafun_tree::LoadTree::Request &req, sarafun_tree::LoadTree::Response &ans)
94 ROS_ERROR(
"Called the service to stop tree without having started it");
100 ans.success = initializeTree(req.file_path);
105 int main(
int argc,
char **argv) {
106 ros::init(argc, argv,
"sarafun_bt_demo");
109 if (ros::param::has(
"/sarafun/bt/tick_period")){
110 ros::param::get(
"/sarafun/bt/tick_period", TickPeriod_milliseconds);
112 TickPeriod_milliseconds = 1000;
115 ros::ServiceServer bt_start_service = n.advertiseService(
"/sarafun/start_tree", startTreeCallback);
116 ros::ServiceServer bt_stop_service = n.advertiseService(
"/sarafun/stop_tree", stopTreeCallback);
117 ros::ServiceServer bt_restart_service = n.advertiseService(
"/sarafun/restart_tree", restartTreeCallback);
119 ROS_INFO(
"Started the sarafun tree node!");
bool startTree(std::string tree_description_path)