disturbances.h
Go to the documentation of this file.
1 /*********************************************************************
2  *
3  * Software License Agreement
4  *
5  * Copyright (c) 2020,
6  * TU Dortmund - Institute of Control Theory and Systems Engineering.
7  * All rights reserved.
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <https://www.gnu.org/licenses/>.
21  *
22  * Authors: Christoph Rösmann
23  *********************************************************************/
24 
25 #ifndef SRC_PLANTS_INCLUDE_CORBO_PLANTS_DISTURBANCES_H_
26 #define SRC_PLANTS_INCLUDE_CORBO_PLANTS_DISTURBANCES_H_
27 
29 
30 #include <memory>
31 #include <random>
32 
33 namespace corbo {
34 
36 {
37  public:
38  using Ptr = std::shared_ptr<DisturbanceGaussianNoise>;
39 
42 
43  // implements interface method
44  DisturbanceInterface::Ptr getInstance() const override { return std::make_shared<DisturbanceGaussianNoise>(); }
45 
46  // implements interface method
47  void disturb(const Time& t, const Eigen::Ref<const Eigen::VectorXd>& values, Eigen::Ref<Eigen::VectorXd> disturbed_values) override;
48 
50  {
51  assert(mean_vec.size() == std_vec.size());
52  _mean = mean_vec;
53  _std = std_vec;
54  }
55 
56  void setSeed(int seed);
57 
58  bool checkParameters(int values_dim, std::stringstream* issues) const override;
59 
60  // implements interface method
61  void reset() override;
62 
64 
65 #ifdef MESSAGE_SUPPORT
66  virtual void toMessage(messages::DisturbanceGaussianNoise& message) const;
69  virtual void fromMessage(const messages::DisturbanceGaussianNoise& message, std::stringstream* issues = nullptr);
70 
71  // implements interface method
72  void toMessage(messages::Disturbance& message) const override { toMessage(*message.mutable_gaussian_noise()); }
73  // implements interface method
74  void fromMessage(const messages::Disturbance& message, std::stringstream* issues = nullptr) override
75  {
76  fromMessage(message.gaussian_noise(), issues);
77  }
78 #endif
79 
80  private:
81  Eigen::VectorXd _mean;
82  Eigen::VectorXd _std;
83 
84  int _seed = 1;
85  std::mt19937 _random_engine = std::mt19937(_seed);
86  // TODO(roesmann) should we use multiple engines (1 per distribution) to avoid possible correlatons?
87 
88  std::vector<std::normal_distribution<double>> _distributions;
89 };
90 
92 
93 } // namespace corbo
94 
95 #endif // SRC_PLANTS_INCLUDE_CORBO_PLANTS_DISTURBANCES_H_
void reset() override
reset internal state
#define FACTORY_REGISTER_DISTURBANCE(type)
Representation of time stamps.
Definition: time.h:251
std::shared_ptr< DisturbanceInterface > Ptr
bool checkParameters(int values_dim, std::stringstream *issues) const override
Check the underlying parameter configuration for validity.
A matrix or vector expression mapping an existing expression.
Definition: Ref.h:192
void setParameters(const Eigen::Ref< const Eigen::VectorXd > &mean_vec, const Eigen::Ref< const Eigen::VectorXd > &std_vec)
Definition: disturbances.h:49
std::vector< std::normal_distribution< double > > _distributions
Definition: disturbances.h:88
DisturbanceInterface::Ptr getInstance() const override
Return a newly created shared instance of the implemented class.
Definition: disturbances.h:44
virtual ~DisturbanceGaussianNoise()
Virtual destructor.
Definition: disturbances.h:41
void disturb(const Time &t, const Eigen::Ref< const Eigen::VectorXd > &values, Eigen::Ref< Eigen::VectorXd > disturbed_values) override
Modify values according to the underlying disturbance model.


control_box_rst
Author(s): Christoph Rösmann
autogenerated on Mon Feb 28 2022 22:06:51