- 3.0.2 optimal control module.
OptconSystemInterface.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 
10 namespace ct {
11 namespace optcon {
12 
14 
24 template <size_t STATE_DIM, size_t CONTROL_DIM, typename OPTCONPROBLEM, typename SCALAR = double>
26 {
27 public:
28  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
29 
34 
36  typedef std::shared_ptr<StateVectorArray> StateVectorArrayPtr;
37  typedef std::vector<StateVectorArrayPtr, Eigen::aligned_allocator<StateVectorArrayPtr>> StateSubsteps;
38  typedef std::shared_ptr<StateSubsteps> StateSubstepsPtr;
39 
41  typedef std::shared_ptr<ControlVectorArray> ControlVectorArrayPtr;
42  typedef std::vector<ControlVectorArrayPtr, Eigen::aligned_allocator<ControlVectorArrayPtr>> ControlSubsteps;
43  typedef std::shared_ptr<ControlSubsteps> ControlSubstepsPtr;
44 
46  typedef std::shared_ptr<constant_controller_t> ConstantControllerPtr;
47 
48  typedef OPTCONPROBLEM optConProblem_t;
50 
52  OptconSystemInterface(const optConProblem_t& problem, const settings_t& settings)
53  : controller_(settings.nThreads + 1), optConProblem_(problem), settings_(settings)
54  {
55  for (auto& controller_i : controller_)
56  {
57  controller_i = ConstantControllerPtr(new constant_controller_t());
58  }
59  }
60 
62  virtual void initialize() {}
63  virtual void configure(const settings_t& settings) {}
65 
75  virtual void getAandB(const state_vector_t& x,
76  const control_vector_t& u,
77  const state_vector_t& x_next,
78  const int n,
79  size_t subSteps,
80  state_matrix_t& A,
81  state_control_matrix_t& B,
82  const size_t threadId) = 0;
83 
84 
86 
93  virtual void propagateControlledDynamics(const state_vector_t& state,
94  const time_t n,
95  const control_vector_t& control,
96  state_vector_t& stateNext,
97  const size_t threadId) = 0;
98 
100  virtual void changeNumStages(const int numStages) {}
101  const optConProblem_t& getOptConProblem() { return optConProblem_; };
102  std::vector<typename optConProblem_t::DynamicsPtr_t>& getNonlinearSystemsInstances() { return systems_; }
103  std::vector<typename optConProblem_t::LinearPtr_t>& getLinearSystemsInstances() { return linearSystems_; }
104  virtual void changeNonlinearSystem(const typename optConProblem_t::DynamicsPtr_t& dyn) = 0;
105  virtual void changeLinearSystem(const typename optConProblem_t::LinearPtr_t& lin) = 0;
106 
107  virtual void getSubstates(StateVectorArrayPtr& subStepsX, const size_t threadId) {}
108  virtual void getSubcontrols(ControlVectorArrayPtr& subStepsU, const size_t threadId) {}
109  virtual void setSubstepTrajectoryReference(const StateSubstepsPtr& xSubsteps,
110  const ControlSubstepsPtr& uSubsteps,
111  const size_t threadId){};
112 
113 protected:
118  std::vector<typename optConProblem_t::DynamicsPtr_t> systems_;
119  std::vector<typename optConProblem_t::LinearPtr_t> linearSystems_;
120 
121 
122  std::vector<ConstantControllerPtr, Eigen::aligned_allocator<ConstantControllerPtr>>
124 
125  optConProblem_t optConProblem_;
126 
127  settings_t settings_;
128 };
129 
130 } // namespace optcon
131 } // namespace ct
virtual void changeNumStages(const int numStages)
set the number of stages/time steps
Definition: OptconSystemInterface.h:100
std::vector< ConstantControllerPtr, Eigen::aligned_allocator< ConstantControllerPtr > > controller_
Definition: OptconSystemInterface.h:123
std::vector< typename optConProblem_t::DynamicsPtr_t > systems_
Definition: OptconSystemInterface.h:111
std::shared_ptr< constant_controller_t > ConstantControllerPtr
Definition: OptconSystemInterface.h:46
std::vector< StateVectorArrayPtr, Eigen::aligned_allocator< StateVectorArrayPtr > > StateSubsteps
Definition: OptconSystemInterface.h:37
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)=0
retrieve discrete-time linear system matrices A and B.
std::vector< typename optConProblem_t::LinearPtr_t > linearSystems_
Definition: OptconSystemInterface.h:119
ct::core::StateMatrix< STATE_DIM, SCALAR > state_matrix_t
Definition: OptconSystemInterface.h:32
virtual void changeNonlinearSystem(const typename optConProblem_t::DynamicsPtr_t &dyn)=0
ct::core::ControlVector< control_dim > u
Definition: LoadFromFileTest.cpp:21
settings_t settings_
instance of the optconProblem
Definition: OptconSystemInterface.h:127
std::shared_ptr< StateVectorArray > StateVectorArrayPtr
Definition: OptconSystemInterface.h:36
virtual void changeLinearSystem(const typename optConProblem_t::LinearPtr_t &lin)=0
OPTCONPROBLEM optConProblem_t
Definition: OptconSystemInterface.h:48
ct::core::ConstantController< STATE_DIM, CONTROL_DIM, SCALAR > constant_controller_t
Definition: OptconSystemInterface.h:45
interface base class for optimal control algorithms
Definition: OptconSystemInterface.h:25
std::vector< typename optConProblem_t::LinearPtr_t > & getLinearSystemsInstances()
Definition: OptconSystemInterface.h:103
std::vector< ControlVectorArrayPtr, Eigen::aligned_allocator< ControlVectorArrayPtr > > ControlSubsteps
Definition: OptconSystemInterface.h:42
Settings for the NLOptCon algorithm.
Definition: NLOptConSettings.hpp:198
NLOptConSettings settings_t
Definition: OptconSystemInterface.h:49
ct::core::StateVectorArray< STATE_DIM, SCALAR > StateVectorArray
Definition: OptconSystemInterface.h:35
virtual void getSubstates(StateVectorArrayPtr &subStepsX, const size_t threadId)
Definition: OptconSystemInterface.h:107
const optConProblem_t & getOptConProblem()
Definition: OptconSystemInterface.h:101
constexpr size_t n
virtual void initialize()
perform any required setup work
Definition: OptconSystemInterface.h:62
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef ct::core::ControlVector< CONTROL_DIM, SCALAR > control_vector_t
Definition: OptconSystemInterface.h:30
optConProblem_t optConProblem_
the constant controller for forward-integration during one time-step
Definition: OptconSystemInterface.h:125
ct::core::StateVector< state_dim > x
Definition: LoadFromFileTest.cpp:20
std::shared_ptr< LINEAR_SYSTEM_T > LinearPtr_t
Definition: OptConProblemBase.h:51
OptconSystemInterface(const optConProblem_t &problem, const settings_t &settings)
constructor
Definition: OptconSystemInterface.h:52
virtual void getSubcontrols(ControlVectorArrayPtr &subStepsU, const size_t threadId)
Definition: OptconSystemInterface.h:108
ct::core::ControlVectorArray< CONTROL_DIM, SCALAR > ControlVectorArray
Definition: OptconSystemInterface.h:40
virtual void setSubstepTrajectoryReference(const StateSubstepsPtr &xSubsteps, const ControlSubstepsPtr &uSubsteps, const size_t threadId)
Definition: OptconSystemInterface.h:109
std::vector< typename optConProblem_t::DynamicsPtr_t > & getNonlinearSystemsInstances()
Definition: OptconSystemInterface.h:102
std::shared_ptr< ControlVectorArray > ControlVectorArrayPtr
Definition: OptconSystemInterface.h:41
std::shared_ptr< ControlSubsteps > ControlSubstepsPtr
Definition: OptconSystemInterface.h:43
virtual void configure(const settings_t &settings)
Definition: OptconSystemInterface.h:63
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)=0
propagate discrete-time dynamics
ct::core::StateControlMatrix< STATE_DIM, CONTROL_DIM, SCALAR > state_control_matrix_t
Definition: OptconSystemInterface.h:33
std::shared_ptr< StateSubsteps > StateSubstepsPtr
Definition: OptconSystemInterface.h:38
ct::core::StateVector< STATE_DIM, SCALAR > state_vector_t
Definition: OptconSystemInterface.h:31
std::shared_ptr< SYSTEM_T > DynamicsPtr_t
Definition: OptConProblemBase.h:50