- 3.0.2 core module.
SwitchedLinearSystem.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 
10 
11 namespace ct {
12 namespace core {
13 
15 
21 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR = double>
22 class SwitchedLinearSystem : public LinearSystem<STATE_DIM, CONTROL_DIM, SCALAR>
23 {
24 public:
25  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
26 
27  typedef typename std::shared_ptr<LinearSystem<STATE_DIM, CONTROL_DIM, SCALAR>> LinearSystemPtr;
29 
31  typedef typename Base::time_t time_t;
32 
35 
38 
40 
43  SwitchedLinearSystem(const SwitchedLinearSystems& switchedLinearSystems,
44  const ContinuousModeSequence& continuousModeSequence,
46  : LinearSystem<STATE_DIM, CONTROL_DIM, SCALAR>(type),
47  switchedLinearSystems_(switchedLinearSystems),
48  continuousModeSequence_(continuousModeSequence)
49  {
50  }
51 
54  : LinearSystem<STATE_DIM, CONTROL_DIM, SCALAR>(arg), continuousModeSequence_(arg.continuousModeSequence_)
55  {
56  switchedLinearSystems_.clear();
57  for (auto& subSystem : arg.switchedLinearSystems_)
58  {
59  switchedLinearSystems_.emplace_back(subSystem->clone());
60  }
61  }
62 
64  virtual ~SwitchedLinearSystem(){};
65 
68  {
69  return new SwitchedLinearSystem(*this);
70  };
71 
73 
74  virtual const state_matrix_t& getDerivativeState(const state_vector_t& x,
75  const control_vector_t& u,
76  const time_t t = time_t(0.0)) override
77  {
78  auto mode = continuousModeSequence_.getPhaseFromTime(t);
79  return switchedLinearSystems_[mode]->getDerivativeState(x, u, t);
80  };
81 
82  virtual const state_control_matrix_t& getDerivativeControl(const state_vector_t& x,
83  const control_vector_t& u,
84  const time_t t = time_t(0.0)) override
85  {
86  auto mode = continuousModeSequence_.getPhaseFromTime(t);
87  return switchedLinearSystems_[mode]->getDerivativeControl(x, u, t);
88  };
89 
90 private:
91  SwitchedLinearSystems switchedLinearSystems_;
92  ContinuousModeSequence continuousModeSequence_;
93 };
94 }
95 }
interface class for a general linear system or linearized system
Definition: LinearSystem.h:23
std::vector< T, Alloc > Switched
Declaring Switched alias such that we can write Switched<System>
Definition: Switching.h:12
Base::time_t time_t
Definition: ControlledSystem.h:53
virtual ~SwitchedLinearSystem()
destructor
Definition: SwitchedLinearSystem.h:64
SwitchedLinearSystem(const SwitchedLinearSystems &switchedLinearSystems, const ContinuousModeSequence &continuousModeSequence, const ct::core::SYSTEM_TYPE &type=ct::core::SYSTEM_TYPE::GENERAL)
default constructor
Definition: SwitchedLinearSystem.h:43
interface class for a general switched linear system or linearized system
Definition: SwitchedLinearSystem.h:22
ControlledSystem< STATE_DIM, CONTROL_DIM, SCALAR > Base
Definition: SwitchedLinearSystem.h:30
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef std::shared_ptr< LinearSystem< STATE_DIM, CONTROL_DIM, SCALAR > > LinearSystemPtr
Definition: SwitchedLinearSystem.h:27
Definition: StateMatrix.h:12
clear all close all load ct GNMSLog0 mat reformat t
virtual const state_control_matrix_t & getDerivativeControl(const state_vector_t &x, const control_vector_t &u, const time_t t=time_t(0.0)) override
get the B matrix of a linear system
Definition: SwitchedLinearSystem.h:82
Definition: ControlVector.h:12
CppAD::AD< CppAD::cg::CG< double > > SCALAR
ControlVector< CONTROL_DIM, SCALAR > control_vector_t
input vector type
Definition: SwitchedLinearSystem.h:34
Definition: StateVector.h:12
StateMatrix< STATE_DIM, SCALAR > state_matrix_t
state Jacobian type
Definition: SwitchedLinearSystem.h:36
virtual const state_matrix_t & getDerivativeState(const state_vector_t &x, const control_vector_t &u, const time_t t=time_t(0.0)) override
get the A matrix of a linear system
Definition: SwitchedLinearSystem.h:74
StateControlMatrix< STATE_DIM, CONTROL_DIM, SCALAR > state_control_matrix_t
input Jacobian type
Definition: SwitchedLinearSystem.h:37
SYSTEM_TYPE
type of system
Definition: System.h:15
Base::time_t time_t
Definition: SwitchedLinearSystem.h:31
Phase getPhaseFromTime(Time time) const
get phase pointer from time
Definition: Switching.h:68
any non-specific system
Definition: System.h:17
SwitchedLinearSystem(const SwitchedLinearSystem &arg)
copy constructor
Definition: SwitchedLinearSystem.h:53
Switched< LinearSystemPtr > SwitchedLinearSystems
Definition: SwitchedLinearSystem.h:28
StateVector< STATE_DIM, SCALAR > state_vector_t
state vector type
Definition: SwitchedLinearSystem.h:33
Definition: StateControlMatrix.h:12
A general, non-linear dynamic system with a control input.
Definition: ControlledSystem.h:46
virtual SwitchedLinearSystem< STATE_DIM, CONTROL_DIM, SCALAR > * clone() const override
deep cloning
Definition: SwitchedLinearSystem.h:67