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.
| Field | Type | Description |
|---|---|---|
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 |
bool IsAvailable() constTrue iff a mapping backend is attached and running.
Returns: bool
OccupancyGrid Get2DMap() constReturns the 2D occupancy grid for navigation and display.
Returns: Current OccupancyGrid; empty if the mapping backend is unavailable.
PointCloud Get3DMap() constReturns the 3D point-cloud map for visualisation.
Returns: Current PointCloud; empty if no 3D data has been produced yet.
Pose2D GetEstimatedPose() constReturns the corrected robot pose in the map frame.
Returns: Estimated Pose2D; zero pose if unavailable.
Stats GetStats() constReturns summary statistics about the current map state.
Returns: Stats snapshot.
bool SaveMap(const std::string& path) constSave 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.
| Parameter | Type | Description |
|---|---|---|
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.
| Parameter | Type | Description |
|---|---|---|
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.
| Parameter | Type | Description |
|---|---|---|
cb |
MapUpdatedCallback |
bool ConnectMapRpc(const std::string& host, uint16_t port)Configure the remote map-RPC endpoint.
| Parameter | Type | Description |
|---|---|---|
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.