bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
range_sensor_backend_base.h
Go to the documentation of this file.
1#ifndef BITSIM_SENSORS_BACKENDS_RANGE_SENSOR_BACKEND_BASE_H
2#define BITSIM_SENSORS_BACKENDS_RANGE_SENSOR_BACKEND_BASE_H
3
4#include "bitsim/bitsim_config.h"
6#include "bitsim/extern/nlohmann/json/json.hpp"
8#include <memory>
9#include <string>
10
11#ifdef BITSIM_CHRONO
12#include <any>
13#include <unordered_map>
14#endif
15
16namespace bitsim
17{
18namespace sensors::backends
19{
30{
31 public:
39 static std::shared_ptr<RangeSensorBackendBase> create(const std::string &backend_type);
40
44 real_t max_distance() const noexcept { return max_distance_; }
45
50 void set_max_distance(real_t max_distance) noexcept { max_distance_ = max_distance; }
51
55 real_t min_distance() const noexcept { return min_distance_; }
56
61 void set_min_distance(real_t min_distance) noexcept { min_distance_ = min_distance; }
62
67 virtual std::string sensor_units() const { return sensor_units_; }
68
73 void set_sensor_units(const std::string &units) { sensor_units_ = units; }
74
85 virtual void load(const nlohmann::json &j);
86
90 void load_from_json(const std::string &filename) override;
91
92#ifdef BITSIM_CHRONO
98 virtual void
99 add_visual_shape(const std::unordered_map<std::string, std::any> &shape_properties) override;
100#endif
101
102 protected:
107 explicit RangeSensorBackendBase(const std::string &backend_type);
108
112 real_t clamp_distance(real_t distance) const noexcept;
113
114 private:
115 std::string sensor_units_{"METERS"};
116
120 real_t max_distance_{0.0};
121
125 real_t min_distance_{0.0};
126};
127
128inline RangeSensorBackendBase::RangeSensorBackendBase(const std::string &backend_type)
129 : SensorBackendBase(backend_type)
130{
131}
132
133} // namespace sensors::backends
134} // namespace bitsim
135
136#endif // BITSIM_SENSORS_BACKENDS_RANGE_SENSOR_BACKEND_BASE_H
The basic types of bitsim. Code outside this file names Eigen's matrix and vector types only through ...
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:
Definition range_sensor_backend_base.cpp:43
RangeSensorBackendBase(const std::string &backend_type)
Constructor.
Definition range_sensor_backend_base.h:128
real_t min_distance() const noexcept
Definition range_sensor_backend_base.h:55
real_t clamp_distance(real_t distance) const noexcept
Definition range_sensor_backend_base.cpp:73
virtual std::string sensor_units() const
Definition range_sensor_backend_base.h:67
real_t max_distance() const noexcept
Definition range_sensor_backend_base.h:44
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 choos...
Definition range_sensor_backend_base.cpp:79
void set_min_distance(real_t min_distance) noexcept
Set the minimum distance the range sensor can read.
Definition range_sensor_backend_base.h:61
void load_from_json(const std::string &filename) override
Read the settings from a JSON file, see load().
Definition range_sensor_backend_base.cpp:63
void set_sensor_units(const std::string &units)
Set the sensor units.
Definition range_sensor_backend_base.h:73
void set_max_distance(real_t max_distance) noexcept
Set the maximum distance the range sensor can read.
Definition range_sensor_backend_base.h:50
static std::shared_ptr< RangeSensorBackendBase > create(const std::string &backend_type)
Create a backend by the name a robot file gives it.
Definition range_sensor_backend_base.cpp:19
SensorBackendBase(const std::string &backend_type)
Constructor.
Definition sensor_backend_base.h:140
Definition camera_backend_base.h:19
Definition dc_motor_backend_base.h:9
double real_t
real_t
Definition bitsim_types.h:20