1 #include <sarafun_tree/TreeRunner.h>
6 TreeRunner::TreeRunner(
int tick_period)
8 tick_period_ = tick_period;
12 root_ =
new SequenceNode(
"root");
15 bool TreeRunner::startTree(std::string tree_description_path)
17 ControlNode *tree_root;
20 ROS_WARN(
"startTree called with an active tree running. Will terminate active tree.");
28 tree_root =
dynamic_cast<ControlNode *
>(parser_->parseTree());
30 if (tree_root ==
nullptr)
35 root_->AddChild(tree_root);
37 if (draw_thread_ == 0)
39 ROS_DEBUG(
"Start drawing");
40 draw_thread_ =
new boost::thread(&drawTree, root_);
43 catch(BehaviorTreeException &Exception)
45 ROS_ERROR(
"%s", Exception.what());
49 tree_thread_ =
new boost::thread(Execute, root_, tick_period_);
55 void TreeRunner::stopTree()
59 if (tree_thread_ != 0)
61 if (tree_thread_->joinable())
63 ROS_INFO(
"Stopping a running behavior tree");
66 tree_thread_->interrupt();
70 catch (std::exception &e)
72 ROS_WARN(
"Exception when joining the tree thread: %s", e.what());
82 ROS_WARN(
"stopTree called with no tree to stop");