diff --git a/include/iri_base_bt_client/iri_base_bt_client.h b/include/iri_base_bt_client/iri_base_bt_client.h index caba2ee069c509b785f0db1ebaa0393c6779dcf4..4b6082d96fcf743a285414f8c0c78f869a3c051b 100644 --- a/include/iri_base_bt_client/iri_base_bt_client.h +++ b/include/iri_base_bt_client/iri_base_bt_client.h @@ -476,7 +476,12 @@ template <class ConfigClass> void IriBaseBTClient<ConfigClass>::enable_cout_logger() { if(this->logger_cout==NULL) - this->logger_cout=new BT::StdCoutLogger(this->tree); + { + if (this->tree.rootNode() != nullptr) + this->logger_cout=new BT::StdCoutLogger(this->tree); + else + ROS_WARN("IriBaseBTClient::enable_cout_logger -> BehaviorTree not initialized. Disable and re-enable BT cout logger if not working."); + } } template <class ConfigClass> @@ -504,7 +509,12 @@ void IriBaseBTClient<ConfigClass>::enable_minitrace_logger() path_ok=true; if(path_ok) - this->logger_minitrace=new BT::MinitraceLogger(this->tree, (this->path + "/logs/" + this->tree_xml_file + ".json").c_str()); + { + if (this->tree.rootNode() != nullptr) + this->logger_minitrace=new BT::MinitraceLogger(this->tree, (this->path + "/logs/" + this->tree_xml_file + ".json").c_str()); + else + ROS_WARN("IriBaseBTClient::enable_minitrace_logger -> BehaviorTree not initialized. Disable and re-enable BT minitrace logger if not working."); + } else ROS_ERROR("IriBaseBTClient: MinitraceLogger couldn't be enabled"); } @@ -535,7 +545,12 @@ void IriBaseBTClient<ConfigClass>::enable_file_logger() path_ok=true; if(path_ok) - this->logger_file=new BT::FileLogger(this->tree, (this->path + "/logs/" + this->tree_xml_file + ".fbl").c_str()); + { + if (this->tree.rootNode() != nullptr) + this->logger_file=new BT::FileLogger(this->tree, (this->path + "/logs/" + this->tree_xml_file + ".fbl").c_str()); + else + ROS_WARN("IriBaseBTClient::enable_file_logger -> BehaviorTree not initialized. Disable and re-enable BT file logger if not working."); + } else ROS_ERROR("IriBaseBTClient: Filelogger couldn't be enabled"); } @@ -545,7 +560,12 @@ template <class ConfigClass> void IriBaseBTClient<ConfigClass>::enable_zmq_publisher() { if(this->publisher_zmq==NULL) - this->publisher_zmq=new BT::PublisherZMQ(this->tree); + { + if (this->tree.rootNode() != nullptr) + this->publisher_zmq=new BT::PublisherZMQ(this->tree); + else + ROS_WARN("IriBaseBTClient::enable_zmq_publisher -> BehaviorTree not initialized. Disable and re-enable BT ZMQ logger if not working."); + } } template <class ConfigClass>