bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
infrared_sensor.h
Go to the documentation of this file.
1#ifndef BITSIM_SENSORS_INFRARED_SENSOR_H
2#define BITSIM_SENSORS_INFRARED_SENSOR_H
3
8
9#include <array>
10#include <memory>
11#include <optional>
12#include <string>
13#include <vector>
14
15namespace bitsim
16{
17namespace sensors
18{
19
32class InfraredSensor final : public SensorBase
33{
34 public:
38 static const std::string SENSOR_TYPE;
39
44 static std::shared_ptr<InfraredSensor> create(const std::string &backend_type,
45 const std::string &name);
46
47 explicit InfraredSensor(std::shared_ptr<backends::InfraredBackendBase> backend,
48 const std::string &name = consts::INVALID_STR);
49
54 void init() override;
55
60 const std::vector<real_t> &read_values() override;
61
62 std::string backend_type_str() const override { return backend_->backend_type_str(); }
63
64 std::string sensor_units() const override { return backend_->sensor_units(); }
65
66 std::shared_ptr<backends::SensorBackendBase> backend_ptr() const override { return backend_; }
67
71 std::shared_ptr<backends::InfraredBackendBase> infrared_backend() const noexcept
72 {
73 return backend_;
74 }
75
79 uint_t n_elements() const noexcept { return backend_->n_elements(); }
80
85 std::optional<std::array<real_t, 2>> line_position() const;
86
91 std::string pattern() const;
92
96 real_t threshold() const noexcept { return threshold_; }
98
102 bool is_dark(uint_t i) const;
103
104 private:
105 std::shared_ptr<backends::InfraredBackendBase> backend_;
106 real_t threshold_{0.5};
107};
108
109} // namespace sensors
110} // namespace bitsim
111
112#endif // BITSIM_SENSORS_INFRARED_SENSOR_H
The basic types of bitsim. Code outside this file names Eigen's matrix and vector types only through ...
std::string backend_type_str() const override
Definition infrared_sensor.h:62
void set_threshold(real_t threshold)
Definition infrared_sensor.cpp:53
const std::vector< real_t > & read_values() override
Read the backend, if the sensor is enabled.
Definition infrared_sensor.cpp:35
std::shared_ptr< backends::InfraredBackendBase > infrared_backend() const noexcept
Definition infrared_sensor.h:71
void init() override
Enable the sensor, with every element reading white until the first read.
Definition infrared_sensor.cpp:29
uint_t n_elements() const noexcept
Definition infrared_sensor.h:79
real_t threshold() const noexcept
Reflectances below this are dark.
Definition infrared_sensor.h:96
static std::shared_ptr< InfraredSensor > create(const std::string &backend_type, const std::string &name)
A sensor with a new backend of the given type, see backends::InfraredBackendBase::create.
Definition infrared_sensor.cpp:12
InfraredSensor(std::shared_ptr< backends::InfraredBackendBase > backend, const std::string &name=consts::INVALID_STR)
Definition infrared_sensor.cpp:19
std::string pattern() const
Definition infrared_sensor.cpp:86
static const std::string SENSOR_TYPE
The type of the sensor.
Definition infrared_sensor.h:38
std::string sensor_units() const override
Definition infrared_sensor.h:64
std::optional< std::array< real_t, 2 > > line_position() const
Definition infrared_sensor.cpp:64
std::shared_ptr< backends::SensorBackendBase > backend_ptr() const override
Definition infrared_sensor.h:66
bool is_dark(uint_t i) const
Definition infrared_sensor.cpp:62
SensorBase(const std::string &sensor_type, const std::string &sensor_name=bitsim::consts::INVALID_STR)
Definition sensor_base.h:134
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
std::size_t uint_t
uint_t
Definition bitsim_types.h:40
double real_t
real_t
Definition bitsim_types.h:20