Skip to content

Commit 517ebf4

Browse files
Changing BT loading warning to be more clear (#5938)
* Changing BT loading warning to be more clear Signed-off-by: SteveMacenski <stevenmacenski@gmail.com> * Comment out ros2/rviz repository Comment out the ros2/rviz repository entry in underlay.repos Signed-off-by: Steve Macenski <stevenmacenski@gmail.com> --------- Signed-off-by: SteveMacenski <stevenmacenski@gmail.com> Signed-off-by: Steve Macenski <stevenmacenski@gmail.com>
1 parent 3eba44b commit 517ebf4

File tree

3 files changed

+50
-17
lines changed

3 files changed

+50
-17
lines changed

nav2_behavior_tree/include/nav2_behavior_tree/bt_action_server_impl.hpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ bool BtActionServer<ActionT, NodeT>::loadBehaviorTree(const std::string & bt_xml
261261
}
262262

263263
std::set<std::string> registered_ids;
264+
std::vector<std::string> conflicting_files;
264265
std::string main_id;
265266
auto register_all_bt_files = [&](const std::string & skip_file = "") {
266267
for (const auto & directory : search_directories_) {
@@ -278,9 +279,7 @@ bool BtActionServer<ActionT, NodeT>::loadBehaviorTree(const std::string & bt_xml
278279
continue;
279280
}
280281
if (registered_ids.count(id)) {
281-
RCLCPP_WARN(
282-
logger_, "Skipping conflicting BT file %s (duplicate ID %s)",
283-
entry.path().c_str(), id.c_str());
282+
conflicting_files.push_back(entry.path().string());
284283
continue;
285284
}
286285

@@ -318,6 +317,23 @@ bool BtActionServer<ActionT, NodeT>::loadBehaviorTree(const std::string & bt_xml
318317
main_id = file_or_id;
319318
register_all_bt_files();
320319
}
320+
321+
// Log all conflicting files once at the end
322+
if (!conflicting_files.empty()) {
323+
std::string files_list;
324+
for (const auto & file : conflicting_files) {
325+
if (!files_list.empty()) {
326+
files_list += ", ";
327+
}
328+
files_list += file;
329+
}
330+
RCLCPP_WARN(
331+
logger_,
332+
"Skipping conflicting BT XML files, multiple files have the same ID. "
333+
"Please set unique behavior tree IDs. This may affect loading of subtrees. "
334+
"Files not loaded: %s",
335+
files_list.c_str());
336+
}
321337
} catch (const std::exception & e) {
322338
setInternalError(
323339
ActionT::Result::FAILED_TO_LOAD_BEHAVIOR_TREE,

nav2_system_tests/src/behavior_tree/test_behavior_tree_node.cpp

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ class BehaviorTreeHandler
119119
kXmlExtension.size(), kXmlExtension) != 0);
120120

121121
std::set<std::string> registered_ids;
122+
std::vector<std::string> conflicting_files;
122123
std::string main_id;
123124

124125
auto register_all_bt_files = [&](const std::string & skip_file = "") {
@@ -137,8 +138,7 @@ class BehaviorTreeHandler
137138
continue;
138139
}
139140
if (registered_ids.count(id)) {
140-
std::cerr << "Skipping conflicting BT file " << entry.path() << " (duplicate ID " <<
141-
id << ")" << "\n";
141+
conflicting_files.push_back(entry.path().string());
142142
continue;
143143
}
144144
std::cout << "Registering Tree from File: " << entry.path().string() << "\n";
@@ -169,6 +169,20 @@ class BehaviorTreeHandler
169169
register_all_bt_files();
170170
}
171171

172+
// Log all conflicting files once at the end
173+
if (!conflicting_files.empty()) {
174+
std::string files_list;
175+
for (const auto & file : conflicting_files) {
176+
if (!files_list.empty()) {
177+
files_list += ", ";
178+
}
179+
files_list += file;
180+
}
181+
std::cerr << "Skipping conflicting BT XML files, multiple files have the same ID. "
182+
<< "Please set unique behavior tree IDs. This may affect loading of subtrees. "
183+
<< "Files not loaded: " << files_list << "\n";
184+
}
185+
172186
// Create the tree with the specified ID
173187
blackboard = setBlackboardVariables();
174188
try {
@@ -437,15 +451,18 @@ TEST_F(BehaviorTreeTestFixture, TestDuplicateIDsWithFileSpecified) {
437451

438452
EXPECT_TRUE(result);
439453

440-
bool found_conflict =
441-
log_output.find(
442-
"Skipping conflicting BT file \"" + dup2_file +
443-
"\" (duplicate ID DuplicateTree)") != std::string::npos;
444-
EXPECT_TRUE(found_conflict);
454+
// Verify the new message format
455+
EXPECT_NE(
456+
log_output.find("Skipping conflicting BT XML files, multiple files have the same ID."),
457+
std::string::npos) << "Should warn about duplicate IDs";
458+
EXPECT_NE(log_output.find("Please set unique behavior tree IDs"), std::string::npos)
459+
<< "Should provide guidance about unique IDs";
460+
EXPECT_NE(log_output.find("Files not loaded:"), std::string::npos)
461+
<< "Should list files not loaded";
462+
EXPECT_NE(log_output.find(dup2_file), std::string::npos)
463+
<< "Should mention the skipped file";
445464

446465
EXPECT_NE(log_output.find("Registering Tree from File"), std::string::npos);
447-
EXPECT_NE(log_output.find("Skipping conflicting BT file"), std::string::npos)
448-
<< "Should warn about duplicate ID";
449466
EXPECT_NE(log_output.find("Created BT from ID: DuplicateTree"), std::string::npos);
450467

451468
std::filesystem::remove_all(tmp_dir);
@@ -590,7 +607,7 @@ TEST_F(BehaviorTreeTestFixture, TestDuplicateIDsWithIDSpecified) {
590607

591608
EXPECT_NE(log_output.find("Registering Tree from File"), std::string::npos)
592609
<< "Should have registered at least one BT file";
593-
EXPECT_NE(log_output.find("Skipping conflicting BT file"), std::string::npos)
610+
EXPECT_NE(log_output.find("Skipping conflicting BT XML files"), std::string::npos)
594611
<< "Should warn about duplicate IDs";
595612
EXPECT_NE(log_output.find("Created BT from ID: DuplicateTree"), std::string::npos)
596613
<< "Should have created BT from the given ID";
@@ -604,7 +621,7 @@ TEST_F(BehaviorTreeTestFixture, TestDuplicateIDsWithIDSpecified) {
604621
<< "At least one duplicate file should have been registered";
605622
EXPECT_FALSE(registered_dup1 && registered_dup2)
606623
<< "Only one of the duplicate files should be registered as the main tree";
607-
EXPECT_NE(log_output.find("Skipping conflicting BT file"), std::string::npos);
624+
EXPECT_NE(log_output.find("Skipping conflicting BT XML files"), std::string::npos);
608625
EXPECT_NE(log_output.find("Created BT from ID: DuplicateTree"), std::string::npos);
609626

610627

tools/underlay.repos

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ repositories:
44
# url: https://github.com/BehaviorTree/BehaviorTree.CPP.git
55
# version: 4.8.2
66
# ros2/rviz:
7-
# type: git
8-
# url: https://github.com/ros2/rviz.git
9-
# version: rolling
7+
# type: git
8+
# url: https://github.com/ros2/rviz.git
9+
# version: rolling
1010
# ros/angles:
1111
# type: git
1212
# url: https://github.com/ros/angles.git

0 commit comments

Comments
 (0)