okapi::OpticalSensor class

Base classes

template<typename T>
class ControllerInput

Constructors, destructors, conversion operators

OpticalSensor(std::uint8_t iport, OpticalSensorOutput ioutput = OpticalSensorOutput::hue, bool idisableGestures = true, std::unique_ptr<Filter> ifilter = std::make_unique<PassthroughFilter>())
An optical sensor on a V5 port.
~OpticalSensor() defaulted virtual

Public functions

auto get() -> double
Get the current filtered value of the selected output (configured by the constructor).
auto getHue() const -> double
Get the current hue value in the range [0, 360).
auto getBrightness() const -> double
Get the current brightness value in the range [0, 1].
auto getSaturation() const -> double
Get the current saturation value in the range [0, 1].
auto getLedPWM() const -> int32_t
Get the PWM value of the white LED in the range [0, 100].
auto setLedPWM(std::uint8_t ivalue) const -> int32_t
Set the PWM value of the white LED in the range [0, 100].
auto getProximity() const -> int32_t
Get the current proximity value in the range [0, 255].
auto getRGB() const -> pros::c::optical_rgb_s_t
Get the processed RGBC data from the sensor.
auto controllerGet() -> double override
Get the sensor value for use in a control loop.
auto enableGestures() const -> int32_t
Enable gestures.
auto disableGestures() const -> int32_t
Disable gestures.

Protected functions

auto getSelectedOutput() -> double
Gets the output directly from the sensor using the selected output.

Protected variables

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

Function documentation

okapi::OpticalSensor::OpticalSensor(std::uint8_t iport, OpticalSensorOutput ioutput = OpticalSensorOutput::hue, bool idisableGestures = true, std::unique_ptr<Filter> ifilter = std::make_unique<PassthroughFilter>())

An optical sensor on a V5 port.

Parameters
iport The V5 port the device uses.
ioutput Which sensor output to return from (okapi::OpticalSensor::get).
idisableGestures Whether to automatically disable the gesture sensor. Typically, the gesture sensor should be disabled unless you are going to use gestures because the optical sensor does not update color information while detecting a gesture.
ifilter The filter to use to filter the sensor output. Only the selected output (via ioutput) is filtered; the other outputs are untouched.
auto osHue = OpticalSensor(1);
auto osSat = OpticalSensor(1, OpticalSensorOutput::saturation);

double okapi::OpticalSensor::get()

Get the current filtered value of the selected output (configured by the constructor).

Returns The current filtered value of the selected output (configured by the constructor).

double okapi::OpticalSensor::getHue() const

Get the current hue value in the range [0, 360).

Returns The current hue value in the range [0, 360).

double okapi::OpticalSensor::getBrightness() const

Get the current brightness value in the range [0, 1].

Returns The current brightness value in the range [0, 1].

double okapi::OpticalSensor::getSaturation() const

Get the current saturation value in the range [0, 1].

Returns The current saturation value in the range [0, 1].

int32_t okapi::OpticalSensor::getLedPWM() const

Get the PWM value of the white LED in the range [0, 100].

Returns The PWM value of the white LED in the range [0, 100] or PROS_ERR if the operation failed, setting errno.

int32_t okapi::OpticalSensor::setLedPWM(std::uint8_t ivalue) const

Set the PWM value of the white LED in the range [0, 100].

Returns 1 if the operation was successful or PROS_ERR if the operation failed, setting errno.

int32_t okapi::OpticalSensor::getProximity() const

Get the current proximity value in the range [0, 255].

Returns The current proximity value in the range [0, 255].

This is not available if gestures are being detected.

pros::c::optical_rgb_s_t okapi::OpticalSensor::getRGB() const

Get the processed RGBC data from the sensor.

Returns The RGBC value if the operation was successful. If the operation failed, all field are set to PROS_ERR and errno is set.

double okapi::OpticalSensor::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.

int32_t okapi::OpticalSensor::enableGestures() const

Enable gestures.

Returns 1 if the operation was successful or PROS_ERR if the operation failed, setting errno.

int32_t okapi::OpticalSensor::disableGestures() const

Disable gestures.

Returns 1 if the operation was successful or PROS_ERR if the operation failed, setting errno.