- 3.0.2 core module.
SwitchedDiscreteLinearSystem.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 core {
10 
12 
18 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR = double>
19 class SwitchedDiscreteLinearSystem : public DiscreteLinearSystem<STATE_DIM, CONTROL_DIM, SCALAR>
20 {
21 public:
22  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
23 
24  typedef typename std::shared_ptr<DiscreteLinearSystem<STATE_DIM, CONTROL_DIM, SCALAR>> LinearSystemPtr;
26 
28  typedef typename Base::time_t time_t;
29 
32 
35 
37 
40  SwitchedDiscreteLinearSystem(const SwitchedLinearSystems& switchedLinearSystems,
41  const DiscreteModeSequence& discreteModeSequence,
42  const SYSTEM_TYPE& type = SYSTEM_TYPE::GENERAL)
43  : DiscreteLinearSystem<STATE_DIM, CONTROL_DIM, SCALAR>(type),
44  switchedLinearSystems_(switchedLinearSystems),
45  discreteModeSequence_(discreteModeSequence){};
46 
49  : DiscreteLinearSystem<STATE_DIM, CONTROL_DIM, SCALAR>(arg), discreteModeSequence_(arg.discreteModeSequence_)
50  {
51  switchedLinearSystems_.clear();
52  for (auto& subSystem : arg.switchedLinearSystems_)
53  {
54  switchedLinearSystems_.emplace_back(subSystem->clone());
55  }
56  };
57 
60 
63  {
64  return new SwitchedDiscreteLinearSystem(*this);
65  };
66 
68 
78  virtual void propagateControlledDynamics(const state_vector_t& state,
79  const time_t n,
80  const control_vector_t& control,
81  state_vector_t& stateNext) override
82  {
84  switchedLinearSystems_[mode]->propagateControlledDynamics(state, n, control, stateNext);
85  };
86 
88 
106  virtual void getAandB(const state_vector_t& x,
107  const control_vector_t& u,
108  const state_vector_t& x_next,
109  const int n,
110  size_t subSteps,
111  state_matrix_t& A,
112  state_control_matrix_t& B) override
113  {
115  switchedLinearSystems_[mode]->getAandB(x, u, x_next, n, subSteps, A, B);
116  };
117 
119 
120 protected:
121  SwitchedLinearSystems switchedLinearSystems_;
123 };
124 
125 } // namespace core
126 } // namespace ct
std::vector< T, Alloc > Switched
Declaring Switched alias such that we can write Switched<System>
Definition: Switching.h:12
class for a general switched discrete linear system or linearized discrete system ...
Definition: SwitchedDiscreteLinearSystem.h:19
virtual void propagateControlledDynamics(const state_vector_t &state, const time_t n, const control_vector_t &control, state_vector_t &stateNext) override
compute the system dynamics
Definition: SwitchedDiscreteLinearSystem.h:78
DiscreteModeSequence discreteModeSequence_
the prespecified mode sequence
Definition: SwitchedDiscreteLinearSystem.h:122
Switched< LinearSystemPtr > SwitchedLinearSystems
Definition: SwitchedDiscreteLinearSystem.h:25
virtual void getAandB(const state_vector_t &x, const control_vector_t &u, const state_vector_t &x_next, const int n, size_t subSteps, state_matrix_t &A, state_control_matrix_t &B) override
retrieve discrete-time linear system matrices A and B for mode i, active at time n.
Definition: SwitchedDiscreteLinearSystem.h:106
interface class for a general discrete linear system or linearized discrete system ...
Definition: DiscreteLinearSystem.h:23
virtual SwitchedDiscreteLinearSystem< STATE_DIM, CONTROL_DIM, SCALAR > * clone() const override
deep cloning
Definition: SwitchedDiscreteLinearSystem.h:62
Definition: StateMatrix.h:12
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef std::shared_ptr< DiscreteLinearSystem< STATE_DIM, CONTROL_DIM, SCALAR > > LinearSystemPtr
Definition: SwitchedDiscreteLinearSystem.h:24
Definition: ControlVector.h:12
A general, non-linear discrete dynamic system with a control input.
Definition: DiscreteControlledSystem.h:40
CppAD::AD< CppAD::cg::CG< double > > SCALAR
constexpr size_t n
Definition: MatrixInversionTest.cpp:14
Base::state_vector_t state_vector_t
Definition: SwitchedDiscreteLinearSystem.h:30
SwitchedDiscreteLinearSystem(const SwitchedDiscreteLinearSystem &arg)
copy constructor
Definition: SwitchedDiscreteLinearSystem.h:48
Definition: StateVector.h:12
Base::time_t time_t
Definition: SwitchedDiscreteLinearSystem.h:28
SwitchedDiscreteLinearSystem(const SwitchedLinearSystems &switchedLinearSystems, const DiscreteModeSequence &discreteModeSequence, const SYSTEM_TYPE &type=SYSTEM_TYPE::GENERAL)
default constructor
Definition: SwitchedDiscreteLinearSystem.h:40
virtual ~SwitchedDiscreteLinearSystem()
destructor
Definition: SwitchedDiscreteLinearSystem.h:59
SYSTEM_TYPE
type of system
Definition: System.h:15
Phase getPhaseFromTime(Time time) const
get phase pointer from time
Definition: Switching.h:68
any non-specific system
Definition: System.h:17
SwitchedLinearSystems switchedLinearSystems_
Switched linear system container.
Definition: SwitchedDiscreteLinearSystem.h:121
StateMatrix< STATE_DIM, SCALAR > state_matrix_t
state Jacobian type
Definition: SwitchedDiscreteLinearSystem.h:33
StateControlMatrix< STATE_DIM, CONTROL_DIM, SCALAR > state_control_matrix_t
input Jacobian type
Definition: SwitchedDiscreteLinearSystem.h:34
int time_t
the type of the time variable
Definition: DiscreteSystem.h:15
DiscreteControlledSystem< STATE_DIM, CONTROL_DIM, SCALAR > Base
Definition: SwitchedDiscreteLinearSystem.h:27
Base::control_vector_t control_vector_t
Definition: SwitchedDiscreteLinearSystem.h:31
Definition: StateControlMatrix.h:12