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.
This commit is contained in:
@@ -32,6 +32,9 @@ recovery_core::RecoveryTrigger toCoreTrigger(RecoveryTrigger trigger)
|
||||
return recovery_core::RecoveryTrigger::kPathBlocked;
|
||||
case RecoveryTrigger::kOffPath:
|
||||
return recovery_core::RecoveryTrigger::kOffPath;
|
||||
case RecoveryTrigger::kCollision:
|
||||
case RecoveryTrigger::kDetector:
|
||||
break; // recovery_core chưa có hai lý do này: kUnspecified (chỉ dùng để log)
|
||||
}
|
||||
return recovery_core::RecoveryTrigger::kUnspecified;
|
||||
}
|
||||
@@ -220,6 +223,7 @@ bool RecoveryRunner::configureRoutes(robot::NodeHandle& nh, std::string& error)
|
||||
return false;
|
||||
};
|
||||
|
||||
std::vector<std::string> named_keys;
|
||||
for (const auto& entry : configured_routes)
|
||||
{
|
||||
if (!entry.first.IsScalar())
|
||||
@@ -230,8 +234,7 @@ bool RecoveryRunner::configureRoutes(robot::NodeHandle& nh, std::string& error)
|
||||
const std::string key = entry.first.as<std::string>();
|
||||
if (!is_expected_key(key))
|
||||
{
|
||||
error = routes_key + " has unsupported trigger '" + key + "'";
|
||||
return false;
|
||||
named_keys.push_back(key); // route theo detector (ví dụ `intrusion`): detector trỏ tới theo tên
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,6 +253,8 @@ bool RecoveryRunner::configureRoutes(robot::NodeHandle& nh, std::string& error)
|
||||
return &routes_.off_path;
|
||||
case RecoveryTrigger::kCollision:
|
||||
return &routes_.collision;
|
||||
case RecoveryTrigger::kDetector:
|
||||
break;
|
||||
}
|
||||
return &routes_.planning_failed;
|
||||
};
|
||||
@@ -262,9 +267,8 @@ bool RecoveryRunner::configureRoutes(robot::NodeHandle& nh, std::string& error)
|
||||
// (2026-08-05): cursor chỉ reset khi robot đi được quá oscillation_distance, nhưng giữa hai lần
|
||||
// monitor bắn robot chỉ nhích được ~0.1-0.15 m, nên route không lặp thì cạn ngay sau một cặp
|
||||
// [detour, wait] dù vật cản sắp vào tầm. Route vẫn hữu hạn — bế tắc thật vẫn ABORT được.
|
||||
const auto resolve_route = [&](const char* trigger_name, RecoveryTrigger trigger,
|
||||
const auto resolve_route = [&](const char* trigger_name, std::vector<std::size_t>* resolved,
|
||||
const YAML::Node& route_node) {
|
||||
std::vector<std::size_t>* resolved = route_for(trigger);
|
||||
resolved->clear();
|
||||
|
||||
for (const YAML::Node& behavior_node : route_node)
|
||||
@@ -300,7 +304,7 @@ bool RecoveryRunner::configureRoutes(robot::NodeHandle& nh, std::string& error)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!resolve_route(expected.first, expected.second, route_node))
|
||||
if (!resolve_route(expected.first, route_for(expected.second), route_node))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -328,7 +332,7 @@ bool RecoveryRunner::configureRoutes(robot::NodeHandle& nh, std::string& error)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!resolve_route(optional.first, optional.second, route_node))
|
||||
if (!resolve_route(optional.first, route_for(optional.second), route_node))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -343,6 +347,22 @@ bool RecoveryRunner::configureRoutes(robot::NodeHandle& nh, std::string& error)
|
||||
}
|
||||
}
|
||||
|
||||
for (const std::string& key : named_keys)
|
||||
{
|
||||
const YAML::Node route_node = configured_routes[key];
|
||||
if (!route_node.IsSequence())
|
||||
{
|
||||
error = routes_key + "/" + key + " must be a YAML sequence";
|
||||
return false;
|
||||
}
|
||||
if (!resolve_route(key.c_str(), &routes_.named[key], route_node))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
robot::log_info("[move_base2] RecoveryRunner: detector route '%s' resolved with %zu behavior(s).", key.c_str(),
|
||||
routes_.named[key].size());
|
||||
}
|
||||
|
||||
robot::log_info("[move_base2] RecoveryRunner: routes resolved: planning=%zu controlling=%zu "
|
||||
"oscillation=%zu path_blocked=%zu off_path=%zu collision=%zu.",
|
||||
routes_.planning_failed.size(), routes_.controlling_failed.size(),
|
||||
|
||||
Reference in New Issue
Block a user