bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
line_following_infrared_sonar::InfraredSensor Class Referencefinal

An array of infrared reflectance elements that looks at the floor, to tell its colour: light paper or a dark line. More...

#include <infrared_sensor.h>

Inheritance diagram for line_following_infrared_sonar::InfraredSensor:
Collaboration diagram for line_following_infrared_sonar::InfraredSensor:

Public Member Functions

 InfraredSensor (std::shared_ptr< backends::InfraredBackendBase > backend, const std::string &name=consts::INVALID_STR)
void init () override
 Enable the sensor, with every element reading white until the first read.
const std::vector< real_t > & read_values () override
 Read the backend, if the sensor is enabled.
std::string backend_type_str () const override
std::string sensor_units () const override
std::shared_ptr< backends::SensorBackendBase > backend_ptr () const override
std::shared_ptr< backends::InfraredBackendBase > infrared_backend () const noexcept
uint_t n_elements () const noexcept
std::optional< std::array< real_t, 2 > > line_position () const
std::string pattern () const
real_t threshold () const noexcept
 Reflectances below this are dark.
void set_threshold (real_t threshold)
bool is_dark (uint_t i) const
Public Member Functions inherited from bitsim::sensors::SensorBase
virtual ~SensorBase ()=default
 Destructor.
bool is_enabled () const noexcept
 Returns true if the sensor is enabled.
void enable () noexcept
 Set the is_enabled_ flag to true.
void disable () noexcept
 Disable the sensor.
const std::vector< real_t > & last_read_values () const noexcept
std::string sensor_name () const noexcept
void set_sensor_name (const std::string &sensor_name) noexcept
 Set the sensor name.
std::string sensor_type () const noexcept

Static Public Member Functions

static std::shared_ptr< InfraredSensor > create (const std::string &backend_type, const std::string &name)
 A sensor with a new backend of the given type, see backends::InfraredBackendBase::create.

Static Public Attributes

static const std::string SENSOR_TYPE = "InfraredSensor"
 The type of the sensor.

Additional Inherited Members

Protected Member Functions inherited from bitsim::sensors::SensorBase
 SensorBase (const std::string &sensor_type, const std::string &sensor_name=bitsim::consts::INVALID_STR)
Protected Attributes inherited from bitsim::sensors::SensorBase
std::vector< real_t > values_
 The values last read by the sensor.
std::shared_ptr< backends::SensorBackendBase > backend_ptr_
 Pointer to backend tha actually handles the sensor.

Detailed Description

An array of infrared reflectance elements that looks at the floor, to tell its colour: light paper or a dark line.

read_values() gives the reflectance under each element, from 0 for black to 1 for white. An element whose reflectance is below threshold() is over something dark; see is_dark(). Where the values come from is up to the backend: backends::CHRONO_InfraredBackend simulates the elements, and backends::MQTT_InfraredBackend reads real ones on a board.

Constructor & Destructor Documentation

◆ InfraredSensor()

bitsim::sensors::InfraredSensor::InfraredSensor ( std::shared_ptr< backends::InfraredBackendBase > backend,
const std::string & name = consts::INVALID_STR )
explicit

Member Function Documentation

◆ backend_ptr()

std::shared_ptr< backends::SensorBackendBase > bitsim::sensors::InfraredSensor::backend_ptr ( ) const
inlineoverridevirtual

Reimplemented from bitsim::sensors::SensorBase.

◆ backend_type_str()

std::string bitsim::sensors::InfraredSensor::backend_type_str ( ) const
inlineoverridevirtual
Returns
An instance of std::string of the backend type. If the implementation does not use a specific backend returns bitsim::consts::INVALID_STR

Implements bitsim::sensors::SensorBase.

◆ create()

std::shared_ptr< InfraredSensor > bitsim::sensors::InfraredSensor::create ( const std::string & backend_type,
const std::string & name )
static

A sensor with a new backend of the given type, see backends::InfraredBackendBase::create.

◆ infrared_backend()

std::shared_ptr< backends::InfraredBackendBase > bitsim::sensors::InfraredSensor::infrared_backend ( ) const
inlinenoexcept
Returns
The backend, with the positions of the elements

◆ init()

void bitsim::sensors::InfraredSensor::init ( )
overridevirtual

Enable the sensor, with every element reading white until the first read.

Implements bitsim::sensors::SensorBase.

◆ is_dark()

Returns
True if element i was over something dark at the last read

◆ line_position()

std::optional< std::array< real_t, 2 > > bitsim::sensors::InfraredSensor::line_position ( ) const
Returns
Where the line is under the elements, in the body's frame [m]: the mean of the positions of the elements that see it, x and y; nothing if none does

◆ n_elements()

Returns
The number of elements

◆ pattern()

Returns
Which elements are over something dark, left to right: "#" for dark and "." for light, such as ".#." with the line under the middle element

◆ read_values()

const std::vector< real_t > & bitsim::sensors::InfraredSensor::read_values ( )
overridevirtual

Read the backend, if the sensor is enabled.

Returns
The reflectance under each element

Implements bitsim::sensors::SensorBase.

◆ sensor_units()

std::string bitsim::sensors::InfraredSensor::sensor_units ( ) const
inlineoverridevirtual
Returns
An instance of std::string indicating the units the sensor is using. If units have not been established this returns bitsim::consts::INVALID_STR

Implements bitsim::sensors::SensorBase.

◆ set_threshold()

◆ threshold()

Reflectances below this are dark.

Member Data Documentation

◆ SENSOR_TYPE

const std::string bitsim::sensors::InfraredSensor::SENSOR_TYPE = "InfraredSensor"
static

The type of the sensor.


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