- 3.0.2 optimal control module.
CTSystemModel-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, typename SCALAR>
14  std::shared_ptr<SensitivityApprox_t> sensApprox,
15  const state_matrix_t& dFdv,
16  const ct::core::IntegrationType& intType)
17  : system_(system),
18  constantController_(new ct::core::ConstantController<STATE_DIM, CONTROL_DIM, SCALAR>()),
19  sensApprox_(sensApprox),
20  dFdv_(dFdv),
21  integrator_(system_, intType)
22 {
23  if (!system_)
24  throw std::runtime_error("CTSystemModel: System not initialized!");
25 
26  // hand over constant controller for dynamics evaluation with known control inputs to the system.
27  system_->setController(constantController_);
28 }
29 
30 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
32  const control_vector_t& u,
33  const Time_t dt,
35 {
36  constantController_->setControl(u);
37  state_vector_t x = state;
38  integrator_.integrate_n_steps(x, t, 1, dt);
39  return x;
40 }
41 
42 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
44  const control_vector_t& u,
45  const Time_t dt,
47 {
48  // local vars
51 
52  sensApprox_->setTimeDiscretization(dt);
53 
54  sensApprox_->getAandB(state, u, state, int(t / dt), 1, A, Btemp);
55  return A;
56 }
57 
58 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR>
60  const control_vector_t& control,
61  const Time_t dt,
63 {
64  return dFdv_;
65 }
66 
67 } // namespace optcon
68 } // namespace ct
std::shared_ptr< SensitivityApprox_t > sensApprox_
The sensitivity approximator.
Definition: CTSystemModel.h:72
ct::core::ControlVector< control_dim > u
Definition: LoadFromFileTest.cpp:21
std::shared_ptr< ct::core::ConstantController< STATE_DIM, CONTROL_DIM, SCALAR > > constantController_
each system gets re-assigned a constant controller for dynamics evaluation with known control inputs ...
Definition: CTSystemModel.h:69
CTSystemModel(std::shared_ptr< ct::core::ControlledSystem< STATE_DIM, CONTROL_DIM, SCALAR >> system, std::shared_ptr< SensitivityApprox_t > sensApprox, const state_matrix_t &dFdv, const ct::core::IntegrationType &intType=ct::core::IntegrationType::EULERCT)
Constructor. Takes in the system with defined controller, and sens approximator for computing the der...
Definition: CTSystemModel-impl.h:12
std::shared_ptr< ct::core::ControlledSystem< STATE_DIM, CONTROL_DIM, SCALAR > > system_
The underlying CT system.
Definition: CTSystemModel.h:66
clear all close all load ct GNMSLog0 mat reformat t
Definition: gnmsPlot.m:6
state_vector_t computeDynamics(const state_vector_t &state, const control_vector_t &u, const Time_t dt, Time_t t) override
Propagates the system giving the next state as output. Control input is generated by the system contr...
Definition: CTSystemModel-impl.h:31
state_matrix_t dFdv_
Derivative w.r.t. noise.
Definition: CTSystemModel.h:75
const double dt
Definition: LQOCSolverTiming.cpp:18
CppAD::AD< CppAD::cg::CG< double > > SCALAR
state_matrix_t computeDerivativeNoise(const state_vector_t &state, const control_vector_t &control, const Time_t dt, Time_t t) override
Computes the derivative w.r.t noise. Control input is generated by the system controller.
Definition: CTSystemModel-impl.h:59
ct::core::StateVector< state_dim > x
Definition: LoadFromFileTest.cpp:20
ct::core::Integrator< STATE_DIM, SCALAR > integrator_
Integrator.
Definition: CTSystemModel.h:78
state_matrix_t computeDerivativeState(const state_vector_t &state, const control_vector_t &u, const Time_t dt, Time_t t) override
Computes the derivative w.r.t state. Control input is generated by the system controller.
Definition: CTSystemModel-impl.h:43
SCALAR Time_t
Definition: SystemModelBase.h:27