- 3.0.2 optimal control module.
LQOCSolver.hpp
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 
11 
12 namespace ct {
13 namespace optcon {
14 
21 template <size_t STATE_DIM, size_t CONTROL_DIM, typename SCALAR = double>
23 {
24 public:
25  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
26 
28 
33  LQOCSolver(const std::shared_ptr<LQOCProblem_t>& lqocProblem = nullptr) : lqocProblem_(lqocProblem) {}
34 
35  virtual ~LQOCSolver() = default;
36 
42  void setProblem(std::shared_ptr<LQOCProblem_t> lqocProblem)
43  {
44  setProblemImpl(lqocProblem);
45  lqocProblem_ = lqocProblem;
46  }
47 
48  virtual void configure(const NLOptConSettings& settings) = 0;
49 
51  // return true if configuration changed, otherwise false
52  virtual bool configureInputBoxConstraints(std::shared_ptr<LQOCProblem<STATE_DIM, CONTROL_DIM>> lqocProblem)
53  {
54  throw std::runtime_error("input box constraints are not available for this solver.");
55  }
56 
57  // return true if configuration changed, otherwise false
58  virtual bool configureStateBoxConstraints(std::shared_ptr<LQOCProblem<STATE_DIM, CONTROL_DIM>> lqocProblem)
59  {
60  throw std::runtime_error("state box constraints are not available for this solver.");
61  }
62 
64  // return true if configuration changed, otherwise false
65  virtual bool configureGeneralConstraints(std::shared_ptr<LQOCProblem<STATE_DIM, CONTROL_DIM>> lqocProblem)
66  {
67  throw std::runtime_error("general constraints are not available for this solver.");
68  }
69 
71  virtual void initializeAndAllocate() = 0;
72 
74  virtual void solve() = 0;
75 
76  virtual void solveSingleStage(int N)
77  {
78  throw std::runtime_error("solveSingleStage not available for this solver.");
79  }
80 
82  virtual void computeStatesAndControls() = 0;
87 
89  virtual void computeFeedbackMatrices() = 0;
91 
93  virtual void compute_lv() = 0;
96 
99  {
100  throw std::runtime_error("getSmallestEigenvalue not available for this solver.");
101  }
102 
103 
104 protected:
105  virtual void setProblemImpl(std::shared_ptr<LQOCProblem_t> lqocProblem) = 0;
106 
107  std::shared_ptr<LQOCProblem_t> lqocProblem_;
108 
112  ct::core::ControlVectorArray<CONTROL_DIM, SCALAR> lv_; // feedforward increment (iLQR-style)
113 };
114 
115 } // namespace optcon
116 } // namespace ct
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef LQOCProblem< STATE_DIM, CONTROL_DIM, SCALAR > LQOCProblem_t
Definition: LQOCSolver.hpp:27
const ct::core::ControlVectorArray< CONTROL_DIM, SCALAR > & getSolutionControl()
return solution for control
Definition: LQOCSolver.hpp:86
virtual const ct::core::ControlVectorArray< CONTROL_DIM, SCALAR > & get_lv()
return iLQR-style feedforward lv
Definition: LQOCSolver.hpp:95
virtual bool configureStateBoxConstraints(std::shared_ptr< LQOCProblem< STATE_DIM, CONTROL_DIM >> lqocProblem)
Definition: LQOCSolver.hpp:58
ct::core::FeedbackArray< STATE_DIM, CONTROL_DIM, SCALAR > L_
Definition: LQOCSolver.hpp:111
LQOCSolver(const std::shared_ptr< LQOCProblem_t > &lqocProblem=nullptr)
Definition: LQOCSolver.hpp:33
virtual bool configureGeneralConstraints(std::shared_ptr< LQOCProblem< STATE_DIM, CONTROL_DIM >> lqocProblem)
setup and configure the general (in)equality constraints
Definition: LQOCSolver.hpp:65
virtual void setProblemImpl(std::shared_ptr< LQOCProblem_t > lqocProblem)=0
virtual void solveSingleStage(int N)
Definition: LQOCSolver.hpp:76
virtual SCALAR getSmallestEigenvalue()
return the smallest eigenvalue
Definition: LQOCSolver.hpp:98
virtual void initializeAndAllocate()=0
a method reserved for memory allocation (e.g. required for HPIPM)
virtual void computeStatesAndControls()=0
extract the solution (can be overriden if additional extraction steps required in specific solver) ...
Settings for the NLOptCon algorithm.
Definition: NLOptConSettings.hpp:198
CppAD::AD< CppAD::cg::CG< double > > SCALAR
std::shared_ptr< LQOCProblem_t > lqocProblem_
Definition: LQOCSolver.hpp:107
virtual void computeFeedbackMatrices()=0
return TVLQR feedback matrices
Defines a Linear-Quadratic Optimal Control Problem, which is optionally constrained.
Definition: LQOCProblem.hpp:57
virtual void compute_lv()=0
compute iLQR-style lv
void setProblem(std::shared_ptr< LQOCProblem_t > lqocProblem)
Definition: LQOCSolver.hpp:42
const ct::core::FeedbackArray< STATE_DIM, CONTROL_DIM, SCALAR > & getSolutionFeedback()
Definition: LQOCSolver.hpp:90
virtual void configure(const NLOptConSettings &settings)=0
core::ControlVectorArray< CONTROL_DIM, SCALAR > u_sol_
Definition: LQOCSolver.hpp:110
virtual void solve()=0
solve the LQOC problem
ct::core::ControlVectorArray< CONTROL_DIM, SCALAR > lv_
Definition: LQOCSolver.hpp:112
virtual bool configureInputBoxConstraints(std::shared_ptr< LQOCProblem< STATE_DIM, CONTROL_DIM >> lqocProblem)
setup and configure the box constraints
Definition: LQOCSolver.hpp:52
const ct::core::StateVectorArray< STATE_DIM, SCALAR > & getSolutionState()
return solution for state
Definition: LQOCSolver.hpp:84
core::StateVectorArray< STATE_DIM, SCALAR > x_sol_
Definition: LQOCSolver.hpp:109
virtual ~LQOCSolver()=default
Definition: LQOCSolver.hpp:22