DistanceDetector

Hardware-agnostic distance / range readings from the active ranging sensor.

#include <distance_detector.hpp>

Classes

class DistanceDetector

Distance Detection feature of the perception service.

Owned by PerceptionController — do not construct directly. Obtain via `vehicle.GetPerceptionController().GetDistanceDetector()`.

Threading: getters are non-blocking snapshot reads, safe from any thread. Callbacks fire on the producing sensor's thread; do not block inside them.

bool IsAvailable() const

True iff at least one sensor with `kRanging` capability is attached and running.

Useful to gate UI ("Show LiDAR view") and decide whether to call the data-returning methods at all. The data methods themselves are always safe to call — they return empty values when unavailable.

Returns: bool

DistanceScan GetLatestScan() const

The latest complete scan from the active ranging sensor.

Returns an empty `DistanceScan` (`ray_count() == 0`) if no sensor has produced data yet or `IsAvailable()` is false.

Returns: DistanceScan

float GetForwardDistance() const

Distance in metres straight ahead (bearing 0°), or -1 if unknown.

Convenience wrapper around `GetLatestScan()` — picks the ray nearest to bearing 0° within the sensor's field of view.

Returns: float

float GetClosestObstacleDistance() const

Distance to the closest detected obstacle, in metres, or -1 if unknown.

Returns: float

float GetClosestObstacleAngle() const

Bearing of the closest detected obstacle, in degrees, or 0 if unknown. Convention: negative = left, positive = right.

Returns: float

void OnScanUpdated(ScanCallback cb)

Register a callback that fires whenever a new scan arrives.

Replaces any previously registered scan callback. Pass an empty `std::function` to clear it.

ParameterTypeDescription
cb ScanCallback
void OnProximityAlert(float threshold_m, ProximityCallback cb)

Fire `cb` once any forward-facing return drops below `threshold_m`. Callback re-arms after the obstacle clears.

Replaces any previously registered proximity callback. Pass an empty callback to clear.

ParameterTypeDescription
threshold_m float
cb ProximityCallback