Skip to content

Commit

Permalink
Make a ROS parameter for it
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Huemer <johannes.huemer@ait.ac.at>
  • Loading branch information
christophfroehlich authored and huemerj committed Mar 24, 2024
1 parent 79e2af6 commit 1d65af7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,10 @@ class BtActionServer
/**
* @brief Replace current BT with another one
* @param bt_xml_filename The file containing the new BT, uses default filename if empty
* @param overwrite If true, the new BT will be reloaded even if the filename is the same
* @return bool true if the resulting BT correspond to the one in bt_xml_filename. false
* if something went wrong, and previous BT is maintained
*/
bool loadBehaviorTree(const std::string & bt_xml_filename = "", bool overwrite = false);
bool loadBehaviorTree(const std::string & bt_xml_filename = "");

/**
* @brief Getter function for BT Blackboard
Expand Down Expand Up @@ -252,6 +251,9 @@ class BtActionServer
// The timeout value for waiting for a service to response
std::chrono::milliseconds wait_for_service_timeout_;

// should the BT be reloaded even if the same xml filename is requested?
bool overwrite_xml_ = false;

// User-provided callbacks
OnGoalReceivedCallback on_goal_received_callback_;
OnLoopCallback on_loop_callback_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ BtActionServer<ActionT>::BtActionServer(
if (!node->has_parameter("action_server_result_timeout")) {
node->declare_parameter("action_server_result_timeout", 900.0);
}
if (!node->has_parameter("overwrite_xml")) {
node->declare_parameter("overwrite_xml", false);
}

std::vector<std::string> error_code_names = {
"follow_path_error_code",
Expand Down Expand Up @@ -161,6 +164,7 @@ bool BtActionServer<ActionT>::on_configure()
int wait_for_service_timeout;
node->get_parameter("wait_for_service_timeout", wait_for_service_timeout);
wait_for_service_timeout_ = std::chrono::milliseconds(wait_for_service_timeout);
node->get_parameter("overwrite_xml", overwrite_xml_);

// Get error code id names to grab off of the blackboard
error_code_names_ = node->get_parameter("error_code_names").as_string_array();
Expand Down Expand Up @@ -215,13 +219,13 @@ bool BtActionServer<ActionT>::on_cleanup()
}

template<class ActionT>
bool BtActionServer<ActionT>::loadBehaviorTree(const std::string & bt_xml_filename, bool overwrite)
bool BtActionServer<ActionT>::loadBehaviorTree(const std::string & bt_xml_filename)
{
// Empty filename is default for backward compatibility
auto filename = bt_xml_filename.empty() ? default_bt_xml_filename_ : bt_xml_filename;

// Use previous BT if it is the existing one and overwrite flag is not set to true
if (!overwrite && current_bt_xml_filename_ == filename) {
if (!overwrite_xml_ && current_bt_xml_filename_ == filename) {
RCLCPP_DEBUG(logger_, "BT will not be reloaded as the given xml is already loaded");
return true;
}
Expand Down

0 comments on commit 1d65af7

Please sign in to comment.