- 3.0.2 core module.
LTISystem.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 #pragma GCC diagnostic push
9 #pragma GCC diagnostic ignored "-Wunused-parameter"
10 #pragma GCC diagnostic ignored "-Wunused-value"
11 
12 namespace ct {
13 namespace core {
14 
16 
31 template <size_t STATE_DIM, size_t CONTROL_DIM>
32 class LTISystem : public LinearSystem<STATE_DIM, CONTROL_DIM>
33 {
34 public:
35  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
36 
38 
45  LTISystem(const Eigen::Matrix<double, STATE_DIM, STATE_DIM>& A,
46  const Eigen::Matrix<double, STATE_DIM, CONTROL_DIM>& B,
47  const Eigen::Matrix<double, STATE_DIM, STATE_DIM>& C = Eigen::Matrix<double, STATE_DIM, STATE_DIM>::Identity(),
48  const Eigen::Matrix<double, STATE_DIM, CONTROL_DIM> D = Eigen::Matrix<double, STATE_DIM, CONTROL_DIM>::Zero())
49  : A_(A), B_(B), C_(C), D_(D)
50  {
51  }
52 
54  LTISystem(const LTISystem& arg) : A_(arg.A_), B_(arg.B_), C_(arg.C_), D_(arg.D_) {}
57  virtual ~LTISystem() {}
59  virtual const Eigen::Matrix<double, STATE_DIM, STATE_DIM>& getDerivativeState(const StateVector<STATE_DIM>& x,
61  const double t = 0.0) override
62  {
63  return A_;
64  }
65 
67  virtual const Eigen::Matrix<double, STATE_DIM, CONTROL_DIM>& getDerivativeControl(const StateVector<STATE_DIM>& x,
69  const double t = 0.0) override
70  {
71  return B_;
72  }
73 
75  Eigen::Matrix<double, STATE_DIM, STATE_DIM>& A() { return A_; }
77  Eigen::Matrix<double, STATE_DIM, CONTROL_DIM>& B() { return B_; }
79  Eigen::Matrix<double, STATE_DIM, STATE_DIM>& C() { return C_; }
81  Eigen::Matrix<double, STATE_DIM, CONTROL_DIM>& D() { return D_; }
83 
90  void computeControlledDynamics(const Eigen::Matrix<double, STATE_DIM, 1>& state,
91  const Time& t,
92  const Eigen::Matrix<double, CONTROL_DIM, 1>& control,
93  Eigen::Matrix<double, STATE_DIM, 1>& derivative)
94  {
95  derivative = A_ * state + B_ * control;
96  }
97 
99 
106  void computeOutput(const Eigen::Matrix<double, STATE_DIM, 1>& state,
107  const Time& t,
108  const Eigen::Matrix<double, CONTROL_DIM, 1>& control,
109  Eigen::Matrix<double, STATE_DIM, 1>& output)
110  {
111  output = C_ * state + D_ * control;
112  }
113 
115 
122  void computeControllabilityMatrix(Eigen::Matrix<double, STATE_DIM, STATE_DIM * CONTROL_DIM>& CO)
123  {
124  CO.block<STATE_DIM, CONTROL_DIM>(0, 0) = B_;
125 
126  for (size_t i = 1; i < STATE_DIM; i++)
127  {
128  CO.block<STATE_DIM, CONTROL_DIM>(0, i * CONTROL_DIM) =
129  A_ * CO.block<STATE_DIM, CONTROL_DIM>(0, (i - 1) * CONTROL_DIM);
130  }
131  }
132 
134 
140  {
141  Eigen::Matrix<double, STATE_DIM, STATE_DIM * CONTROL_DIM> CO;
143 
144  Eigen::FullPivLU<Eigen::Matrix<double, STATE_DIM, STATE_DIM * CONTROL_DIM>> LUdecomposition(CO);
145  return LUdecomposition.rank() == STATE_DIM;
146  }
147 
149 
155  void computeObservabilityMatrix(Eigen::Matrix<double, STATE_DIM, STATE_DIM * STATE_DIM>& O)
156  {
157  O.block<STATE_DIM, STATE_DIM>(0, 0) = C_;
158 
159  for (size_t i = 1; i < STATE_DIM; i++)
160  {
161  O.block<STATE_DIM, STATE_DIM>(i * STATE_DIM, 0) =
162  O.block<STATE_DIM, STATE_DIM>(0, (i - 1) * STATE_DIM) * A_;
163  }
164  }
165 
167 
173  {
174  Eigen::Matrix<double, STATE_DIM, STATE_DIM * STATE_DIM> O;
176 
177  Eigen::FullPivLU<Eigen::Matrix<double, STATE_DIM, STATE_DIM * STATE_DIM>> LUdecomposition(O);
178  return LUdecomposition.rank() == STATE_DIM;
179  }
180 
181 
182 private:
183  Eigen::Matrix<double, STATE_DIM, STATE_DIM> A_;
184  Eigen::Matrix<double, STATE_DIM, CONTROL_DIM> B_;
185 
186  Eigen::Matrix<double, STATE_DIM, STATE_DIM> C_;
187  Eigen::Matrix<double, STATE_DIM, CONTROL_DIM> D_;
188 };
189 
190 } // namespace core
191 } // namespace ct
192 
193 #pragma GCC diagnostic pop
interface class for a general linear system or linearized system
Definition: LinearSystem.h:23
Linear time-invariant system.
Definition: LTISystem.h:32
bool isObservable()
checks if system is fully observable
Definition: LTISystem.h:172
void computeControllabilityMatrix(Eigen::Matrix< double, STATE_DIM, STATE_DIM *CONTROL_DIM > &CO)
computes the controllability matrix
Definition: LTISystem.h:122
LTISystem< STATE_DIM, CONTROL_DIM > * clone() const override
deep clone
Definition: LTISystem.h:56
LTISystem(const LTISystem &arg)
copy constructor
Definition: LTISystem.h:54
virtual const Eigen::Matrix< double, STATE_DIM, STATE_DIM > & getDerivativeState(const StateVector< STATE_DIM > &x, const ControlVector< CONTROL_DIM > &u, const double t=0.0) override
get A matrix
Definition: LTISystem.h:59
void computeControlledDynamics(const Eigen::Matrix< double, STATE_DIM, 1 > &state, const Time &t, const Eigen::Matrix< double, CONTROL_DIM, 1 > &control, Eigen::Matrix< double, STATE_DIM, 1 > &derivative)
computes the system dynamics
Definition: LTISystem.h:90
Eigen::Matrix< double, STATE_DIM, STATE_DIM > & A()
get A matrix
Definition: LTISystem.h:75
Eigen::Matrix< double, STATE_DIM, CONTROL_DIM > & D()
get D matrix
Definition: LTISystem.h:81
Definition: ControlVector.h:12
bool isControllable()
checks if system is fully controllable
Definition: LTISystem.h:139
virtual const Eigen::Matrix< double, STATE_DIM, CONTROL_DIM > & getDerivativeControl(const StateVector< STATE_DIM > &x, const ControlVector< CONTROL_DIM > &u, const double t=0.0) override
get B matrix
Definition: LTISystem.h:67
for i
void computeObservabilityMatrix(Eigen::Matrix< double, STATE_DIM, STATE_DIM *STATE_DIM > &O)
computes the observability matrix
Definition: LTISystem.h:155
Eigen::Matrix< double, STATE_DIM, STATE_DIM > & C()
get C matrix
Definition: LTISystem.h:79
void computeOutput(const Eigen::Matrix< double, STATE_DIM, 1 > &state, const Time &t, const Eigen::Matrix< double, CONTROL_DIM, 1 > &control, Eigen::Matrix< double, STATE_DIM, 1 > &output)
computes the system output (measurement)
Definition: LTISystem.h:106
Eigen::Matrix< double, STATE_DIM, CONTROL_DIM > & B()
get B matrix
Definition: LTISystem.h:77
EIGEN_MAKE_ALIGNED_OPERATOR_NEW LTISystem(const Eigen::Matrix< double, STATE_DIM, STATE_DIM > &A, const Eigen::Matrix< double, STATE_DIM, CONTROL_DIM > &B, const Eigen::Matrix< double, STATE_DIM, STATE_DIM > &C=Eigen::Matrix< double, STATE_DIM, STATE_DIM >::Identity(), const Eigen::Matrix< double, STATE_DIM, CONTROL_DIM > D=Eigen::Matrix< double, STATE_DIM, CONTROL_DIM >::Zero())
Constructs a linear time invariant system.
Definition: LTISystem.h:45
virtual ~LTISystem()
Definition: LTISystem.h:57
double Time
Definition: Time.h:11