Skip to content

Commit a4b406b

Browse files
christophfroehlichhuemerj
authored andcommitted
Enable reloading BT xml file with same name (ros-navigation#4209) (ros-navigation#4422)
* Let BtActionServer overwrite xml * Make a ROS parameter for it * Rename flag to always reload BT xml file --------- Signed-off-by: Johannes Huemer <johannes.huemer@ait.ac.at> Signed-off-by: Christoph Froehlich <christoph.froehlich@ait.ac.at> Co-authored-by: Johannes Huemer <johannes.huemer@ait.ac.at>
1 parent 10ef868 commit a4b406b

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

nav2_behavior_tree/include/nav2_behavior_tree/bt_action_server.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,9 @@ class BtActionServer
245245
// The timeout value for waiting for a service to response
246246
std::chrono::milliseconds wait_for_service_timeout_;
247247

248+
// should the BT be reloaded even if the same xml filename is requested?
249+
bool always_reload_bt_xml_ = false;
250+
248251
// User-provided callbacks
249252
OnGoalReceivedCallback on_goal_received_callback_;
250253
OnLoopCallback on_loop_callback_;

nav2_behavior_tree/include/nav2_behavior_tree/bt_action_server_impl.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ BtActionServer<ActionT>::BtActionServer(
6161
if (!node->has_parameter("default_server_timeout")) {
6262
node->declare_parameter("default_server_timeout", 20);
6363
}
64+
if (!node->has_parameter("always_reload_bt_xml")) {
65+
node->declare_parameter("always_reload_bt_xml", false);
66+
}
6467
if (!node->has_parameter("wait_for_service_timeout")) {
6568
node->declare_parameter("wait_for_service_timeout", 1000);
6669
}
@@ -150,6 +153,7 @@ bool BtActionServer<ActionT>::on_configure()
150153
int wait_for_service_timeout;
151154
node->get_parameter("wait_for_service_timeout", wait_for_service_timeout);
152155
wait_for_service_timeout_ = std::chrono::milliseconds(wait_for_service_timeout);
156+
node->get_parameter("always_reload_bt_xml", always_reload_bt_xml_);
153157

154158
// Get error code id names to grab off of the blackboard
155159
error_code_names_ = node->get_parameter("error_code_names").as_string_array();
@@ -209,8 +213,8 @@ bool BtActionServer<ActionT>::loadBehaviorTree(const std::string & bt_xml_filena
209213
// Empty filename is default for backward compatibility
210214
auto filename = bt_xml_filename.empty() ? default_bt_xml_filename_ : bt_xml_filename;
211215

212-
// Use previous BT if it is the existing one
213-
if (current_bt_xml_filename_ == filename) {
216+
// Use previous BT if it is the existing one and always reload flag is not set to true
217+
if (!always_reload_bt_xml_ && current_bt_xml_filename_ == filename) {
214218
RCLCPP_DEBUG(logger_, "BT will not be reloaded as the given xml is already loaded");
215219
return true;
216220
}

0 commit comments

Comments
 (0)