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

Base class for modelling range sensors. More...

#include <range_sensor_backend_base.h>

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

Public Member Functions

real_t max_distance () const noexcept
void set_max_distance (real_t max_distance) noexcept
 Set the maximum distance the range sensor can read.
real_t min_distance () const noexcept
void set_min_distance (real_t min_distance) noexcept
 Set the minimum distance the range sensor can read.
virtual std::string sensor_units () const
void set_sensor_units (const std::string &units)
 Set the sensor units.
virtual void load (const nlohmann::json &j)
 Read the settings of the sensor from its section of a robot or sensor file. Every key is optional:
void load_from_json (const std::string &filename) override
 Read the settings from a JSON file, see load().
virtual void add_visual_shape (const std::unordered_map< std::string, std::any > &shape_properties) override
 Add a visual shape for the sensor in order to be visualized with Irrlicht. Concrete classes may choose not to implement this. In this case the sensor will not be visible.
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< RangeSensorBackendBase > create (const std::string &backend_type)
 Create a backend by the name a robot file gives it.

Protected Member Functions

 RangeSensorBackendBase (const std::string &backend_type)
 Constructor.
real_t clamp_distance (real_t distance) const noexcept
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 modelling range sensors.

A range sensor measures the distance to the nearest obstacle in front of it, between min_distance() and max_distance(). Closer than min_distance() it reports min_distance(), and with nothing in range max_distance().

Constructor & Destructor Documentation

◆ RangeSensorBackendBase()

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

Constructor.

Parameters
backend_type

Member Function Documentation

◆ add_visual_shape()

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

Add a visual shape for the sensor in order to be visualized with Irrlicht. Concrete classes may choose not to implement this. In this case the sensor will not be visible.

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

◆ clamp_distance()

real_t bitsim::sensors::backends::RangeSensorBackendBase::clamp_distance ( real_t distance) const
protectednoexcept
Returns
The distance clamped to [min_distance(), max_distance()]

◆ create()

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

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

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

◆ load()

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

Read the settings of the sensor from its section of a robot or sensor file. Every key is optional:

Backends read their own keys as well

Reimplemented in bitsim::sensors::backends::CHRONO_UltrasonicBackend, and bitsim::sensors::backends::MQTT_UltrasonicBackend.

◆ load_from_json()

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

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

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

◆ max_distance()

real_t bitsim::sensors::backends::RangeSensorBackendBase::max_distance ( ) const
inlinenoexcept
Returns
The maximum distance the range sensor can read

◆ min_distance()

real_t bitsim::sensors::backends::RangeSensorBackendBase::min_distance ( ) const
inlinenoexcept
Returns
The minimum distance the range sensor can read

◆ sensor_units()

virtual std::string bitsim::sensors::backends::RangeSensorBackendBase::sensor_units ( ) const
inlinevirtual
Returns
An instance of std::string representing the units the sensor readings are assumed in

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

◆ set_max_distance()

void bitsim::sensors::backends::RangeSensorBackendBase::set_max_distance ( real_t max_distance)
inlinenoexcept

Set the maximum distance the range sensor can read.

Parameters
max_distance

◆ set_min_distance()

void bitsim::sensors::backends::RangeSensorBackendBase::set_min_distance ( real_t min_distance)
inlinenoexcept

Set the minimum distance the range sensor can read.

Parameters
min_distance

◆ set_sensor_units()

void bitsim::sensors::backends::RangeSensorBackendBase::set_sensor_units ( const std::string & units)
inline

Set the sensor units.

Parameters
unitsThe string representing the sensor units

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