bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
sensor_base.h
Go to the documentation of this file.
1#ifndef BITSIM_SENSORS_SENSOR_BASE_H
2#define BITSIM_SENSORS_SENSOR_BASE_H
3
4#include "../bitsim_consts.h"
8
9#include <string>
10#include <vector>
11namespace bitsim
12{
13namespace sensors
14{
27{
28 public:
32 virtual ~SensorBase() = default;
33
38 virtual void init() = 0;
39
43 virtual const std::vector<real_t> &read_values() = 0;
44
49 virtual std::string backend_type_str() const = 0;
50
55 virtual std::string sensor_units() const = 0;
56
61 bool is_enabled() const noexcept { return is_enabled_; }
62
66 void enable() noexcept { is_enabled_ = true; }
67
71 void disable() noexcept { is_enabled_ = false; }
72
76 const std::vector<real_t> &last_read_values() const noexcept { return values_; }
77
81 std::string sensor_name() const noexcept { return sensor_name_; }
82
87 void set_sensor_name(const std::string &sensor_name) noexcept { sensor_name_ = sensor_name; }
88
92 std::string sensor_type() const noexcept { return sensor_type_; }
93
94 virtual std::shared_ptr<backends::SensorBackendBase> backend_ptr() const
95 {
96 return backend_ptr_;
97 }
98
99 protected:
104 explicit SensorBase(const std::string &sensor_type,
105 const std::string &sensor_name = bitsim::consts::INVALID_STR);
106
110 std::vector<real_t> values_;
111
115 std::shared_ptr<backends::SensorBackendBase> backend_ptr_;
116
117 private:
121 const std::string sensor_type_;
122
126 std::string sensor_name_{bitsim::consts::INVALID_STR};
127
131 bool is_enabled_{false};
132};
133
134inline SensorBase::SensorBase(const std::string &sensor_type, const std::string &sensor_name)
135 : values_(), sensor_type_(sensor_type), sensor_name_(sensor_name)
136{
137}
138
139} // namespace sensors
140} // namespace bitsim
141
142#endif // BITSIM_SENSORS_SENSOR_BASE_H
The basic types of bitsim. Code outside this file names Eigen's matrix and vector types only through ...
virtual ~SensorBase()=default
Destructor.
virtual std::string backend_type_str() const =0
Definition sensor_base.cpp:10
virtual std::shared_ptr< backends::SensorBackendBase > backend_ptr() const
Definition sensor_base.h:94
std::vector< real_t > values_
The values last read by the sensor.
Definition sensor_base.h:110
std::string sensor_type() const noexcept
Definition sensor_base.h:92
std::shared_ptr< backends::SensorBackendBase > backend_ptr_
Pointer to backend tha actually handles the sensor.
Definition sensor_base.h:115
virtual std::string sensor_units() const =0
Definition sensor_base.cpp:11
virtual void init()=0
Initialize the sensor. Set the is is_enabled_ flag to true. and performs any other initializations re...
void set_sensor_name(const std::string &sensor_name) noexcept
Set the sensor name.
Definition sensor_base.h:87
const std::vector< real_t > & last_read_values() const noexcept
Definition sensor_base.h:76
void disable() noexcept
Disable the sensor.
Definition sensor_base.h:71
bool is_enabled() const noexcept
Returns true if the sensor is enabled.
Definition sensor_base.h:61
std::string sensor_name() const noexcept
Definition sensor_base.h:81
virtual const std::vector< real_t > & read_values()=0
SensorBase(const std::string &sensor_type, const std::string &sensor_name=bitsim::consts::INVALID_STR)
Definition sensor_base.h:134
void enable() noexcept
Set the is_enabled_ flag to true.
Definition sensor_base.h:66
const std::string INVALID_STR
Invalid string.
Definition bitsim_consts.h:21
Definition infrared_line_follower.h:9
Definition dc_motor_backend_base.h:9