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); +}