bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
bitsim::sensors::backends::InfraredBackendBase Class Reference

Base class for arrays of infrared reflectance sensors, such as the TCRT5000 modules that line following robots use. More...

#include <infrared_backend_base.h>

Inheritance diagram for bitsim::sensors::backends::InfraredBackendBase:
Collaboration diagram for bitsim::sensors::backends::InfraredBackendBase:

Public Types

using Position = std::array<real_t, 3>
 The position of an element on the robot's body [m].

Public Member Functions

const std::vector< Position > & elements () const noexcept
void set_elements (const std::vector< Position > &elements)
 Set the positions of the elements on the body. One value is read per element.
uint_t n_elements () const noexcept
std::string sensor_units () const override
virtual void load (const nlohmann::json &j)
 Read the settings of the sensor from its section of a robot or sensor file:
void load_from_json (const std::string &filename) override
 Read the settings from a JSON file, see load().
void add_visual_shape (const std::unordered_map< std::string, std::any > &shape_properties) override
 Draw each element as a small box on the body. The properties are x_length, y_length, z_length (float_t) and chrono::ChColor.
Public Member Functions inherited from bitsim::sensors::backends::SensorBackendBase
virtual ~SensorBackendBase ()=default
 Destructor.
real_t sampling_period () const noexcept
 Returns the sampling period of the sensor.
void set_sampling_period (real_t period)
 Set the sampling period of the backend.
virtual std::vector< real_t > read_values ()=0
 Read the sensor value.
uint_t n_read_values () const noexcept
std::string backend_type_str () const noexcept
 Return a string that specifies the type of the backend.
void set_chrono_body (std::shared_ptr< chrono::ChBody > body)
 Set the pointer to the body that this sensor is attached.

Static Public Member Functions

static std::shared_ptr< InfraredBackendBase > create (const std::string &backend_type)
 Create a backend by the name a robot file gives it.

Protected Member Functions

 InfraredBackendBase (const std::string &backend_type)
Protected Member Functions inherited from bitsim::sensors::backends::SensorBackendBase
 SensorBackendBase (const std::string &backend_type)
 Constructor.
void set_n_read_values (uint_t n) noexcept
 Set how many values the implementation returns.

Additional Inherited Members

Protected Attributes inherited from bitsim::sensors::backends::SensorBackendBase
std::shared_ptr< chrono::ChBody > body_ {nullptr}
 The body on which the sensor sits.

Detailed Description

Base class for arrays of infrared reflectance sensors, such as the TCRT5000 modules that line following robots use.

Each element shines infrared light at the floor just below it and measures how much comes back. White paper reflects most of it and a black line very little, so the elements tell the colour of the floor under them. A backend reads one value per element: the reflectance, from 0 for black to 1 for white.

Member Typedef Documentation

◆ Position

The position of an element on the robot's body [m].

Constructor & Destructor Documentation

◆ InfraredBackendBase()

bitsim::sensors::backends::InfraredBackendBase::InfraredBackendBase ( const std::string & backend_type)
inlineexplicitprotected

Member Function Documentation

◆ add_visual_shape()

void bitsim::sensors::backends::InfraredBackendBase::add_visual_shape ( const std::unordered_map< std::string, std::any > & shape_properties)
overridevirtual

Draw each element as a small box on the body. The properties are x_length, y_length, z_length (float_t) and chrono::ChColor.

Implements bitsim::sensors::backends::SensorBackendBase.

◆ create()

std::shared_ptr< InfraredBackendBase > bitsim::sensors::backends::InfraredBackendBase::create ( const std::string & backend_type)
static

Create a backend by the name a robot file gives it.

Parameters
backend_typeSIMULATION (or CHRONO) for elements simulated with Chrono, MQTT for real elements on a board
Exceptions
std::runtime_errorIf the type is unknown, or bitsim was built without what the backend needs

◆ elements()

const std::vector< Position > & bitsim::sensors::backends::InfraredBackendBase::elements ( ) const
inlinenoexcept
Returns
The positions of the elements on the body, in the order of the values

◆ load()

void bitsim::sensors::backends::InfraredBackendBase::load ( const nlohmann::json & j)
virtual

Read the settings of the sensor from its section of a robot or sensor file:

  • elements: [[x, y, z], ...], the positions of the elements on the body [m]
  • update_rate, readings per second [1/s], optional

Backends read their own keys as well

Reimplemented in bitsim::sensors::backends::MQTT_InfraredBackend.

◆ load_from_json()

void bitsim::sensors::backends::InfraredBackendBase::load_from_json ( const std::string & filename)
overridevirtual

Read the settings from a JSON file, see load().

Implements bitsim::sensors::backends::SensorBackendBase.

◆ n_elements()

uint_t bitsim::sensors::backends::InfraredBackendBase::n_elements ( ) const
inlinenoexcept
Returns
The number of elements

◆ sensor_units()

std::string bitsim::sensors::backends::InfraredBackendBase::sensor_units ( ) const
inlineoverridevirtual
Returns
REFLECTANCE: the values are shares of the light, in [0, 1]

Reimplemented from bitsim::sensors::backends::SensorBackendBase.

◆ set_elements()

void bitsim::sensors::backends::InfraredBackendBase::set_elements ( const std::vector< Position > & elements)

Set the positions of the elements on the body. One value is read per element.


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