diff --git a/src/io/sensor_gateway.cpp b/src/io/sensor_gateway.cpp index d43e30f..ba9f112 100644 --- a/src/io/sensor_gateway.cpp +++ b/src/io/sensor_gateway.cpp @@ -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_); diff --git a/test/sensor_gateway_test.cpp b/test/sensor_gateway_test.cpp index 79b4766..bddb620 100644 --- a/test/sensor_gateway_test.cpp +++ b/test/sensor_gateway_test.cpp @@ -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 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{"directional", "static"})); +} + TEST(SensorGateway, PointCloudAndPointCloud2AreDistinctTypes) { Bench bench;