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:
@@ -366,6 +366,25 @@ namespace robot_costmap_2d
|
||||
}
|
||||
}
|
||||
|
||||
DirectionFieldSnapshot LayeredCostmap::getDirectionFieldSnapshot() const
|
||||
{
|
||||
DirectionFieldSnapshot result;
|
||||
unsigned int count = 0;
|
||||
for (const auto& plugin : plugins_)
|
||||
{
|
||||
if (!plugin->isEnabled()) continue;
|
||||
const auto* provider = dynamic_cast<const DirectionFieldProvider*>(plugin.get());
|
||||
if (!provider) continue;
|
||||
result = provider->directionSnapshot();
|
||||
if (++count > 1)
|
||||
{
|
||||
robot::log_error("Multiple enabled direction field providers; refusing direction queries");
|
||||
return {DirectionFieldState::kPending, {}, 0};
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool LayeredCostmap::isCurrent()
|
||||
{
|
||||
current_ = true;
|
||||
|
||||
Reference in New Issue
Block a user