LightLib
PROS library for VEX V5: EKF/MCL localization, RAMSETE path following, high-level chassis API
Loading...
Searching...
No Matches
okapi::OpticalSensor Class Reference

#include <opticalSensor.hpp>

Inheritance diagram for okapi::OpticalSensor:
okapi::ControllerInput< double >

Public Member Functions

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

Protected Member Functions

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

Protected Attributes

std::uint8_t port
 
OpticalSensorOutput output
 
std::unique_ptr< Filterfilter
 

Detailed Description

Definition at line 20 of file opticalSensor.hpp.

Constructor & Destructor Documentation

◆ OpticalSensor()

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.

auto osHue = OpticalSensor(1);
@ saturation
The color's intensity relative to its brightness.
Parameters
iportThe V5 port the device uses.
ioutputWhich sensor output to return from (okapi::OpticalSensor::get).
idisableGesturesWhether 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.
ifilterThe filter to use to filter the sensor output. Only the selected output (via ioutput) is filtered; the other outputs are untouched.

◆ ~OpticalSensor()

virtual okapi::OpticalSensor::~OpticalSensor ( )
virtualdefault

Member Function Documentation

◆ controllerGet()

double okapi::OpticalSensor::controllerGet ( )
overridevirtual

Get the sensor value for use in a control loop.

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

Returns
The same as get.

Implements okapi::ControllerInput< double >.

◆ disableGestures()

int32_t okapi::OpticalSensor::disableGestures ( ) const

Disable gestures.

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

◆ enableGestures()

int32_t okapi::OpticalSensor::enableGestures ( ) const

Enable gestures.

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

◆ get()

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).

◆ getBrightness()

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].

◆ getHue()

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).

◆ getLedPWM()

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.

◆ getProximity()

int32_t okapi::OpticalSensor::getProximity ( ) const

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

This is not available if gestures are being detected.

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

◆ getRGB()

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.

◆ getSaturation()

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].

◆ getSelectedOutput()

double okapi::OpticalSensor::getSelectedOutput ( )
protected

Gets the output directly from the sensor using the selected output.

◆ setLedPWM()

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

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

Parameters
valueThe PWM value in the range [0, 100].
Returns
1 if the operation was successful or PROS_ERR if the operation failed, setting errno.

Member Data Documentation

◆ filter

std::unique_ptr<Filter> okapi::OpticalSensor::filter
protected

Definition at line 133 of file opticalSensor.hpp.

◆ output

OpticalSensorOutput okapi::OpticalSensor::output
protected

Definition at line 132 of file opticalSensor.hpp.

◆ port

std::uint8_t okapi::OpticalSensor::port
protected

Definition at line 131 of file opticalSensor.hpp.


The documentation for this class was generated from the following file: