- 3.0.2 optimal control module.
FilterSettings.h
Go to the documentation of this file.
1 /**********************************************************************************************************************
2 This file is part of the Control Toolbox (https://github.com/ethz-adrl/control-toolbox), copyright by ETH Zurich.
3 Licensed under the BSD-2 license (see LICENSE file in main directory)
4 **********************************************************************************************************************/
5 
6 #pragma once
7 
8 #include <boost/property_tree/info_parser.hpp>
9 
10 namespace ct {
11 namespace optcon {
12 
14 
21 template <size_t OUTPUT_DIM, size_t STATE_DIM, typename SCALAR = double>
23 {
27  bool parametersOk() const { return true; }
32 
34  void print() const
35  {
36  std::cout << "State Observer Settings: " << std::endl;
37  std::cout << "=====================" << std::endl;
38  std::cout << "C:\n" << C << std::endl;
39  std::cout << "Q:\n" << Q << std::endl;
40  std::cout << "R:\n" << R << std::endl;
41  std::cout << "dFdv:\n" << dFdv << std::endl;
42  std::cout << " =======" << std::endl;
43  std::cout << std::endl;
44  }
45 
47  void load(const std::string& filename, bool verbose, const std::string& ns)
48  {
49  if (verbose)
50  std::cout << "Trying to load state observer settings from " << filename << ": " << std::endl;
51 
52  boost::property_tree::ptree pt;
53  boost::property_tree::read_info(filename, pt);
54 
55  ct::core::loadMatrix(filename, "C", C, ns);
56  ct::core::loadMatrix(filename, "Q", Q, ns);
57  ct::core::loadMatrix(filename, "R", R, ns);
58  ct::core::loadMatrix(filename, "dFdv", dFdv, ns);
59 
60  if (verbose)
61  {
62  std::cout << "Loaded state observer settings from " << filename << ": " << std::endl;
63  print();
64  }
65  }
66 };
67 
69 
76 template <size_t OUTPUT_DIM, size_t STATE_DIM, typename SCALAR = double>
78 
80 
87 template <size_t STATE_DIM, typename SCALAR = double>
89 {
93  SteadyStateKalmanFilterSettings() : maxDAREIterations(1000u) {}
96  void print() const
97  {
98  std::cout << "State Observer Settings: " << std::endl;
99  std::cout << "=====================" << std::endl;
100  std::cout << "x0:\n" << x0 << std::endl;
101  std::cout << "maxDAREIterations:\t" << maxDAREIterations << std::endl;
102  std::cout << " =======" << std::endl;
103  std::cout << std::endl;
104  }
105 
107  void load(const std::string& filename, bool verbose, const std::string& ns)
108  {
109  if (verbose)
110  std::cout << "Trying to load steady state KF settings from " << filename << ": " << std::endl;
111 
112  boost::property_tree::ptree pt;
113  boost::property_tree::read_info(filename, pt);
114 
115  maxDAREIterations = pt.get<size_t>(ns + ".maxDAREIterations", 1000);
116  ct::core::loadMatrix(filename, "x0", x0, ns);
117 
118  if (verbose)
119  {
120  std::cout << "Loaded steady state KF settings from " << filename << ": " << std::endl;
121  print();
122  }
123  }
124 };
125 
127 
134 template <size_t STATE_DIM, typename SCALAR = double>
136 {
143  void print() const
144  {
145  std::cout << "State Observer Settings: " << std::endl;
146  std::cout << "=====================" << std::endl;
147  std::cout << "x0:\n" << x0 << std::endl;
148  std::cout << "P0:\n" << P0 << std::endl;
149  std::cout << " =======" << std::endl;
150  std::cout << std::endl;
151  }
152 
154  void load(const std::string& filename, bool verbose, const std::string& ns)
155  {
156  if (verbose)
157  std::cout << "Trying to load steady state KF settings from " << filename << ": " << std::endl;
158 
159  boost::property_tree::ptree pt;
160  boost::property_tree::read_info(filename, pt);
161 
162  ct::core::loadMatrix(filename, "x0", x0, ns);
163  ct::core::loadMatrix(filename, "P0", P0, ns);
164 
165  if (verbose)
166  {
167  std::cout << "Loaded ExtendedKF settings from " << filename << ": " << std::endl;
168  print();
169  }
170  }
171 };
172 
174 
181 template <size_t STATE_DIM, typename SCALAR = double>
183 {
193  void print() const
194  {
195  std::cout << "State Observer Settings: " << std::endl;
196  std::cout << "=====================" << std::endl;
197  std::cout << "x0:\n" << x0 << std::endl;
198  std::cout << "alpha:\n" << alpha << std::endl;
199  std::cout << "beta:\n" << beta << std::endl;
200  std::cout << "kappa:\n" << kappa << std::endl;
201  std::cout << "P0:\n" << P0 << std::endl;
202  std::cout << " =======" << std::endl;
203  std::cout << std::endl;
204  }
205 
207  void load(const std::string& filename, bool verbose, const std::string& ns)
208  {
209  if (verbose)
210  std::cout << "Trying to load steady state KF settings from " << filename << ": " << std::endl;
211 
212  boost::property_tree::ptree pt;
213  boost::property_tree::read_info(filename, pt);
214 
215  ct::core::loadMatrix(filename, "x0", x0, ns);
216  alpha = pt.get<bool>(ns + ".alpha");
217  beta = pt.get<bool>(ns + ".beta");
218  kappa = pt.get<bool>(ns + ".kappa");
219  ct::core::loadMatrix(filename, "P0", P0, ns);
220 
221  if (verbose)
222  {
223  std::cout << "Loaded UnscentedKF settings from " << filename << ": " << std::endl;
224  print();
225  }
226  }
227 };
228 
229 } // namespace optcon
230 } // namespace ct
void load(const std::string &filename, bool verbose, const std::string &ns)
load settings from file
Definition: FilterSettings.h:207
void loadMatrix(const std::string &filename, const std::string &matrixName, Eigen::Matrix< SCALAR, ROW, COL > &matrix, const std::string &ns="")
ct::core::ControlVector< control_dim > u
Definition: LoadFromFileTest.cpp:21
StateObserverSettings()
default constructor for the state Observer settings
Definition: FilterSettings.h:25
void print() const
print the current settings
Definition: FilterSettings.h:193
ct::core::StateMatrix< STATE_DIM, SCALAR > P0
Definition: FilterSettings.h:138
SCALAR kappa
Definition: FilterSettings.h:187
ct::core::StateMatrix< STATE_DIM, SCALAR > dFdv
Definition: FilterSettings.h:31
void load(const std::string &filename, bool verbose, const std::string &ns)
load settings from file
Definition: FilterSettings.h:154
ct::core::StateVector< STATE_DIM > x0
Definition: FilterSettings.h:184
bool parametersOk() const
check if the currently set parameters are meaningful
Definition: FilterSettings.h:27
CppAD::AD< CppAD::cg::CG< double > > SCALAR
SCALAR beta
Definition: FilterSettings.h:186
size_t maxDAREIterations
Definition: FilterSettings.h:91
void load(const std::string &filename, bool verbose, const std::string &ns)
load settings from file
Definition: FilterSettings.h:107
ct::core::StateMatrix< STATE_DIM, SCALAR > Q
Definition: FilterSettings.h:29
ct::core::OutputMatrix< OUTPUT_DIM, SCALAR > R
Definition: FilterSettings.h:30
void print() const
print the current settings
Definition: FilterSettings.h:34
void load(const std::string &filename, bool verbose, const std::string &ns)
load settings from file
Definition: FilterSettings.h:47
Settings for setting up an ExtendedKF.
Definition: ExtendedKalmanFilter.h:14
Settings for setting up a StateObserver.
Definition: FilterSettings.h:22
Settings for setting up an UnscentedKF.
Definition: FilterSettings.h:182
const bool verbose
Definition: ConstraintComparison.h:18
void print() const
print the current settings
Definition: FilterSettings.h:143
ct::core::StateVector< STATE_DIM > x0
Definition: FilterSettings.h:137
Settings for setting up a SteadyStateKF.
Definition: FilterSettings.h:88
ct::core::StateVector< STATE_DIM > x0
Definition: FilterSettings.h:90
ct::core::OutputStateMatrix< OUTPUT_DIM, STATE_DIM, SCALAR > C
Definition: FilterSettings.h:28
ct::core::StateMatrix< STATE_DIM, SCALAR > P0
Definition: FilterSettings.h:188
SCALAR alpha
Definition: FilterSettings.h:185
void print() const
print the current settings
Definition: FilterSettings.h:96