- 3.0.2 core module.
SystemDiscretizer.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 
9 #include "../continuous_time/ControlledSystem.h"
11 
15 
16 #define SYMPLECTIC_ENABLED \
17  template <size_t V, size_t P, size_t ST> \
18  typename std::enable_if<(V > 0 && P > 0 && (V + P == ST)), void>::type
19 #define SYMPLECTIC_DISABLED \
20  template <size_t V, size_t P, size_t ST> \
21  typename std::enable_if<(V <= 0 || P <= 0 || (V + P != ST)), void>::type
22 
23 
24 namespace ct {
25 namespace core {
26 
28 
39 template <size_t STATE_DIM,
40  size_t CONTROL_DIM,
41  size_t P_DIM = STATE_DIM / 2,
42  size_t V_DIM = STATE_DIM / 2,
43  typename SCALAR = double>
44 class SystemDiscretizer : public DiscreteControlledSystem<STATE_DIM, CONTROL_DIM, SCALAR>
45 {
46 public:
47  // convenience typedefs
49  typedef typename Base::time_t time_t;
50 
51  using IntegratorPtr = std::shared_ptr<Integrator<STATE_DIM, SCALAR>>;
53  std::shared_ptr<ct::core::IntegratorSymplecticEuler<P_DIM, V_DIM, CONTROL_DIM, SCALAR>>;
55  std::shared_ptr<ct::core::IntegratorSymplecticRk<P_DIM, V_DIM, CONTROL_DIM, SCALAR>>;
56 
57  using ContinuousSystemPtr = std::shared_ptr<ControlledSystem<STATE_DIM, CONTROL_DIM, SCALAR>>;
58  using ContinuousConstantControllerPtr = std::shared_ptr<ConstantController<STATE_DIM, CONTROL_DIM, SCALAR>>;
59 
60  using SubstepRecorderPtr = std::shared_ptr<ct::core::SubstepRecorder<STATE_DIM, CONTROL_DIM, SCALAR>>;
61 
63  using StateVectorArrayPtr = std::shared_ptr<StateVectorArray>;
65  using ControlVectorArrayPtr = std::shared_ptr<ControlVectorArray>;
66 
69 
71 
76  SystemDiscretizer(const SCALAR& dt,
78  const int& K_sim = 1);
79 
81 
89  const SCALAR& dt,
91  const int& K_sim = 1);
92 
95 
97  virtual ~SystemDiscretizer();
98 
101 
103  void initialize();
104 
106  void setIntegrationType(const ct::core::IntegrationType& integratorType);
107 
109  void setParameters(const SCALAR& dt, const int& K_sim = 1);
110 
113 
115 
124  const time_t n,
125  const ControlVector<CONTROL_DIM, SCALAR>& control,
126  StateVector<STATE_DIM, SCALAR>& stateNext) override;
127 
129  const StateVectorArrayPtr& getSubstates() const;
130 
132  const ControlVectorArrayPtr& getSubcontrols() const;
133 
134 protected:
137 
140 
143  const double& t,
144  const size_t& steps,
145  const double& dt_sim) const;
146 
149  const double& t,
150  const size_t& steps,
151  const double& dt_sim) const;
152 
155 
158 
160  int K_sim_;
161 
164 
167 
170 
173 
176 
179 
182 
185 };
186 
187 
188 } // namespace core
189 } // namespace ct
190 
191 #undef SYMPLECTIC_ENABLED
192 #undef SYMPLECTIC_DISABLED
SCALAR dt_
the time discretization interval
Definition: SystemDiscretizer.h:157
#define SYMPLECTIC_DISABLED
Definition: SystemDiscretizer.h:19
virtual ~SystemDiscretizer()
destructor
Definition: SystemDiscretizer-impl.h:53
An discrete array (vector) of a particular data type.
Definition: DiscreteArray.h:22
SCALAR getSimulationTimestep()
compute the simulation timestep
Definition: SystemDiscretizer-impl.h:73
SYMPLECTIC_ENABLED integrateSymplectic(ct::core::StateVector< STATE_DIM, SCALAR > &x0, const double &t, const size_t &steps, const double &dt_sim) const
integrateSymplectic, gets instantiated if the system is symplectic
Definition: SystemDiscretizer-impl.h:181
DiscreteControlledSystem< STATE_DIM, CONTROL_DIM, SCALAR > Base
Definition: SystemDiscretizer.h:48
std::shared_ptr< ct::core::IntegratorSymplecticRk< P_DIM, V_DIM, CONTROL_DIM, SCALAR > > IntegratorSymplecticRkPtr
Definition: SystemDiscretizer.h:55
void setIntegrationType(const ct::core::IntegrationType &integratorType)
update integration type
Definition: SystemDiscretizer-impl.h:80
IntegratorSymplecticRkPtr integratorRkSymplectic_
an integrator for forward integrating a symplectic continuous-time system with symplectic RK methods ...
Definition: SystemDiscretizer.h:181
ct::core::IntegrationType integratorType_
the integration type for forward integration
Definition: SystemDiscretizer.h:166
IntegratorPtr integrator_
an integrator for forward integrating a general continuous-time system with standard RK methods ...
Definition: SystemDiscretizer.h:175
ContinuousSystemPtr cont_time_system_
the continuous-time system to be discretized
Definition: SystemDiscretizer.h:169
SCALAR dt_sim_
the integration sub-step size, which is a function of dt_ and K_sim_
Definition: SystemDiscretizer.h:163
std::shared_ptr< ConstantController< STATE_DIM, CONTROL_DIM, SCALAR > > ContinuousConstantControllerPtr
Definition: SystemDiscretizer.h:58
virtual void propagateControlledDynamics(const StateVector< STATE_DIM, SCALAR > &state, const time_t n, const ControlVector< CONTROL_DIM, SCALAR > &control, StateVector< STATE_DIM, SCALAR > &stateNext) override
propagate discrete-time dynamics by performing a numerical forward integration of the continuous-time...
Definition: SystemDiscretizer-impl.h:121
Discretize a general, continuous-time non-linear dynamic system using forward integration.
Definition: SystemDiscretizer.h:44
void initialize()
initialize class
Definition: SystemDiscretizer-impl.h:96
std::shared_ptr< ControlledSystem< STATE_DIM, CONTROL_DIM, SCALAR > > ContinuousSystemPtr
Definition: SystemDiscretizer.h:57
Base::time_t time_t
Definition: SystemDiscretizer.h:49
#define SYMPLECTIC_ENABLED
Definition: SystemDiscretizer.h:16
Definition: ControlVector.h:12
SubstepRecorderPtr substepRecorder_
substep recorder which logs all the substeps required for later computing exact sensitivities ...
Definition: SystemDiscretizer.h:184
void setParameters(const SCALAR &dt, const int &K_sim=1)
update parameters
Definition: SystemDiscretizer-impl.h:87
A general, non-linear discrete dynamic system with a control input.
Definition: DiscreteControlledSystem.h:40
CppAD::AD< CppAD::cg::CG< double > > SCALAR
virtual SystemDiscretizer< STATE_DIM, CONTROL_DIM, P_DIM, V_DIM, SCALAR > * clone() const override
deep cloning
Definition: SystemDiscretizer-impl.h:66
void changeContinuousTimeSystem(ContinuousSystemPtr newSystem)
update the SystemDiscretizer with a new nonlinear, continuous-time system
Definition: SystemDiscretizer-impl.h:111
std::shared_ptr< Integrator< STATE_DIM, SCALAR > > IntegratorPtr
Definition: SystemDiscretizer.h:51
constexpr size_t n
Definition: MatrixInversionTest.cpp:14
Definition: StateVector.h:12
int K_sim_
the forward simulation can be discretized finer than dt_. K_sim_ is an integer number representing th...
Definition: SystemDiscretizer.h:160
SystemDiscretizer()
default constructor
Definition: SystemDiscretizer-impl.h:19
Definition: Integrator.h:33
ContinuousConstantControllerPtr cont_constant_controller_
the continuous-time constant controller to be applied to the continuous-time dynamics ...
Definition: SystemDiscretizer.h:172
std::shared_ptr< ct::core::IntegratorSymplecticEuler< P_DIM, V_DIM, CONTROL_DIM, SCALAR > > IntegratorSymplecticEulerPtr
Definition: SystemDiscretizer.h:53
std::shared_ptr< ControlVectorArray > ControlVectorArrayPtr
Definition: SystemDiscretizer.h:65
IntegratorSymplecticEulerPtr integratorEulerSymplectic_
an integrator for forward integrating a symplectic continuous-time system with symplectic Euler ...
Definition: SystemDiscretizer.h:178
std::shared_ptr< ct::core::SubstepRecorder< STATE_DIM, CONTROL_DIM, SCALAR > > SubstepRecorderPtr
Definition: SystemDiscretizer.h:60
std::shared_ptr< StateVectorArray > StateVectorArrayPtr
Definition: SystemDiscretizer.h:63
SYMPLECTIC_ENABLED initializeSymplecticIntegrator()
initialize the symplectic integrator, if the system is symplectic
Definition: SystemDiscretizer-impl.h:153
const StateVectorArrayPtr & getSubstates() const
return a pointer to the substates recorded during integration
Definition: SystemDiscretizer-impl.h:216
int time_t
the type of the time variable
Definition: DiscreteSystem.h:15
const ControlVectorArrayPtr & getSubcontrols() const
reuturn a pointer to the subcontrols recorded during integration
Definition: SystemDiscretizer-impl.h:223
IntegrationType
The available integration types.
Definition: Integrator.h:30