MappingService

2D / 3D occupancy mapping and SLAM-style pose tracking.

#include <mapping_service.hpp>

Classes

class MappingService

Mapping feature of the perception service.

Owned by PerceptionController. Obtain via `vehicle.GetPerceptionController().GetMappingService()`.

Threading: snapshot reads are safe from any thread. The map update callback fires on the mapping backend's thread.

struct Stats

Summary statistics about the current map state.

FieldTypeDescription
visited_cells int cells marked free
obstacle_cells int cells marked occupied
unknown_cells int cells never observed
frontier_cells int free cells adjacent to unknown
coverage_pct float percentage of the map area observed (0–100)
nearest_frontier_angle_deg float bearing to the nearest unexplored frontier, in degrees
nearest_frontier_dist_m float distance to the nearest unexplored frontier in metres; -1 if none

struct NavOverlay

Exploration overlay: the goal the planner is heading toward and the planned path to it, in map-frame world metres.

FieldTypeDescription
valid bool true when a planned path is active
goal_x float goal x in world metres
goal_y float goal y in world metres
path_xy std::vector<float> planned path as [x0,y0,x1,y1,...] in world metres
bool IsAvailable() const

True iff a mapping backend is attached and running.

Returns: bool

OccupancyGrid Get2DMap() const

Returns the 2D occupancy grid for navigation and display.

Returns: Current OccupancyGrid; empty if the mapping backend is unavailable.

PointCloud Get3DMap() const

Returns the 3D point-cloud map for visualisation.

Returns: Current PointCloud; empty if no 3D data has been produced yet.

Pose2D GetEstimatedPose() const

Returns the corrected robot pose in the map frame.

Returns: Estimated Pose2D; zero pose if unavailable.

Stats GetStats() const

Returns summary statistics about the current map state.

Returns: Stats snapshot.

bool SaveMap(const std::string& path) const

Save the current map to disk.

The output format depends on the active mapping backend. Returns false if the backend does not support persistence or the write fails.

ParameterTypeDescription
path const std::string&

Returns: bool

bool LoadMap(const std::string& path)

Load a previously saved map.

Returns false if the file is missing, the backend can't parse it, or no mapping backend is currently attached.

ParameterTypeDescription
path const std::string&

Returns: bool

void Reset()

Resets the map to empty, discarding all accumulated data.

void OnMapUpdated(MapUpdatedCallback cb)

Register a callback that fires whenever the map statistics change materially. Pass an empty callback to clear.

ParameterTypeDescription
cb MapUpdatedCallback
bool ConnectMapRpc(const std::string& host, uint16_t port)

Configure the remote map-RPC endpoint.

ParameterTypeDescription
host const std::string& IP address of the host running the perception service.
port uint16_t TCP port matching the perception service's map_rpc.port

Returns: true if the endpoint configuration was accepted; the socket

void DisconnectMapRpc()

Drop the map-RPC endpoint configuration.

Subsequent Get2DMap and Get3DMap calls return empty results until ConnectMapRpc is called again.