From 7721e7ed0430a2ff9621d530a29f5165cf399cc8 Mon Sep 17 00:00:00 2001 From: Esther Aguado Date: Mon, 30 Nov 2026 18:09:14 +0100 Subject: [PATCH 1/2] Move DiagnosticRecoveryManager reference components to their own library --- .../CMakeLists.txt | 36 ++++++++----- ...diagnostic_recovery_components_plugins.xml | 2 +- .../tests/CMakeLists.txt | 21 ++++++-- .../tests/component_library_tests.cpp | 51 +++++++++++++++++++ 4 files changed, 92 insertions(+), 18 deletions(-) create mode 100644 recoveries/easynav_diagnostic_recovery/tests/component_library_tests.cpp diff --git a/recoveries/easynav_diagnostic_recovery/CMakeLists.txt b/recoveries/easynav_diagnostic_recovery/CMakeLists.txt index 8b31cdaf..e9d7c296 100644 --- a/recoveries/easynav_diagnostic_recovery/CMakeLists.txt +++ b/recoveries/easynav_diagnostic_recovery/CMakeLists.txt @@ -20,25 +20,14 @@ find_package(rcl_interfaces REQUIRED) find_package(PCL REQUIRED COMPONENTS common io) # A diagnosis-driven recovery system (DiagnosticRecoveryManager), the plugin interfaces it is composed -# of (safety reflexes, evaluators, mitigations), the helpers its plugins share and the reference plugins. +# of (safety reflexes, evaluators, mitigations) and the helpers its plugins share. +# A recovery manager may inherit from the DRM: it links only this library. add_library(${PROJECT_NAME} SHARED src/easynav_diagnostic_recovery/DiagnosticRecoveryManager.cpp src/easynav_diagnostic_recovery/ObstacleProximity.cpp src/easynav_diagnostic_recovery/RecoveryEvaluatorBase.cpp src/easynav_diagnostic_recovery/RecoveryMitigationBase.cpp src/easynav_diagnostic_recovery/SafetyReflexBase.cpp - src/easynav_diagnostic_recovery/evaluators/ControllerStuckEvaluator.cpp - src/easynav_diagnostic_recovery/evaluators/NoPathEvaluator.cpp - src/easynav_diagnostic_recovery/evaluators/ObstacleTooCloseEvaluator.cpp - src/easynav_diagnostic_recovery/evaluators/RosGraphEvaluator.cpp - src/easynav_diagnostic_recovery/evaluators/SafetyChannelEvaluator.cpp - src/easynav_diagnostic_recovery/mitigations/AdvanceRecovery.cpp - src/easynav_diagnostic_recovery/mitigations/RotateRecovery.cpp - src/easynav_diagnostic_recovery/mitigations/CancelMissionRecovery.cpp - src/easynav_diagnostic_recovery/mitigations/HumanAssistanceRecovery.cpp - src/easynav_diagnostic_recovery/mitigations/SafeRetreatRecovery.cpp - src/easynav_diagnostic_recovery/mitigations/ShutdownRecovery.cpp - src/easynav_diagnostic_recovery/reflexes/CollisionSafetyReflex.cpp ) target_include_directories(${PROJECT_NAME} PUBLIC $ @@ -60,6 +49,25 @@ target_link_libraries(${PROJECT_NAME} PUBLIC ${PCL_LIBRARIES} ) +# The reference safety reflexes, evaluators and mitigations, in their own library: pluginlib +# loads it. If they lived in the DRM library, a recovery manager that inherits from the DRM +# would load them as a link dependency, outside pluginlib, and the DRM could not create them. +add_library(${PROJECT_NAME}_components SHARED + src/easynav_diagnostic_recovery/evaluators/ControllerStuckEvaluator.cpp + src/easynav_diagnostic_recovery/evaluators/NoPathEvaluator.cpp + src/easynav_diagnostic_recovery/evaluators/ObstacleTooCloseEvaluator.cpp + src/easynav_diagnostic_recovery/evaluators/RosGraphEvaluator.cpp + src/easynav_diagnostic_recovery/evaluators/SafetyChannelEvaluator.cpp + src/easynav_diagnostic_recovery/mitigations/AdvanceRecovery.cpp + src/easynav_diagnostic_recovery/mitigations/RotateRecovery.cpp + src/easynav_diagnostic_recovery/mitigations/CancelMissionRecovery.cpp + src/easynav_diagnostic_recovery/mitigations/HumanAssistanceRecovery.cpp + src/easynav_diagnostic_recovery/mitigations/SafeRetreatRecovery.cpp + src/easynav_diagnostic_recovery/mitigations/ShutdownRecovery.cpp + src/easynav_diagnostic_recovery/reflexes/CollisionSafetyReflex.cpp +) +target_link_libraries(${PROJECT_NAME}_components PUBLIC ${PROJECT_NAME}) + add_library(dummy_evaluator SHARED src/easynav_diagnostic_recovery/DummyEvaluator.cpp ) @@ -82,6 +90,7 @@ install( install(TARGETS ${PROJECT_NAME} + ${PROJECT_NAME}_components dummy_evaluator dummy_mitigation dummy_safety_reflex @@ -106,6 +115,7 @@ endif() ament_export_include_directories("include/${PROJECT_NAME}") ament_export_libraries( ${PROJECT_NAME} + ${PROJECT_NAME}_components dummy_evaluator dummy_mitigation dummy_safety_reflex diff --git a/recoveries/easynav_diagnostic_recovery/easynav_diagnostic_recovery_components_plugins.xml b/recoveries/easynav_diagnostic_recovery/easynav_diagnostic_recovery_components_plugins.xml index 88c57b5b..e32a5705 100644 --- a/recoveries/easynav_diagnostic_recovery/easynav_diagnostic_recovery_components_plugins.xml +++ b/recoveries/easynav_diagnostic_recovery/easynav_diagnostic_recovery_components_plugins.xml @@ -1,5 +1,5 @@ - + Diagnoses a robot commanded to move ("cmd_vel" above threshold) that is not making diff --git a/recoveries/easynav_diagnostic_recovery/tests/CMakeLists.txt b/recoveries/easynav_diagnostic_recovery/tests/CMakeLists.txt index 3cf4d5ee..eaba82ad 100644 --- a/recoveries/easynav_diagnostic_recovery/tests/CMakeLists.txt +++ b/recoveries/easynav_diagnostic_recovery/tests/CMakeLists.txt @@ -4,6 +4,19 @@ find_package(lifecycle_msgs REQUIRED) ament_add_gtest(diagnostic_recovery_bases_tests diagnostic_recovery_bases_tests.cpp) target_link_libraries(diagnostic_recovery_bases_tests ${PROJECT_NAME}) +# Links neither library on purpose (like system_main): pluginlib must load the components after +# a plugin that links the DRM library. Only the headers and their dependencies are used. +ament_add_gtest(component_library_tests component_library_tests.cpp) +target_include_directories(component_library_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include) +target_link_libraries(component_library_tests + easynav_common::easynav_common + easynav_core::easynav_core + pluginlib::pluginlib + rclcpp::rclcpp + rclcpp_lifecycle::rclcpp_lifecycle + ${diagnostic_msgs_TARGETS} +) + ament_add_gtest(obstacle_proximity_tests obstacle_proximity_tests.cpp) target_link_libraries(obstacle_proximity_tests ${PROJECT_NAME}) @@ -23,12 +36,12 @@ foreach(test ros_graph_evaluator_tests safety_channel_evaluator_tests) ament_add_gtest(${test} evaluators/${test}.cpp) - target_link_libraries(${test} ${PROJECT_NAME}) + target_link_libraries(${test} ${PROJECT_NAME}_components) endforeach() find_package(easynav_planner REQUIRED) ament_add_gtest(no_path_faulty_planner_tests evaluators/no_path_faulty_planner_tests.cpp) -target_link_libraries(no_path_faulty_planner_tests ${PROJECT_NAME} easynav_planner::faulty_planner) +target_link_libraries(no_path_faulty_planner_tests ${PROJECT_NAME}_components easynav_planner::faulty_planner) # Mitigations foreach(test @@ -39,9 +52,9 @@ foreach(test safe_retreat_recovery_tests shutdown_recovery_tests) ament_add_gtest(${test} mitigations/${test}.cpp) - target_link_libraries(${test} ${PROJECT_NAME}) + target_link_libraries(${test} ${PROJECT_NAME}_components) endforeach() # Reflexes ament_add_gtest(collision_safety_reflex_tests reflexes/collision_safety_reflex_tests.cpp) -target_link_libraries(collision_safety_reflex_tests ${PROJECT_NAME}) +target_link_libraries(collision_safety_reflex_tests ${PROJECT_NAME}_components) diff --git a/recoveries/easynav_diagnostic_recovery/tests/component_library_tests.cpp b/recoveries/easynav_diagnostic_recovery/tests/component_library_tests.cpp new file mode 100644 index 00000000..225e7b33 --- /dev/null +++ b/recoveries/easynav_diagnostic_recovery/tests/component_library_tests.cpp @@ -0,0 +1,51 @@ +// Copyright 2026 Intelligent Robotics Lab +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/// \file +/// \brief The reference components can be loaded after a plugin that links the DRM library. +/// +/// A recovery manager of one's own (or one that inherits from the DRM) links +/// easynav_diagnostic_recovery for the base classes, and is loaded by recovery_node's class +/// loader. If the reference components lived in that library, they would be registered then, +/// under that loader, and the manager's own loader could not create them ("no factory exists"). +/// +/// This executable links neither library, as system_main does: pluginlib loads them. +/// DummyEvaluator plays the plugin that links the DRM library, loaded by a first class loader; +/// a second one, like the manager's, then creates a reference component. + +#include + +#include "gtest/gtest.h" +#include "pluginlib/class_loader.hpp" + +#include "easynav_diagnostic_recovery/RecoveryEvaluatorBase.hpp" + +using easynav_diagnostic_recovery::RecoveryEvaluatorBase; + +TEST(ComponentLibraryTest, ComponentLoadsAfterAPluginThatLinksTheDrmLibrary) +{ + pluginlib::ClassLoader first_loader( + "easynav_diagnostic_recovery", "easynav_diagnostic_recovery::RecoveryEvaluatorBase"); + // Its library links easynav_diagnostic_recovery, so loading it loads the DRM library too + std::shared_ptr dummy; + ASSERT_NO_THROW( + dummy = first_loader.createSharedInstance("easynav_diagnostic_recovery/DummyEvaluator")); + + pluginlib::ClassLoader second_loader( + "easynav_diagnostic_recovery", "easynav_diagnostic_recovery::RecoveryEvaluatorBase"); + std::shared_ptr no_path; + EXPECT_NO_THROW( + no_path = second_loader.createSharedInstance("easynav_diagnostic_recovery/NoPathEvaluator")); + EXPECT_NE(no_path, nullptr); +} From 6c79ffe22e7d9969fcfc7d1d61ea61d838f754b2 Mon Sep 17 00:00:00 2001 From: Esther Aguado Date: Thu, 3 Dec 2026 11:40:47 +0100 Subject: [PATCH 2/2] Fix description of DRMs and test all three interfaces --- .../CMakeLists.txt | 3 + .../easynav_diagnostic_recovery/README.md | 12 +++- .../tests/component_library_tests.cpp | 62 ++++++++++++++----- 3 files changed, 59 insertions(+), 18 deletions(-) diff --git a/recoveries/easynav_diagnostic_recovery/CMakeLists.txt b/recoveries/easynav_diagnostic_recovery/CMakeLists.txt index e9d7c296..e6fb8729 100644 --- a/recoveries/easynav_diagnostic_recovery/CMakeLists.txt +++ b/recoveries/easynav_diagnostic_recovery/CMakeLists.txt @@ -22,6 +22,9 @@ find_package(PCL REQUIRED COMPONENTS common io) # A diagnosis-driven recovery system (DiagnosticRecoveryManager), the plugin interfaces it is composed # of (safety reflexes, evaluators, mitigations) and the helpers its plugins share. # A recovery manager may inherit from the DRM: it links only this library. +# This library also registers the DiagnosticRecoveryManager plugin, so a recovery manager that +# links it registers the DRM class too. recovery_node only creates the manager named in its +# parameters, so the extra registration has no effect. add_library(${PROJECT_NAME} SHARED src/easynav_diagnostic_recovery/DiagnosticRecoveryManager.cpp src/easynav_diagnostic_recovery/ObstacleProximity.cpp diff --git a/recoveries/easynav_diagnostic_recovery/README.md b/recoveries/easynav_diagnostic_recovery/README.md index aeec346a..7d2bfbb6 100644 --- a/recoveries/easynav_diagnostic_recovery/README.md +++ b/recoveries/easynav_diagnostic_recovery/README.md @@ -37,9 +37,15 @@ what the active mitigation reports). The EasyNav TUI shows both. ## Package layout -Everything is in the `easynav_diagnostic_recovery` package and library. Headers are under -`include/easynav_diagnostic_recovery/`, sources under `src/easynav_diagnostic_recovery/` and tests -under `tests/`, with the same subfolders: +The package builds two libraries: + +| Library | Contents | Who uses it | +|---|---|---| +| `easynav_diagnostic_recovery` | The manager, the three plugin interfaces and `ObstacleProximity` | Link it to write your own recovery manager, one that inherits from the DRM, or your own evaluators, mitigations and reflexes | +| `easynav_diagnostic_recovery_components` | The reference reflexes, evaluators and mitigations | Do not link it: pluginlib loads it. If a library that registers plugins is loaded as a link dependency, its plugins are registered under the wrong class loader and pluginlib cannot create them ("no factory exists") | + +Headers are under `include/easynav_diagnostic_recovery/`, sources under `src/easynav_diagnostic_recovery/` +and tests under `tests/`, with the same subfolders: | Subfolder | Contents | |---|---| diff --git a/recoveries/easynav_diagnostic_recovery/tests/component_library_tests.cpp b/recoveries/easynav_diagnostic_recovery/tests/component_library_tests.cpp index 225e7b33..a1301228 100644 --- a/recoveries/easynav_diagnostic_recovery/tests/component_library_tests.cpp +++ b/recoveries/easynav_diagnostic_recovery/tests/component_library_tests.cpp @@ -21,31 +21,63 @@ /// under that loader, and the manager's own loader could not create them ("no factory exists"). /// /// This executable links neither library, as system_main does: pluginlib loads them. -/// DummyEvaluator plays the plugin that links the DRM library, loaded by a first class loader; -/// a second one, like the manager's, then creates a reference component. +/// For each of the three interfaces, a dummy plugin plays the plugin that links the DRM library, +/// loaded by a first class loader; a second one, like the manager's, then creates a reference +/// component. #include +#include #include "gtest/gtest.h" #include "pluginlib/class_loader.hpp" #include "easynav_diagnostic_recovery/RecoveryEvaluatorBase.hpp" +#include "easynav_diagnostic_recovery/RecoveryMitigationBase.hpp" +#include "easynav_diagnostic_recovery/SafetyReflexBase.hpp" using easynav_diagnostic_recovery::RecoveryEvaluatorBase; +using easynav_diagnostic_recovery::RecoveryMitigationBase; +using easynav_diagnostic_recovery::SafetyReflexBase; -TEST(ComponentLibraryTest, ComponentLoadsAfterAPluginThatLinksTheDrmLibrary) +namespace { - pluginlib::ClassLoader first_loader( - "easynav_diagnostic_recovery", "easynav_diagnostic_recovery::RecoveryEvaluatorBase"); + +/// \brief Loads \p dummy with one class loader, then \p component with another one. +template +void expect_component_loads_after_dummy( + const std::string & base_class, const std::string & dummy, const std::string & component) +{ + pluginlib::ClassLoader first_loader("easynav_diagnostic_recovery", base_class); // Its library links easynav_diagnostic_recovery, so loading it loads the DRM library too - std::shared_ptr dummy; - ASSERT_NO_THROW( - dummy = first_loader.createSharedInstance("easynav_diagnostic_recovery/DummyEvaluator")); - - pluginlib::ClassLoader second_loader( - "easynav_diagnostic_recovery", "easynav_diagnostic_recovery::RecoveryEvaluatorBase"); - std::shared_ptr no_path; - EXPECT_NO_THROW( - no_path = second_loader.createSharedInstance("easynav_diagnostic_recovery/NoPathEvaluator")); - EXPECT_NE(no_path, nullptr); + std::shared_ptr dummy_instance; + ASSERT_NO_THROW(dummy_instance = first_loader.createSharedInstance(dummy)); + + pluginlib::ClassLoader second_loader("easynav_diagnostic_recovery", base_class); + std::shared_ptr component_instance; + EXPECT_NO_THROW(component_instance = second_loader.createSharedInstance(component)); + EXPECT_NE(component_instance, nullptr); +} + +} // namespace + +TEST(ComponentLibraryTest, EvaluatorLoadsAfterAPluginThatLinksTheDrmLibrary) +{ + expect_component_loads_after_dummy( + "easynav_diagnostic_recovery::RecoveryEvaluatorBase", + "easynav_diagnostic_recovery/DummyEvaluator", "easynav_diagnostic_recovery/NoPathEvaluator"); +} + +TEST(ComponentLibraryTest, MitigationLoadsAfterAPluginThatLinksTheDrmLibrary) +{ + expect_component_loads_after_dummy( + "easynav_diagnostic_recovery::RecoveryMitigationBase", + "easynav_diagnostic_recovery/DummyMitigation", "easynav_diagnostic_recovery/RotateRecovery"); +} + +TEST(ComponentLibraryTest, SafetyReflexLoadsAfterAPluginThatLinksTheDrmLibrary) +{ + expect_component_loads_after_dummy( + "easynav_diagnostic_recovery::SafetyReflexBase", + "easynav_diagnostic_recovery/DummySafetyReflex", + "easynav_diagnostic_recovery/CollisionSafetyReflex"); }