- 3.0.2 optimal control module.
OptConProblemBase.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 optcon {
13 
14 
34 template <size_t STATE_DIM,
35  size_t CONTROL_DIM,
36  typename SYSTEM_T,
37  typename LINEAR_SYSTEM_T,
38  typename LINEARIZER_T,
39  typename SCALAR = double>
41 {
42 public:
43  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
44 
45  static const size_t STATE_D = STATE_DIM;
46  static const size_t CONTROL_D = CONTROL_DIM;
47 
48  // typedefs
50  typedef std::shared_ptr<SYSTEM_T> DynamicsPtr_t;
51  typedef std::shared_ptr<LINEAR_SYSTEM_T> LinearPtr_t;
52  typedef std::shared_ptr<optcon::CostFunctionQuadratic<STATE_DIM, CONTROL_DIM, SCALAR>> CostFunctionPtr_t;
53  typedef std::shared_ptr<optcon::LinearConstraintContainer<STATE_DIM, CONTROL_DIM, SCALAR>> ConstraintPtr_t;
54  typedef typename SYSTEM_T::time_t time_t;
55 
56  OptConProblemBase() = default;
57 
67  OptConProblemBase(DynamicsPtr_t nonlinDynamics, CostFunctionPtr_t costFunction, LinearPtr_t linearSystem = nullptr);
68 
77  OptConProblemBase(const time_t tf,
78  const state_vector_t& x0,
79  DynamicsPtr_t nonlinDynamics,
80  CostFunctionPtr_t costFunction,
81  LinearPtr_t linearSystem = nullptr);
82 
96  OptConProblemBase(DynamicsPtr_t nonlinDynamics,
97  CostFunctionPtr_t costFunction,
98  ConstraintPtr_t inputBoxConstraints,
99  ConstraintPtr_t stateBoxConstraints,
100  ConstraintPtr_t generalConstraints,
101  LinearPtr_t linearSystem = nullptr);
102 
118  OptConProblemBase(const time_t tf,
119  const state_vector_t& x0,
120  DynamicsPtr_t nonlinDynamics,
121  CostFunctionPtr_t costFunction,
122  ConstraintPtr_t inputBoxConstraints,
123  ConstraintPtr_t stateBoxConstraints,
124  ConstraintPtr_t generalConstraints,
125  LinearPtr_t linearSystem = nullptr);
126 
128  void verify() const;
129 
133  const DynamicsPtr_t getNonlinearSystem() const;
134 
138  const LinearPtr_t getLinearSystem() const;
139 
143  const CostFunctionPtr_t getCostFunction() const;
144 
148  void setNonlinearSystem(const DynamicsPtr_t dyn);
149 
153  void setLinearSystem(const LinearPtr_t lin);
154 
158  void setCostFunction(const CostFunctionPtr_t cost);
159 
164  void setInputBoxConstraints(const ConstraintPtr_t constraint);
165 
170  void setStateBoxConstraints(const ConstraintPtr_t constraint);
171 
176  void setGeneralConstraints(const ConstraintPtr_t constraint);
177 
183  const ConstraintPtr_t getInputBoxConstraints() const;
184 
190  const ConstraintPtr_t getStateBoxConstraints() const;
191 
197  const ConstraintPtr_t getGeneralConstraints() const;
198 
202  const state_vector_t getInitialState() const;
203 
207  void setInitialState(const state_vector_t& x0);
208 
213  time_t getTimeHorizon() const;
214 
219  void setTimeHorizon(const time_t tf);
220 
221 
222 private:
223  time_t tf_;
224 
225  state_vector_t x0_;
226 
227  DynamicsPtr_t controlledSystem_;
228  CostFunctionPtr_t costFunction_;
229  LinearPtr_t linearizedSystem_;
230 
236  ConstraintPtr_t inputBoxConstraints_;
237 
243  ConstraintPtr_t stateBoxConstraints_;
244 
250  ConstraintPtr_t generalConstraints_;
251 };
252 
253 } // namespace optcon
254 } // namespace ct
void setInputBoxConstraints(const ConstraintPtr_t constraint)
Definition: OptConProblemBase-impl.h:211
ct::core::StateVector< STATE_DIM, SCALAR > state_vector_t
Definition: OptConProblemBase.h:49
const LinearPtr_t getLinearSystem() const
Definition: OptConProblemBase-impl.h:151
const ConstraintPtr_t getInputBoxConstraints() const
Retrieve the input box constraints.
Definition: OptConProblemBase-impl.h:255
void setStateBoxConstraints(const ConstraintPtr_t constraint)
Definition: OptConProblemBase-impl.h:225
const DynamicsPtr_t getNonlinearSystem() const
Definition: OptConProblemBase-impl.h:138
const state_vector_t getInitialState() const
Definition: OptConProblemBase-impl.h:297
std::shared_ptr< optcon::CostFunctionQuadratic< STATE_DIM, CONTROL_DIM, SCALAR > > CostFunctionPtr_t
Definition: OptConProblemBase.h:52
void setLinearSystem(const LinearPtr_t lin)
Definition: OptConProblemBase-impl.h:187
void setNonlinearSystem(const DynamicsPtr_t dyn)
Definition: OptConProblemBase-impl.h:175
const CostFunctionPtr_t getCostFunction() const
Definition: OptConProblemBase-impl.h:164
void setCostFunction(const CostFunctionPtr_t cost)
Definition: OptConProblemBase-impl.h:199
std::shared_ptr< optcon::LinearConstraintContainer< STATE_DIM, CONTROL_DIM, SCALAR > > ConstraintPtr_t
Definition: OptConProblemBase.h:53
CppAD::AD< CppAD::cg::CG< double > > SCALAR
void setInitialState(const state_vector_t &x0)
Definition: OptConProblemBase-impl.h:308
SYSTEM_T::time_t time_t
Definition: OptConProblemBase.h:54
time_t getTimeHorizon() const
Definition: OptConProblemBase-impl.h:321
std::shared_ptr< LINEAR_SYSTEM_T > LinearPtr_t
Definition: OptConProblemBase.h:51
const ConstraintPtr_t getGeneralConstraints() const
Retrieves the general constraints.
Definition: OptConProblemBase-impl.h:283
const ConstraintPtr_t getStateBoxConstraints() const
Retrieve the state box constraints.
Definition: OptConProblemBase-impl.h:269
static const size_t CONTROL_D
Definition: OptConProblemBase.h:46
void setGeneralConstraints(const ConstraintPtr_t constraint)
Definition: OptConProblemBase-impl.h:239
void setTimeHorizon(const time_t tf)
Definition: OptConProblemBase-impl.h:332
StateVector< state_dim > x0
Definition: ConstrainedNLOCTest.cpp:14
Definition: OptConProblemBase.h:40
static EIGEN_MAKE_ALIGNED_OPERATOR_NEW const size_t STATE_D
Definition: OptConProblemBase.h:45
void verify() const
check if all the ingredients for an unconstrained optimal control problem are there ...
Definition: OptConProblemBase-impl.h:110
std::shared_ptr< SYSTEM_T > DynamicsPtr_t
Definition: OptConProblemBase.h:50