Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions recoveries/easynav_diagnostic_recovery/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
Expand All @@ -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
)
Expand All @@ -82,6 +90,7 @@ install(

install(TARGETS
${PROJECT_NAME}
${PROJECT_NAME}_components
dummy_evaluator
dummy_mitigation
dummy_safety_reflex
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<class_libraries>
<library path="easynav_diagnostic_recovery">
<library path="easynav_diagnostic_recovery_components">
<class name="easynav_diagnostic_recovery/ControllerStuckEvaluator" type="easynav::ControllerStuckEvaluator" base_class_type="easynav_diagnostic_recovery::RecoveryEvaluatorBase">
<description>
Diagnoses a robot commanded to move ("cmd_vel" above threshold) that is not making
Expand Down
21 changes: 17 additions & 4 deletions recoveries/easynav_diagnostic_recovery/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand All @@ -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
Expand All @@ -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)
Original file line number Diff line number Diff line change
@@ -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 <memory>

#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<RecoveryEvaluatorBase> 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<RecoveryEvaluatorBase> dummy;
ASSERT_NO_THROW(
dummy = first_loader.createSharedInstance("easynav_diagnostic_recovery/DummyEvaluator"));

pluginlib::ClassLoader<RecoveryEvaluatorBase> second_loader(
"easynav_diagnostic_recovery", "easynav_diagnostic_recovery::RecoveryEvaluatorBase");
std::shared_ptr<RecoveryEvaluatorBase> no_path;
EXPECT_NO_THROW(
no_path = second_loader.createSharedInstance("easynav_diagnostic_recovery/NoPathEvaluator"));
EXPECT_NE(no_path, nullptr);
}
Loading