Bayes Filters Library
SimulatedLinearSensor.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016-2019 Istituto Italiano di Tecnologia (IIT)
3  *
4  * This software may be modified and distributed under the terms of the
5  * BSD 3-Clause license. See the accompanying LICENSE file for details.
6  */
7 
10 
11 using namespace bfl;
12 using namespace Eigen;
13 
14 
16 
17 
19 (
20  std::unique_ptr<SimulatedStateModel> simulated_state_model,
21  const LinearMatrixComponent& linear_matrix_component,
22  const Eigen::Ref<const Eigen::MatrixXd>& noise_covariance_matrix,
23  const unsigned int seed
24 ) :
25  LinearModel(linear_matrix_component, noise_covariance_matrix, seed),
26  simulated_state_model_(std::move(simulated_state_model))
27 {
28  /* Since a LinearSensor is intended as a sensor that measure
29  * the state directly (i.e. no linear combination of the states),
30  * then it is possible to extract input and measurement descriptions
31  * from the state description of the simulated state model.
32  */
33 
34  /* Input description. */
35  input_description_ = simulated_state_model_->getStateModel().getStateDescription();
36 
37  /* The number of noise components depend on the size of the noise covariance matrix. */
38  MatrixXd noise_covariance;
39  bool valid_noise_covariance;
40  std::tie(valid_noise_covariance, noise_covariance) = getNoiseCovarianceMatrix();
41  if (!valid_noise_covariance)
42  throw(std::runtime_error("ERROR:SIMULATEDLINEARSENSOR::CTOR. A valid noise covariance matrix from getNoiseCovarianceMatrix() is required."));
43  input_description_.add_noise_components(noise_covariance.rows());
44 
45  /* Measurement description.
46  *
47  * FIXME:
48  * Check if this works in presence of quaternions too.
49  */
50  std::size_t meas_linear_size = 0;
51  std::size_t meas_circular_size = 0;
52 
53  for (std::size_t i = 0; i < H_.rows(); ++i)
54  {
55  Eigen::MatrixXf::Index state_index;
56  H_.row(i).array().abs().maxCoeff(&state_index);
57 
58  if (state_index < input_description_.linear_size())
59  meas_linear_size++;
60  else
61  meas_circular_size++;
62  }
63  measurement_description_ = VectorDescription(meas_linear_size, meas_circular_size);
64 }
65 
66 
68 (
69  std::unique_ptr<SimulatedStateModel> simulated_state_model,
70  const LinearMatrixComponent& linear_matrix_component,
71  const Eigen::Ref<const Eigen::MatrixXd>& noise_covariance_matrix
72 ) :
73  SimulatedLinearSensor(std::move(simulated_state_model), linear_matrix_component, noise_covariance_matrix, 1)
74 { }
75 
76 
78 {
79  if (!simulated_state_model_->bufferData())
80  return false;
81 
82  measurement_ = H_ * any::any_cast<MatrixXd>(simulated_state_model_->getData());
83 
84  MatrixXd noise;
85  std::tie(std::ignore, noise) = getNoiseSample(measurement_.cols());
86 
87  measurement_ += noise;
88 
89  log();
90 
91  return true;
92 }
93 
94 
95 std::pair<bool, Data> SimulatedLinearSensor::measure(const Data& data) const
96 {
97  return std::make_pair(true, measurement_);
98 }
99 
100 
102 {
103  return input_description_;
104 }
105 
106 
108 {
110 }
111 
112 
114 {
115  logger(measurement_.transpose());
116 }
bfl::LinearModel
Definition: LinearModel.h:24
bfl::SimulatedLinearSensor::input_description_
VectorDescription input_description_
Definition: SimulatedLinearSensor.h:44
bfl::SimulatedLinearSensor::measure
std::pair< bool, bfl::Data > measure(const Data &data=Data()) const override
Definition: SimulatedLinearSensor.cpp:95
bfl::SimulatedLinearSensor
Definition: SimulatedLinearSensor.h:22
bfl::Logger::logger
void logger(DatumType datum)
Definition: Logger.h:35
bfl::SimulatedLinearSensor::~SimulatedLinearSensor
virtual ~SimulatedLinearSensor() noexcept
SimulatedLinearSensor.h
bfl
Port of boost::any for C++11 compilers.
Definition: AdditiveMeasurementModel.h:13
bfl::SimulatedLinearSensor::measurement_
Eigen::MatrixXd measurement_
Definition: SimulatedLinearSensor.h:42
bfl::SimulatedLinearSensor::getInputDescription
VectorDescription getInputDescription() const override
Definition: SimulatedLinearSensor.cpp:101
bfl::SimulatedLinearSensor::SimulatedLinearSensor
SimulatedLinearSensor(std::unique_ptr< bfl::SimulatedStateModel > simulated_state_model, const LinearMatrixComponent &linear_matrix_component, const Eigen::Ref< const Eigen::MatrixXd > &noise_covariance_matrix, const unsigned int seed)
bfl::SimulatedLinearSensor::freeze
bool freeze(const Data &data=Data()) override
Definition: SimulatedLinearSensor.cpp:77
VectorDescription.h
bfl::SimulatedLinearSensor::getMeasurementDescription
VectorDescription getMeasurementDescription() const override
Definition: SimulatedLinearSensor.cpp:107
bfl::LTIMeasurementModel::H_
Eigen::MatrixXd H_
Measurement matrix.
Definition: LTIMeasurementModel.h:39
bfl::SimulatedLinearSensor::measurement_description_
VectorDescription measurement_description_
Definition: SimulatedLinearSensor.h:46
bfl::LinearModel::getNoiseSample
std::pair< bool, Eigen::MatrixXd > getNoiseSample(const int num) const
Definition: LinearModel.cpp:51
bfl::SimulatedStateModel
Definition: SimulatedStateModel.h:23
bfl::SimulatedLinearSensor::log
void log() override
Definition: SimulatedLinearSensor.cpp:113
bfl::any::any
The class any describes a type-safe container for single values of any type.
Definition: any.h:77
bfl::SimulatedLinearSensor::simulated_state_model_
std::unique_ptr< bfl::SimulatedStateModel > simulated_state_model_
Definition: SimulatedLinearSensor.h:40
bfl::VectorDescription
Definition: VectorDescription.h:18