- 3.0.2 optimal control module.
OptconContinuousSystemInterface.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 
12 
23 template <size_t STATE_DIM,
24  size_t CONTROL_DIM,
25  size_t P_DIM = STATE_DIM / 2,
26  size_t V_DIM = STATE_DIM / 2,
27  typename SCALAR = double>
29  CONTROL_DIM,
30  ContinuousOptConProblem<STATE_DIM, CONTROL_DIM, SCALAR>,
31  SCALAR>
32 {
33 public:
34  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
35 
36  typedef OptconSystemInterface<STATE_DIM,
37  CONTROL_DIM,
39  SCALAR>
41 
42  typedef typename Base::control_vector_t control_vector_t;
43  typedef typename Base::state_vector_t state_vector_t;
44  typedef typename Base::state_matrix_t state_matrix_t;
45  typedef typename Base::state_control_matrix_t state_control_matrix_t;
46 
48  typedef std::shared_ptr<discretizer_t> system_discretizer_ptr_t;
49 
51  typedef std::shared_ptr<Sensitivity_t> SensitivityPtr;
52 
53  typedef typename Base::StateVectorArrayPtr StateVectorArrayPtr;
54  typedef typename Base::StateSubstepsPtr StateSubstepsPtr;
55  typedef typename Base::ControlVectorArrayPtr ControlVectorArrayPtr;
56  typedef typename Base::ControlSubstepsPtr ControlSubstepsPtr;
57 
58  typedef typename Base::optConProblem_t optConProblem_t;
59  typedef typename Base::settings_t settings_t;
60 
62  OptconContinuousSystemInterface(const optConProblem_t& problem, const settings_t& settings);
63 
67  virtual void initialize() override;
68  virtual void configure(const settings_t& settings) override;
69 
71 
81  virtual void getAandB(const state_vector_t& x,
82  const control_vector_t& u,
83  const state_vector_t& x_next,
84  const int n,
85  size_t subSteps,
86  state_matrix_t& A,
87  state_control_matrix_t& B,
88  const size_t threadId) override;
89 
91 
98  virtual void propagateControlledDynamics(const state_vector_t& state,
99  const time_t n,
100  const control_vector_t& control,
101  state_vector_t& stateNext,
102  const size_t threadId) override;
103 
104  virtual void changeNonlinearSystem(const typename optConProblem_t::DynamicsPtr_t& dyn) override;
105  virtual void changeLinearSystem(const typename optConProblem_t::LinearPtr_t& lin) override;
106 
108  virtual void changeNumStages(const int numStages) override;
109 
110  virtual void getSubstates(StateVectorArrayPtr& subStepsX, const size_t threadId) override;
111  virtual void getSubcontrols(ControlVectorArrayPtr& subStepsU, const size_t threadId) override;
112 
113  virtual void setSubstepTrajectoryReference(const StateSubstepsPtr& xSubsteps,
114  const ControlSubstepsPtr& uSubsteps,
115  const size_t threadId) override;
116 
117 private:
118  std::vector<system_discretizer_ptr_t, Eigen::aligned_allocator<system_discretizer_ptr_t>>
119  discretizers_;
120 
121  std::vector<SensitivityPtr, Eigen::aligned_allocator<SensitivityPtr>>
122  sensitivity_;
123 };
124 
125 } // namespace optcon
126 } // namespace ct
Base::optConProblem_t optConProblem_t
Definition: OptconContinuousSystemInterface.h:58
virtual void changeNumStages(const int numStages) override
set the number of stages/time steps
Definition: OptconContinuousSystemInterface-impl.h:20
std::shared_ptr< Sensitivity_t > SensitivityPtr
Definition: OptconContinuousSystemInterface.h:51
virtual ~OptconContinuousSystemInterface()
destructor
Definition: OptconContinuousSystemInterface.h:65
Base::StateVectorArrayPtr StateVectorArrayPtr
Definition: OptconContinuousSystemInterface.h:53
Base::ControlVectorArrayPtr ControlVectorArrayPtr
Definition: OptconContinuousSystemInterface.h:55
ct::core::Sensitivity< STATE_DIM, CONTROL_DIM, SCALAR > Sensitivity_t
Definition: OptconContinuousSystemInterface.h:50
virtual void setSubstepTrajectoryReference(const StateSubstepsPtr &xSubsteps, const ControlSubstepsPtr &uSubsteps, const size_t threadId) override
Definition: OptconContinuousSystemInterface-impl.h:161
ct::core::ControlVector< control_dim > u
Definition: LoadFromFileTest.cpp:21
virtual void changeLinearSystem(const typename optConProblem_t::LinearPtr_t &lin) override
Definition: OptconContinuousSystemInterface-impl.h:42
virtual void getSubcontrols(ControlVectorArrayPtr &subStepsU, const size_t threadId) override
Definition: OptconContinuousSystemInterface-impl.h:153
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, const size_t threadId) override
retrieve discrete-time linear system matrices A and B.
Definition: OptconContinuousSystemInterface-impl.h:170
virtual void initialize() override
perform necessary setup work
Definition: OptconContinuousSystemInterface-impl.h:56
std::shared_ptr< discretizer_t > system_discretizer_ptr_t
Definition: OptconContinuousSystemInterface.h:48
interface base class for optimal control algorithms
Definition: OptconSystemInterface.h:25
Base::settings_t settings_t
Definition: OptconContinuousSystemInterface.h:59
CppAD::AD< CppAD::cg::CG< double > > SCALAR
ct::core::SystemDiscretizer< STATE_DIM, CONTROL_DIM, P_DIM, V_DIM, SCALAR > discretizer_t
Definition: OptconContinuousSystemInterface.h:47
interface class for optimal control algorithms
Definition: OptconContinuousSystemInterface.h:28
constexpr size_t n
ct::core::StateVector< state_dim > x
Definition: LoadFromFileTest.cpp:20
Base::control_vector_t control_vector_t
Definition: OptconContinuousSystemInterface.h:42
virtual void changeNonlinearSystem(const typename optConProblem_t::DynamicsPtr_t &dyn) override
Definition: OptconContinuousSystemInterface-impl.h:25
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef OptconSystemInterface< STATE_DIM, CONTROL_DIM, ContinuousOptConProblem< STATE_DIM, CONTROL_DIM, SCALAR >, SCALAR > Base
Definition: OptconContinuousSystemInterface.h:40
Base::state_vector_t state_vector_t
Definition: OptconContinuousSystemInterface.h:43
virtual void getSubstates(StateVectorArrayPtr &subStepsX, const size_t threadId) override
Definition: OptconContinuousSystemInterface-impl.h:145
Base::state_matrix_t state_matrix_t
Definition: OptconContinuousSystemInterface.h:44
Base::ControlSubstepsPtr ControlSubstepsPtr
Definition: OptconContinuousSystemInterface.h:56
Definition: OptConProblemBase.h:40
Base::state_control_matrix_t state_control_matrix_t
Definition: OptconContinuousSystemInterface.h:45
virtual void configure(const settings_t &settings) override
Definition: OptconContinuousSystemInterface-impl.h:101
Base::StateSubstepsPtr StateSubstepsPtr
Definition: OptconContinuousSystemInterface.h:54
OptconContinuousSystemInterface(const optConProblem_t &problem, const settings_t &settings)
constructor
Definition: OptconContinuousSystemInterface-impl.h:12
virtual void propagateControlledDynamics(const state_vector_t &state, const time_t n, const control_vector_t &control, state_vector_t &stateNext, const size_t threadId) override
propagate discrete-time dynamics
Definition: OptconContinuousSystemInterface-impl.h:133