fix(sensor_gateway): give static maps to the directional layer first

With a same-geometry map, StaticLayer could be written and report current
between the two dispatches while the old direction field was still READY,
so a plan could pair the new map with the old zones. The directional
layer only needs the map topic to go PENDING, and direction grids are
ignored by StaticLayer, so dispatching it first needs no lock.
This commit is contained in:
2026-11-04 11:14:15 +07:00
parent f85d89ef8c
commit 7bfb3c362d
2 changed files with 27 additions and 4 deletions

View File

@@ -276,13 +276,15 @@ void SensorGateway::pushStaticMap(const std::string& name, const robot_nav_msgs:
}
ScopedSection timer(telemetry_, section_static_map_);
// DirectionalLayer TRƯỚC StaticLayer, có chủ đích. Layer tự lọc theo topic: map_topic chỉ đưa nó về
// PENDING (không cần geometry), direction_topic là grid hướng (StaticLayer bỏ qua, nên trong cùng
// lần gọi không có resize nào). Nếu StaticLayer nhận map trước, giữa hai lần dispatch updateMap có
// thể ghi xong map mới và StaticLayer báo current trong khi field hướng cũ vẫn READY — planner kiểm
// readiness đúng lúc đó sẽ plan theo map mới với zone cũ. Chỉ global costmap có layer này.
dispatchTo(global_costmap_, map, robot_costmap_2d::LayerType::DIRECTIONAL_LAYER, name, stats_);
dispatchTo(global_costmap_, map, robot_costmap_2d::LayerType::STATIC_LAYER, name, stats_);
dispatchTo(global_costmap_, map, robot_costmap_2d::LayerType::PREFERRED_LAYER, name, stats_);
dispatchTo(global_costmap_, map, robot_costmap_2d::LayerType::UNPREFERRED_LAYER, name, stats_);
// Sau STATIC_LAYER có chủ đích: StaticLayer resize master theo map mới ngay trong callback, nên
// DirectionalLayer kiểm geometry của grid hướng trên master đã đúng kích thước. Layer tự lọc theo
// topic: map_topic đưa nó về PENDING, direction_topic là grid hướng. Chỉ global costmap có layer này.
dispatchTo(global_costmap_, map, robot_costmap_2d::LayerType::DIRECTIONAL_LAYER, name, stats_);
dispatchTo(local_costmap_, map, robot_costmap_2d::LayerType::STATIC_LAYER, name, stats_);
dispatchTo(local_costmap_, map, robot_costmap_2d::LayerType::PREFERRED_LAYER, name, stats_);

View File

@@ -152,6 +152,27 @@ TEST(SensorGateway, StaticMapArrivesWithOccupancyGridType)
EXPECT_TRUE(*layer->records()[0].type == typeid(robot_nav_msgs::OccupancyGrid));
}
TEST(SensorGateway, DirectionalLayerSeesAStaticMapBeforeTheStaticLayer)
{
// A same-geometry map must invalidate the old direction field before StaticLayer can be written
// and report current; otherwise a plan could pair the new map with the old zones (DIRECTION_ZONE_PLAN 5.3).
Bench bench;
std::vector<std::string> order;
SpyPtr static_layer = bench.addGlobal(LayerType::STATIC_LAYER, "navigation_map");
SpyPtr directional = bench.addGlobal(LayerType::DIRECTIONAL_LAYER, "direction_zones");
static_layer->setObserver([&](const void*, const std::type_info&, const std::string&) {
order.push_back("static");
});
directional->setObserver([&](const void*, const std::type_info&, const std::string&) {
order.push_back("directional");
});
bench.attach();
bench.gateway().pushStaticMap("/map", robot_nav_msgs::OccupancyGrid());
EXPECT_EQ(order, (std::vector<std::string>{"directional", "static"}));
}
TEST(SensorGateway, PointCloudAndPointCloud2AreDistinctTypes)
{
Bench bench;