- 3.0.2 optimal control module.
SteadyStateKalmanFilter-impl.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 namespace ct {
9 namespace optcon {
10 
11 template <size_t STATE_DIM, size_t CONTROL_DIM, size_t OUTPUT_DIM, typename SCALAR>
15  const state_matrix_t& Q,
16  const output_matrix_t& R,
17  const state_vector_t& x0,
18  size_t maxDAREIterations)
19  : Base(f, h, x0), Q_(Q), R_(R), maxDAREIterations_(maxDAREIterations)
20 {
21  P_.setZero();
22 }
23 
24 template <size_t STATE_DIM, size_t CONTROL_DIM, size_t OUTPUT_DIM, typename SCALAR>
29  : Base(f, h, sskf_settings.x0),
30  Q_(sskf_settings.Q),
31  R_(sskf_settings.R),
32  maxDAREIterations_(sskf_settings.maxDAREIterations)
33 {
34 }
35 
36 template <size_t STATE_DIM, size_t CONTROL_DIM, size_t OUTPUT_DIM, typename SCALAR>
38  const ct::core::Time& dt,
39  const ct::core::Time& t) -> const state_vector_t&
40 {
41  A_ = this->f_->computeDerivativeState(this->x_est_, u, t);
42  this->x_est_ = this->f_->computeDynamics(this->x_est_, u, t);
43  return this->x_est_;
44 }
45 
46 template <size_t STATE_DIM, size_t CONTROL_DIM, size_t OUTPUT_DIM, typename SCALAR>
48  const ct::core::Time& dt,
49  const ct::core::Time& t) -> const state_vector_t&
50 {
51  ct::core::OutputStateMatrix<OUTPUT_DIM, STATE_DIM, SCALAR> dHdx = this->h_->computeDerivativeState(this->x_est_, t);
52  Eigen::Matrix<SCALAR, OUTPUT_DIM, STATE_DIM> K;
53 
55  try
56  {
58  Q_, R_, A_.transpose(), dHdx.transpose(), P_, K, false, 1e-6, maxDAREIterations_);
59  } catch (...)
60  {
61  throw;
62  }
63 
64  this->x_est_ -= K.transpose() * (y - this->h_->computeMeasurement(this->x_est_, t));
65  return this->x_est_;
66 }
67 
68 template <size_t STATE_DIM, size_t CONTROL_DIM, size_t OUTPUT_DIM, typename SCALAR>
70 {
71  maxDAREIterations_ = maxDAREIterations;
72 }
73 
74 } // namespace optcon
75 } // namespace ct
std::shared_ptr< SystemModelBase< STATE_DIM, CONTROL_DIM, SCALAR > > f_
System model for propagating the system.
Definition: EstimatorBase.h:64
ct::core::ControlVector< control_dim > u
Definition: LoadFromFileTest.cpp:21
std::shared_ptr< LinearMeasurementModel< OUTPUT_DIM, STATE_DIM, SCALAR > > h_
Observation model used to calculate the output error.
Definition: EstimatorBase.h:67
clear all close all load ct GNMSLog0 mat reformat t
Definition: gnmsPlot.m:6
const double dt
Definition: LQOCSolverTiming.cpp:18
Linear Measurement Model is an interface for linear measurement models most commonly used in practice...
Definition: LinearMeasurementModel.h:23
state_vector_t x_est_
State estimate.
Definition: EstimatorBase.h:70
System model is an interface that encapsulates the integrator to be able to propagate the system...
Definition: SystemModelBase.h:21
Discrete-Time Algebraic Riccati Equation.
Definition: DARE.hpp:24
Estimator base.
Definition: EstimatorBase.h:21
void setMaxDAREIterations(size_t maxDAREIterations)
Limit number of iterations of the DARE solver.
Definition: SteadyStateKalmanFilter-impl.h:69
StateVector< state_dim > x0
Definition: ConstrainedNLOCTest.cpp:14
SteadyStateKalmanFilter(std::shared_ptr< SystemModelBase< STATE_DIM, CONTROL_DIM, SCALAR >> f, std::shared_ptr< LinearMeasurementModel< OUTPUT_DIM, STATE_DIM, SCALAR >> h, const state_matrix_t &Q, const output_matrix_t &R, const state_vector_t &x0=state_vector_t::Zero(), size_t maxDAREIterations=1000)
Constructor.
Definition: SteadyStateKalmanFilter-impl.h:12
const state_vector_t & predict(const control_vector_t &u, const ct::core::Time &dt, const ct::core::Time &t) override
Estimator predict method.
Definition: SteadyStateKalmanFilter-impl.h:37
state_matrix_t computeSteadyStateRiccatiMatrix(const state_matrix_t &Q, const control_matrix_t &R, const state_matrix_t &A, const control_gain_matrix_t &B, control_feedback_t &K, bool verbose=false, const SCALAR eps=1e-6, size_t maxIter=1000)
Definition: DARE-impl.hpp:18
Settings for setting up a SteadyStateKF.
Definition: FilterSettings.h:88
double Time
const state_vector_t & update(const output_vector_t &y, const ct::core::Time &dt, const ct::core::Time &t) override
Estimator update method.
Definition: SteadyStateKalmanFilter-impl.h:47