okapi::DistanceSensor class

Base classes

template<typename T>
class ControllerInput

Constructors, destructors, conversion operators

DistanceSensor(std::uint8_t iport, std::unique_ptr<Filter> ifilter = std::make_unique<PassthroughFilter>())
A distance sensor on a V5 port.
~DistanceSensor() defaulted virtual

Public functions

auto get() -> double
Get the current filtered sensor value in mm.
auto controllerGet() -> double override
Get the sensor value for use in a control loop.
auto getConfidence() const -> std::int32_t
Get the confidence in the distance reading.
auto getObjectSize() const -> std::int32_t
Get the current guess at relative object size.
auto getObjectVelocity() const -> double
Get the object velocity in m/s.

Protected variables

std::uint8_t port
std::unique_ptr<Filter> filter

Function documentation

okapi::DistanceSensor::DistanceSensor(std::uint8_t iport, std::unique_ptr<Filter> ifilter = std::make_unique<PassthroughFilter>())

A distance sensor on a V5 port.

Parameters
iport The V5 port the device uses.
ifilter The filter to use for filtering the distance measurements.
auto ds = DistanceSensor(1);
auto filteredDistSensor = DistanceSensor(1, std::make_unique<MedianFilter<5>>());

double okapi::DistanceSensor::get()

Get the current filtered sensor value in mm.

Returns The current filtered sensor value in mm.

double okapi::DistanceSensor::controllerGet() override

Get the sensor value for use in a control loop.

Returns The same as get.

This method might be automatically called in another thread by the controller.

std::int32_t okapi::DistanceSensor::getConfidence() const

Get the confidence in the distance reading.

Returns The confidence value in the range [0, 63].

This value has a range of [0, 63]. 63 means high confidence, lower values imply less confidence. Confidence is only available when distance is greater than 200 mm.

std::int32_t okapi::DistanceSensor::getObjectSize() const

Get the current guess at relative object size.

Returns The size value in the range [0, 400] or PROS_ERR if the operation failed, setting errno.

This value has a range of [0, 400]. A 18" x 30" grey card will return a value of approximately 75 in typical room lighting.

double okapi::DistanceSensor::getObjectVelocity() const

Get the object velocity in m/s.

Returns The object velocity in m/s.