Skip to content

Commit

Permalink
Enable reloading BT xml file with same name (ros-navigation#4209)
Browse files Browse the repository at this point in the history
* Let BtActionServer overwrite xml

Co-authored-by: Johannes Huemer <johannes.huemer@ait.ac.at>
Signed-off-by: Johannes Huemer <johannes.huemer@ait.ac.at>
Signed-off-by: Christoph Froehlich <christoph.froehlich@ait.ac.at>

* Make a ROS parameter for it

Signed-off-by: Christoph Froehlich <christoph.froehlich@ait.ac.at>

* Rename flag to always reload BT xml file

Signed-off-by: Johannes Huemer <johannes.huemer@ait.ac.at>

---------

Signed-off-by: Johannes Huemer <johannes.huemer@ait.ac.at>
Signed-off-by: Christoph Froehlich <christoph.froehlich@ait.ac.at>
Co-authored-by: Christoph Froehlich <christoph.froehlich@ait.ac.at>
  • Loading branch information
huemerj and christophfroehlich committed Jun 7, 2024
1 parent 3a2ef8b commit 41836ee
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,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 always_reload_bt_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 @@ -60,6 +60,9 @@ BtActionServer<ActionT>::BtActionServer(
if (!node->has_parameter("default_server_timeout")) {
node->declare_parameter("default_server_timeout", 20);
}
if (!node->has_parameter("always_reload_bt_xml")) {
node->declare_parameter("always_reload_bt_xml", false);
}
}

template<class ActionT>
Expand Down Expand Up @@ -116,6 +119,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("always_reload_bt_xml", always_reload_bt_xml_);

// Create the class that registers our custom nodes and executes the BT
bt_ = std::make_unique<nav2_behavior_tree::BehaviorTreeEngine>(plugin_lib_names_);
Expand Down Expand Up @@ -172,8 +176,8 @@ bool BtActionServer<ActionT>::loadBehaviorTree(const std::string & bt_xml_filena
// 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
if (current_bt_xml_filename_ == filename) {
// Use previous BT if it is the existing one and always reload flag is not set to true
if (!always_reload_bt_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 41836ee

Please sign in to comment.