bitrl & cuberl Documentation
Simulation engine for reinforcement learning agents
Loading...
Searching...
No Matches
sensor_base.h
Go to the documentation of this file.
1#ifndef SENSOR_BASE_H
2#define SENSOR_BASE_H
3
4
5#include "../bitrl_consts.h"
6#include "bitrl/bitrl_types.h"
8#include <vector>
9#include <string>
10namespace bitrl
11{
12namespace sensors
13{
28{
29public:
33 virtual ~SensorBase()=default;
34
39 virtual void init()=0;
40
44 virtual const std::vector<real_t>& read_values()=0;
45
50 virtual std::string backend_type_str()const=0;
51
56 virtual std::string sensor_units()const=0;
57
62 bool is_enabled()const noexcept{return is_enabled_;}
63
67 void enable()noexcept{is_enabled_=true;}
68
72 void disable()noexcept{is_enabled_=false;}
73
77 const std::vector<real_t>& last_read_values()const noexcept{return values_;}
78
82 std::string sensor_name()const noexcept{return sensor_name_;}
83
88 void set_sensor_name(const std::string& sensor_name)noexcept{sensor_name_=sensor_name;}
89
93 std::string sensor_type()const noexcept{return sensor_type_;}
94
95protected:
99 explicit SensorBase(const std::string& sensor_type,
100 const std::string& sensor_name=bitrl::consts::INVALID_STR);
101
105 std::vector<real_t> values_;
106
107private:
108
112 const std::string sensor_type_;
113
117 std::string sensor_name_{bitrl::consts::INVALID_STR};
118
122 bool is_enabled_{false};
123};
124
125inline SensorBase::SensorBase(const std::string &sensor_type, const std::string& sensor_name)
126 :
127values_(),
128sensor_type_(sensor_type),
129sensor_name_(sensor_name)
130{}
131
132
133}
134}
135
136#endif //SENSOR_BASE_H
Class for modelling sensors. The interface follows closely the interface exposed by Webots see: https...
Definition sensor_base.h:28
void set_sensor_name(const std::string &sensor_name) noexcept
Set the sensor name.
Definition sensor_base.h:88
std::string sensor_type() const noexcept
Definition sensor_base.h:93
std::vector< real_t > values_
The values last read by the sensor.
Definition sensor_base.h:105
virtual ~SensorBase()=default
Destructor.
virtual std::string backend_type_str() const =0
Definition sensor_base.cpp:10
virtual std::string sensor_units() const =0
Definition sensor_base.cpp:11
void disable() noexcept
Disable the sensor.
Definition sensor_base.h:72
const std::vector< real_t > & last_read_values() const noexcept
Definition sensor_base.h:77
SensorBase(const std::string &sensor_type, const std::string &sensor_name=bitrl::consts::INVALID_STR)
Definition sensor_base.h:125
virtual const std::vector< real_t > & read_values()=0
bool is_enabled() const noexcept
Returns true if the sensor is enabled.
Definition sensor_base.h:62
void enable() noexcept
Set the is_enabled_ flag to true.
Definition sensor_base.h:67
std::string sensor_name() const noexcept
Definition sensor_base.h:82
virtual void init()=0
Initialize the sensor. Set the is is_enabled_ flag to true. and performs any other initializations re...
const std::string INVALID_STR
Invalid string.
Definition bitrl_consts.h:26
Definition bitrl_consts.h:14