feat(move_base2): direction zone delivery and costmap readiness wait
- SensorGateway::pushStaticMap also dispatches to DIRECTIONAL_LAYER on the global costmap, before STATIC_LAYER: with a same-geometry map the directional layer goes PENDING before StaticLayer can report current, so a plan cannot pair the new map with the old zones. - Static maps are replayed in arrival order instead of topic order, so a direction grid is never replayed before its static map. - PlannerRunner checks every enabled global layer under the same lock as the snapshot. While a layer is not current it keeps the goal, reports waiting_for_costmap, logs the stale layers (throttled) and spends no planner_patience or watchdog budget. After costmap_ready_timeout [s] (default 10, 0 = legacy behaviour) the attempt fails as before. The key is added to config/runtime/move_base_common_params.yaml. - Test fixture destroys the server before its fake ports (the control thread could call a destroyed port). Full history: branch feature/direction-zone.
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include <move_base2/io/sensor_store_types.h>
|
||||
#include <robot_sensor_ports/sensor_writer.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
#include <mission_adapters/mission_request.h>
|
||||
@@ -181,23 +182,41 @@ void NavigationServer::attachCostmaps(robot_costmap_2d::LayeredCostmap* global,
|
||||
// Phát lại static map đã nhận trước khi costmap tồn tại. Chỉ static map, cố ý: một laser scan cũ
|
||||
// phát lại vào costmap là dựng vật cản ở chỗ robot có thể đã rời khỏi từ lâu — im lặng và nguy
|
||||
// hiểm hơn hẳn việc chờ mẫu kế tiếp, vốn chỉ cách vài chục ms.
|
||||
std::map<std::string, robot_nav_msgs::OccupancyGrid> maps;
|
||||
using ReplayEntry = std::pair<std::uint64_t,
|
||||
std::pair<std::string, robot_nav_msgs::OccupancyGrid>>;
|
||||
std::vector<ReplayEntry> maps;
|
||||
std::pair<std::string, robot_nav_msgs::OccupancyGrid> legacy_map;
|
||||
bool has_legacy_map = false;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(data_mutex_);
|
||||
maps = static_maps_;
|
||||
maps.reserve(static_maps_.size());
|
||||
for (const auto& entry : static_maps_)
|
||||
{
|
||||
maps.push_back({ static_map_sequences_.at(entry.first), entry });
|
||||
}
|
||||
|
||||
// `map_save_`/`map_name_save_` là cặp biến PUBLIC của BaseNavigation mà host tự gán (đường bù
|
||||
// của bản cũ cho đúng vấn đề này). Tôn trọng nó để host không phải sửa gì, nhưng không để nó
|
||||
// ghi đè bản đã đi qua addStaticMap.
|
||||
if (!map_name_save_.empty() && maps.find(map_name_save_) == maps.end())
|
||||
if (!map_name_save_.empty() && static_maps_.find(map_name_save_) == static_maps_.end())
|
||||
{
|
||||
maps[map_name_save_] = map_save_;
|
||||
legacy_map = { map_name_save_, map_save_ };
|
||||
has_legacy_map = true;
|
||||
}
|
||||
}
|
||||
|
||||
// The static map must precede its direction grid: the app must resend the direction grid
|
||||
// immediately after every static map. Replaying by topic name would reverse that order.
|
||||
std::sort(maps.begin(), maps.end(), [](const ReplayEntry& a, const ReplayEntry& b) {
|
||||
return a.first < b.first;
|
||||
});
|
||||
if (has_legacy_map)
|
||||
{
|
||||
sensors_.pushStaticMap(legacy_map.first, legacy_map.second);
|
||||
}
|
||||
for (const auto& entry : maps)
|
||||
{
|
||||
sensors_.pushStaticMap(entry.first, entry.second);
|
||||
sensors_.pushStaticMap(entry.second.first, entry.second.second);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -693,6 +712,7 @@ void NavigationServer::addStaticMap(const std::string& topic, robot_nav_msgs::Oc
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(data_mutex_);
|
||||
static_maps_[topic] = map;
|
||||
static_map_sequences_[topic] = ++next_static_map_sequence_;
|
||||
}
|
||||
sensors_.pushStaticMap(topic, map);
|
||||
}
|
||||
@@ -825,6 +845,7 @@ bool NavigationServer::removeStaticMap(const std::string& topic)
|
||||
sensor_store_.clearTopic(topic);
|
||||
|
||||
std::lock_guard<std::mutex> lock(data_mutex_);
|
||||
static_map_sequences_.erase(topic);
|
||||
return static_maps_.erase(topic) > 0;
|
||||
}
|
||||
|
||||
@@ -866,6 +887,7 @@ bool NavigationServer::removeAllStaticMaps()
|
||||
|
||||
std::lock_guard<std::mutex> lock(data_mutex_);
|
||||
static_maps_.clear();
|
||||
static_map_sequences_.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -906,6 +928,7 @@ bool NavigationServer::removeAllData()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(data_mutex_);
|
||||
static_maps_.clear();
|
||||
static_map_sequences_.clear();
|
||||
laser_scans_.clear();
|
||||
point_clouds_.clear();
|
||||
point_cloud2s_.clear();
|
||||
|
||||
Reference in New Issue
Block a user