Files
move_base2/test/env_monitor_fixture.h
duongtd 1aa2a07469 refactor: host EnvMonitor from env_monitor_core, route per detector
EnvMonitor and its detectors now live in env_monitor_core. NavigationRuntime owns
the monitor; StateMachine runs each detector's own route (step or sequence,
lock or abort on exhaustion) with a cursor per detector. RecoveryRunner accepts
named routes for detectors outside the six built-in triggers.
2026-11-27 10:08:52 +07:00

58 lines
1.9 KiB
C++

/*********************************************************************
*
* Software License Agreement (BSD License)
*
* move_base2 tests — an EnvMonitor (env_monitor_core) built from an EnvMonitorConfig through the real YAML path:
* the struct becomes the `env_monitor` block under a fresh namespace, the three built-in detectors are loaded as
* .so from devel/lib, exactly as NavigationRuntime does.
*
* Author: DuongTD
*********************************************************************/
#ifndef MOVE_BASE2_TEST_ENV_MONITOR_FIXTURE_H_
#define MOVE_BASE2_TEST_ENV_MONITOR_FIXTURE_H_
#include <cstdlib>
#include <string>
#include <yaml-cpp/yaml.h>
#include <robot/node_handle.h>
#include <env_monitor_core/env_monitor.h>
#ifndef MOVE_BASE2_TEST_LIBRARY_DIR
#error "MOVE_BASE2_TEST_LIBRARY_DIR must be defined by CMake"
#endif
namespace move_base2
{
namespace testing
{
inline bool initEnvMonitor(env_monitor_core::EnvMonitor& monitor, const env_monitor_core::EnvMonitorConfig& config,
std::string& error)
{
static int counter = 0;
// devel/lib must win over a PNKX_NAV_CORE_LIBRARY_PATH left in the user's shell.
setenv("PNKX_NAV_CORE_LIBRARY_PATH", MOVE_BASE2_TEST_LIBRARY_DIR, 1);
robot::NodeHandle nh("move_base2_env_monitor_test_" + std::to_string(++counter));
const char* const kLibraries[][2] = {
{ "ContactDetector", "libenv_monitor_core_contact_detector" },
{ "StallDetector", "libenv_monitor_core_stall_detector" },
{ "UnreachableDetector", "libenv_monitor_core_unreachable_detector" },
};
for (const auto& lib : kLibraries)
{
YAML::Node node;
node["library_path"] = lib[1];
nh.setParam(lib[0], node);
}
nh.setParam("env_monitor", env_monitor_core::toYaml(config));
return monitor.initialize(nh, error);
}
} // namespace testing
} // namespace move_base2
#endif // MOVE_BASE2_TEST_ENV_MONITOR_FIXTURE_H_