Skip to content

Commit 04082cc

Browse files
huemerjchristophfroehlich
authored andcommitted
Enable reloading BT xml file with same name (ros-navigation#4209)
* Let BtActionServer overwrite xml Co-authored-by: Johannes Huemer <[email protected]> Signed-off-by: Johannes Huemer <[email protected]> Signed-off-by: Christoph Froehlich <[email protected]> * Make a ROS parameter for it Signed-off-by: Christoph Froehlich <[email protected]> * Rename flag to always reload BT xml file Signed-off-by: Johannes Huemer <[email protected]> --------- Signed-off-by: Johannes Huemer <[email protected]> Signed-off-by: Christoph Froehlich <[email protected]> Co-authored-by: Christoph Froehlich <[email protected]> Signed-off-by: enricosutera <[email protected]>
1 parent 95082c0 commit 04082cc

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
@@ -251,6 +251,9 @@ class BtActionServer
251251
// The timeout value for waiting for a service to response
252252
std::chrono::milliseconds wait_for_service_timeout_;
253253

254+
// should the BT be reloaded even if the same xml filename is requested?
255+
bool always_reload_bt_xml_ = false;
256+
254257
// User-provided callbacks
255258
OnGoalReceivedCallback on_goal_received_callback_;
256259
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
@@ -64,6 +64,9 @@ BtActionServer<ActionT>::BtActionServer(
6464
if (!node->has_parameter("action_server_result_timeout")) {
6565
node->declare_parameter("action_server_result_timeout", 900.0);
6666
}
67+
if (!node->has_parameter("always_reload_bt_xml")) {
68+
node->declare_parameter("always_reload_bt_xml", false);
69+
}
6770
if (!node->has_parameter("wait_for_service_timeout")) {
6871
node->declare_parameter("wait_for_service_timeout", 1000);
6972
}
@@ -164,6 +167,7 @@ bool BtActionServer<ActionT>::on_configure()
164167
int wait_for_service_timeout;
165168
node->get_parameter("wait_for_service_timeout", wait_for_service_timeout);
166169
wait_for_service_timeout_ = std::chrono::milliseconds(wait_for_service_timeout);
170+
node->get_parameter("always_reload_bt_xml", always_reload_bt_xml_);
167171

168172
// Get error code id names to grab off of the blackboard
169173
error_code_names_ = node->get_parameter("error_code_names").as_string_array();
@@ -223,8 +227,8 @@ bool BtActionServer<ActionT>::loadBehaviorTree(const std::string & bt_xml_filena
223227
// Empty filename is default for backward compatibility
224228
auto filename = bt_xml_filename.empty() ? default_bt_xml_filename_ : bt_xml_filename;
225229

226-
// Use previous BT if it is the existing one
227-
if (current_bt_xml_filename_ == filename) {
230+
// Use previous BT if it is the existing one and always reload flag is not set to true
231+
if (!always_reload_bt_xml_ && current_bt_xml_filename_ == filename) {
228232
RCLCPP_DEBUG(logger_, "BT will not be reloaded as the given xml is already loaded");
229233
return true;
230234
}

0 commit comments

Comments
 (0)