ekf_cal  0.4.0
A Kalman filter-based sensor calibration package
sensor.hpp
1 // Copyright 2022 Jacob Hartzer
2 //
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program. If not, see <https://www.gnu.org/licenses/>.
15 
16 #ifndef SENSORS__SENSOR_HPP_
17 #define SENSORS__SENSOR_HPP_
18 
19 #include <memory>
20 #include <string>
21 
22 #include "ekf/ekf.hpp"
23 #include "infrastructure/debug_logger.hpp"
24 #include "sensors/sensor_message.hpp"
25 
31 class Sensor
32 {
33 public:
37  typedef struct Parameters
38  {
39  std::string name {""};
40  std::string topic {""};
41  double rate{1.0};
42  double data_log_rate {0.0};
43  std::string log_directory {""};
44  std::shared_ptr<DebugLogger> logger;
45  std::shared_ptr<EKF> ekf;
47 
52  explicit Sensor(Parameters params);
53 
58  unsigned int GetId();
59 
64  std::string GetName();
65 
70  void Callback(SensorMessage sensor_message);
71 
72 protected:
73  double m_rate;
74  unsigned int m_id;
75  std::string m_name;
76  std::shared_ptr<DebugLogger> m_logger;
77  bool m_is_initialized{false};
78 
79 private:
80  static unsigned int m_sensor_count;
81 };
82 
83 
84 bool MessageCompare(std::shared_ptr<SensorMessage> a, std::shared_ptr<SensorMessage> b);
85 
86 #endif // SENSORS__SENSOR_HPP_
Sensor message base class.
Definition: sensor_message.hpp:26
Pure base sensor class.
Definition: sensor.hpp:32
struct Sensor::Parameters Parameters
Sensor parameter structure.
std::string m_name
Sensor name.
Definition: sensor.hpp:75
double m_rate
Sensor measurement rate.
Definition: sensor.hpp:73
Sensor(Parameters params)
Sensor class constructor.
Definition: sensor.cpp:26
std::shared_ptr< DebugLogger > m_logger
Debug logger.
Definition: sensor.hpp:76
unsigned int GetId()
Sensor ID getter method.
Definition: sensor.cpp:33
void Callback(SensorMessage sensor_message)
Sensor callback function.
Definition: sensor.cpp:48
std::string GetName()
Sensor name getter method.
Definition: sensor.cpp:38
bool m_is_initialized
Sensor initialization flag.
Definition: sensor.hpp:77
unsigned int m_id
Sensor id.
Definition: sensor.hpp:74
Sensor parameter structure.
Definition: sensor.hpp:38
double rate
Update rate.
Definition: sensor.hpp:41
std::string topic
Topic.
Definition: sensor.hpp:40
double data_log_rate
Data logging rate.
Definition: sensor.hpp:42
std::shared_ptr< DebugLogger > logger
Debug logger.
Definition: sensor.hpp:44
std::string log_directory
Data logging directory.
Definition: sensor.hpp:43
std::shared_ptr< EKF > ekf
EKF to update.
Definition: sensor.hpp:45
std::string name
Name.
Definition: sensor.hpp:39