mars_lib  0.1.0.3dc76ee85e09
Modular and Robust Sensor-Fusion
empty_sensor_class.h
Go to the documentation of this file.
1 // Copyright (C) 2021 Christian Brommer, Control of Networked Systems, University of Klagenfurt, Austria.
2 //
3 // All rights reserved.
4 //
5 // This software is licensed under the terms of the BSD-2-Clause-License with
6 // no commercial use allowed, the full terms of which are made available
7 // in the LICENSE file. No license in patents is granted.
8 //
9 // You can contact the author at <christian.brommer@ieee.org>
10 
11 #ifndef GPSVELSENSORCLASS_H
12 #define GPSVELSENSORCLASS_H
13 
14 #include <mars/core_state.h>
15 #include <mars/ekf.h>
20 #include <mars/time.h>
22 #include <cmath>
23 #include <iostream>
24 #include <memory>
25 #include <string>
26 #include <utility>
27 
28 namespace mars
29 {
31 
33 {
34 private:
35 public:
36  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
37 
38  EmptySensorClass(const std::string& name, std::shared_ptr<CoreState> core_states)
39  {
40  name_ = name;
41  core_states_ = std::move(core_states);
42  const_ref_to_nav_ = false;
44 
45  std::cout << "Created: [" << this->name_ << "] Sensor" << std::endl;
46  }
47 
48  virtual ~EmptySensorClass() = default;
49 
50  EmptySensorStateType get_state(const std::shared_ptr<void>& sensor_data)
51  {
52  EmptySensorData data = *static_cast<EmptySensorData*>(sensor_data.get());
53  return data.state_;
54  }
55 
56  Eigen::MatrixXd get_covariance(const std::shared_ptr<void>& sensor_data)
57  {
58  EmptySensorData data = *static_cast<EmptySensorData*>(sensor_data.get());
59  return data.get_full_cov();
60  }
61 
62  void set_initial_calib(std::shared_ptr<void> calibration)
63  {
64  initial_calib_ = calibration;
66  }
67 
68  BufferDataType Initialize(const Time& timestamp, std::shared_ptr<void> /*sensor_data*/,
69  std::shared_ptr<CoreType> latest_core_data)
70  {
71  // EmptyMeasurementType measurement = *static_cast<EmptyMeasurementType*>(sensor_data.get());
72 
73  EmptySensorData sensor_state;
74  std::string calibration_type;
75 
76  if (this->initial_calib_provided_)
77  {
78  calibration_type = "Given";
79 
80  EmptySensorData calib = *static_cast<EmptySensorData*>(initial_calib_.get());
81 
82  sensor_state.state_ = calib.state_;
83  sensor_state.sensor_cov_ = calib.sensor_cov_;
84  }
85  else
86  {
87  std::cout << "Empty calibration AUTO init not implemented yet" << std::endl;
88  exit(EXIT_FAILURE);
89  }
90 
91  // Bypass core state for the returned object
92  BufferDataType result(std::make_shared<CoreType>(*latest_core_data.get()),
93  std::make_shared<EmptySensorData>(sensor_state));
94 
95  is_initialized_ = true;
96 
97  std::cout << "Info: Initialized [" << name_ << "] with [" << calibration_type << "] Calibration at t=" << timestamp
98  << std::endl;
99 
100  std::cout << "Info: [" << name_ << "] Calibration(rounded):" << std::endl;
101  std::cout << "\tPosition[m]: [" << sensor_state.state_.value_.transpose() << " ]" << std::endl;
102 
103  return result;
104  }
105 
106  bool CalcUpdate(const Time& /*timestamp*/, std::shared_ptr<void> /*measurement*/,
107  const CoreStateType& prior_core_state, std::shared_ptr<void> latest_sensor_data,
108  const Eigen::MatrixXd& prior_cov, BufferDataType* new_state_data)
109  {
110  // Cast the sensor measurement and prior state information
111  // EmptyMeasurementType* meas = static_cast<EmptyMeasurementType*>(measurement.get());
112  EmptySensorData* prior_sensor_data = static_cast<EmptySensorData*>(latest_sensor_data.get());
113 
114  // Extract sensor state
115  EmptySensorStateType prior_sensor_state(prior_sensor_data->state_);
116 
117  // Return Results
118  // CoreState data
119  CoreType core_data;
120  core_data.cov_ = prior_cov.block(0, 0, CoreStateType::size_error_, CoreStateType::size_error_);
121  core_data.state_ = prior_core_state;
122 
123  // SensorState data
124  std::shared_ptr<EmptySensorData> sensor_data(std::make_shared<EmptySensorData>());
125  sensor_data->set_cov(prior_cov);
126  sensor_data->state_ = prior_sensor_state;
127 
128  BufferDataType state_entry(std::make_shared<CoreType>(core_data), sensor_data);
129 
130  *new_state_data = state_entry;
131 
132  return true;
133  }
134 
136  const Eigen::MatrixXd& correction)
137  {
138  // state + error state correction
139  // with quaternion from small angle approx -> new state
140 
141  EmptySensorStateType corrected_sensor_state;
142  corrected_sensor_state.value_ = prior_sensor_state.value_ + correction.block(0, 0, 3, 1);
143  return corrected_sensor_state;
144  }
145 };
146 } // namespace mars
147 
148 #endif // GPSVELSENSORCLASS_H
The BaseSensorData class binds the sensor state and covariance matrix.
Definition: bind_sensor_data.h:29
EIGEN_MAKE_ALIGNED_OPERATOR_NEW T state_
Definition: bind_sensor_data.h:30
Eigen::MatrixXd get_full_cov() const
get_full_cov builds the full covariance matrix
Definition: bind_sensor_data.h:63
Eigen::MatrixXd sensor_cov_
covariance of the sensor states
Definition: bind_sensor_data.h:37
The BufferDataType binds the core and sensor state in form of a shared void pointer.
Definition: buffer_data_type.h:36
Definition: core_state_type.h:21
static constexpr int size_error_
Definition: core_state_type.h:38
Definition: core_type.h:19
CoreStateMatrix cov_
Definition: core_type.h:22
CoreStateType state_
Definition: core_type.h:21
Definition: empty_sensor_class.h:33
BufferDataType Initialize(const Time &timestamp, std::shared_ptr< void >, std::shared_ptr< CoreType > latest_core_data)
Initialize the state of an individual sensor.
Definition: empty_sensor_class.h:68
EIGEN_MAKE_ALIGNED_OPERATOR_NEW EmptySensorClass(const std::string &name, std::shared_ptr< CoreState > core_states)
Definition: empty_sensor_class.h:38
EmptySensorStateType ApplyCorrection(const EmptySensorStateType &prior_sensor_state, const Eigen::MatrixXd &correction)
Definition: empty_sensor_class.h:135
bool CalcUpdate(const Time &, std::shared_ptr< void >, const CoreStateType &prior_core_state, std::shared_ptr< void > latest_sensor_data, const Eigen::MatrixXd &prior_cov, BufferDataType *new_state_data)
CalcUpdate Calculates the update for an individual sensor definition.
Definition: empty_sensor_class.h:106
virtual ~EmptySensorClass()=default
void set_initial_calib(std::shared_ptr< void > calibration)
set_initial_calib Sets the calibration of an individual sensor
Definition: empty_sensor_class.h:62
EmptySensorStateType get_state(const std::shared_ptr< void > &sensor_data)
Definition: empty_sensor_class.h:50
Eigen::MatrixXd get_covariance(const std::shared_ptr< void > &sensor_data)
get_covariance Resolves a void pointer to the covariance matrix of the corresponding sensor type Each...
Definition: empty_sensor_class.h:56
Definition: empty_sensor_state_type.h:20
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Eigen::Vector3d value_
Definition: empty_sensor_state_type.h:24
std::string name_
Name of the individual sensor instance.
Definition: sensor_abs_class.h:23
bool is_initialized_
True if the sensor has been initialized.
Definition: sensor_abs_class.h:24
bool const_ref_to_nav_
True if the reference should not be estimated.
Definition: sensor_abs_class.h:27
Definition: time.h:20
Definition: update_sensor_abs_class.h:24
bool initial_calib_provided_
True if an initial calibration was provided.
Definition: update_sensor_abs_class.h:38
std::shared_ptr< CoreState > core_states_
Definition: update_sensor_abs_class.h:42
std::shared_ptr< void > initial_calib_
Definition: update_sensor_abs_class.h:37
Definition: buffer.h:27