feat(directional_layer): rewrite as a direction field provider

DirectionalLayer no longer derives from StaticLayer and never writes the
master grid. It receives an OccupancyGrid of direction codes (0 = no
constraint, 1..8 = direction_index + 1) on direction_topic, validates it
against the master geometry and global frame, and publishes an immutable
DirectionField snapshot with a DISABLED / PENDING / READY state and a
generation counter. Every static map on map_topic drops the snapshot and
returns the layer to PENDING until a grid for that map arrives.

direction_field.h holds the core API used by planners: grid validation,
DirectionField with bounds-checked codeAt(), a half-open-cell DDA
(traverseGridSegment), allowedDirectionMask() and checkSegment().
LayeredCostmap::getDirectionFieldSnapshot() exposes the snapshot through
the DirectionFieldProvider interface without adding data members.

Tests: direction_field_test (7) and directional_layer_test (5) pass.
This commit is contained in:
2026-11-03 16:55:10 +07:00
parent 3539afbfb4
commit 3d552b49d0
10 changed files with 1170 additions and 437 deletions

View File

@@ -38,6 +38,7 @@
#ifndef ROBOT_COSTMAP_2D_LAYERED_COSTMAP_H_
#define ROBOT_COSTMAP_2D_LAYERED_COSTMAP_H_
#include <robot_costmap_2d/direction_field.h>
#include <robot_costmap_2d/cost_values.h>
#include <robot_costmap_2d/layer.h>
#include <robot_costmap_2d/costmap_2d.h>
@@ -99,6 +100,9 @@ public:
bool isCurrent();
/** Consistent snapshot; plugin list must be fixed before concurrent reads. */
DirectionFieldSnapshot getDirectionFieldSnapshot() const;
Costmap2D* getCostmap()
{
return &costmap_;