bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
sensor_backend_base.h
Go to the documentation of this file.
1#ifndef BITSIM_SENSORS_BACKENDS_SENSOR_BACKEND_BASE_H
2#define BITSIM_SENSORS_BACKENDS_SENSOR_BACKEND_BASE_H
3
4#include "bitsim/bitsim_config.h"
7
8#ifdef BITSIM_CHRONO
9#include <any>
10#include <chrono/physics/ChBody.h>
11#include <unordered_map>
12#endif
13
14#include <string>
15#include <vector>
16
17namespace bitsim
18{
19namespace sensors::backends
20{
21
29{
30 public:
34 virtual ~SensorBackendBase() = default;
35
40 real_t sampling_period() const noexcept { return sampling_period_; }
41
46 void set_sampling_period(real_t period) { sampling_period_ = period; }
47
52 virtual std::vector<real_t> read_values() = 0;
53
58 virtual std::string sensor_units() const { return bitsim::consts::INVALID_STR; }
59
77 virtual void load_from_json(const std::string &filename) = 0;
78
82 uint_t n_read_values() const noexcept { return n_read_values_; }
83
88 std::string backend_type_str() const noexcept { return backend_type_; }
89
90#ifdef BITSIM_CHRONO
96 virtual void
97 add_visual_shape(const std::unordered_map<std::string, std::any> &shape_properties) = 0;
98
101 void set_chrono_body(std::shared_ptr<chrono::ChBody> body) { body_ = body; }
102#endif
103
104 protected:
109 SensorBackendBase(const std::string &backend_type);
110
114 void set_n_read_values(uint_t n) noexcept { n_read_values_ = n; }
115
116#ifdef BITSIM_CHRONO
120 std::shared_ptr<chrono::ChBody> body_{nullptr};
121#endif
122
123 private:
127 const std::string backend_type_;
128
132 real_t sampling_period_{0.0};
133
137 uint_t n_read_values_{1};
138};
139
140inline SensorBackendBase::SensorBackendBase(const std::string &backend_type)
141 : backend_type_(backend_type)
142{
143}
144
145} // namespace sensors::backends
146} // namespace bitsim
147
148#endif // BITSIM_SENSORS_BACKENDS_SENSOR_BACKEND_BASE_H
The basic types of bitsim. Code outside this file names Eigen's matrix and vector types only through ...
SensorBackendBase(const std::string &backend_type)
Constructor.
Definition sensor_backend_base.h:140
real_t sampling_period() const noexcept
Returns the sampling period of the sensor.
Definition sensor_backend_base.h:40
virtual ~SensorBackendBase()=default
Destructor.
std::shared_ptr< chrono::ChBody > body_
The body on which the sensor sits.
Definition sensor_backend_base.h:120
void set_chrono_body(std::shared_ptr< chrono::ChBody > body)
Set the pointer to the body that this sensor is attached.
Definition sensor_backend_base.h:101
uint_t n_read_values() const noexcept
Definition sensor_backend_base.h:82
std::string backend_type_str() const noexcept
Return a string that specifies the type of the backend.
Definition sensor_backend_base.h:88
virtual std::string sensor_units() const
Definition sensor_backend_base.h:58
virtual std::vector< real_t > read_values()=0
Read the sensor value.
virtual void add_visual_shape(const std::unordered_map< std::string, std::any > &shape_properties)=0
Add a visual shape for the sensor in order to be visualized with Irrlicht. Concrete classes may choos...
void set_sampling_period(real_t period)
Set the sampling period of the backend.
Definition sensor_backend_base.h:46
virtual void load_from_json(const std::string &filename)=0
Load robot and simulation parameters from a JSON file.
void set_n_read_values(uint_t n) noexcept
Set how many values the implementation returns.
Definition sensor_backend_base.h:114
const std::string INVALID_STR
Invalid string.
Definition bitsim_consts.h:21
Definition camera_backend_base.h:19
Definition dc_motor_backend_base.h:9
std::size_t uint_t
uint_t
Definition bitsim_types.h:40
double real_t
real_t
Definition bitsim_types.h:20