- 3.0.2 optimal control module.
LQOCProblem.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 
8 namespace ct {
9 namespace optcon {
10 
56 template <int STATE_DIM, int CONTROL_DIM, typename SCALAR = double>
58 {
59 public:
60  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
61 
62  using constr_vec_t = Eigen::Matrix<SCALAR, -1, -1>;
63  using constr_state_jac_t = Eigen::Matrix<SCALAR, -1, -1>;
64  using constr_control_jac_t = Eigen::Matrix<SCALAR, -1, -1>;
65 
69 
70  using input_box_constr_vec_t = Eigen::Matrix<SCALAR, CONTROL_DIM, 1>;
71  using state_box_constr_vec_t = Eigen::Matrix<SCALAR, STATE_DIM, 1>;
74 
76  using state_box_constr_sparsity_t = Eigen::Matrix<int, STATE_DIM, 1>;
77  using input_box_constr_sparsity_t = Eigen::Matrix<int, CONTROL_DIM, 1>;
78 
81 
82  using VectorXi = Eigen::VectorXi;
83 
85  LQOCProblem(int N = 0);
86 
88  int getNumberOfStages();
89 
91  void changeNumStages(int N);
92 
97  void setZero(const int& nGenConstr = 0);
98 
107  void setInputBoxConstraint(const int index,
108  const int nConstr,
109  const constr_vec_t& u_lb,
110  const constr_vec_t& u_ub,
111  const VectorXi& sp,
113 
122  void setInputBoxConstraints(const int nConstr,
123  const constr_vec_t& u_lb,
124  const constr_vec_t& u_ub,
125  const VectorXi& sp,
127 
137  void setIntermediateStateBoxConstraint(const int index,
138  const int nConstr,
139  const constr_vec_t& x_lb,
140  const constr_vec_t& x_ub,
141  const VectorXi& sp,
143 
152  void setIntermediateStateBoxConstraints(const int nConstr,
153  const constr_vec_t& x_lb,
154  const constr_vec_t& x_ub,
155  const VectorXi& sp,
157 
166  void setTerminalBoxConstraints(const int nConstr,
167  const constr_vec_t& x_lb,
168  const constr_vec_t& x_ub,
169  const VectorXi& sp,
171 
179  void setGeneralConstraints(const constr_vec_t& d_lb,
180  const constr_vec_t& d_ub,
181  const constr_state_jac_t& C,
182  const constr_control_jac_t& D);
183 
195  const ct::core::StateVector<STATE_DIM, SCALAR>& stateOffset,
196  const double dt);
197 
199  bool isConstrained() const;
200 
201  bool isInputBoxConstrained() const;
202  bool isStateBoxConstrained() const;
203  bool isGeneralConstrained() const;
204 
209 
212 
216 
220 
223 
229 
237 
239  std::vector<int> nbu_;
240 
242  std::vector<int> nbx_;
243 
252  std::vector<int> ng_;
253 
254 
255 private:
257  int K_;
258 };
259 
260 } // namespace optcon
261 } // namespace ct
ct::core::StateControlMatrixArray< STATE_DIM, CONTROL_DIM, SCALAR > B_
Definition: LQOCProblem.hpp:207
bool isGeneralConstrained() const
Definition: LQOCProblem-impl.hpp:42
ct::core::StateMatrixArray< STATE_DIM, SCALAR > A_
affine, time-varying system dynamics in discrete time
Definition: LQOCProblem.hpp:206
state_box_constr_sparsity_array_t x_I_
Definition: LQOCProblem.hpp:236
ct::core::ControlMatrixArray< CONTROL_DIM, SCALAR > R_
Definition: LQOCProblem.hpp:219
ct::core::FeedbackArray< STATE_DIM, CONTROL_DIM, SCALAR > P_
LQ approximation of the cross terms of the cost function.
Definition: LQOCProblem.hpp:222
constr_control_jac_array_t D_
Definition: LQOCProblem.hpp:250
void setInputBoxConstraint(const int index, const int nConstr, const constr_vec_t &u_lb, const constr_vec_t &u_ub, const VectorXi &sp, const ct::core::ControlVector< CONTROL_DIM, SCALAR > &u_nom_abs)
set input box constraints at a specific index
Definition: LQOCProblem-impl.hpp:129
ct::core::StateVectorArray< STATE_DIM, SCALAR > b_
Definition: LQOCProblem.hpp:208
Eigen::Matrix< SCALAR, STATE_DIM, 1 > state_box_constr_vec_t
Definition: LQOCProblem.hpp:71
void setTerminalBoxConstraints(const int nConstr, const constr_vec_t &x_lb, const constr_vec_t &x_ub, const VectorXi &sp, const ct::core::StateVector< STATE_DIM, SCALAR > &x_nom_abs)
set box constraints for terminal stage
Definition: LQOCProblem-impl.hpp:217
Eigen::Matrix< SCALAR, CONTROL_DIM, 1 > input_box_constr_vec_t
Definition: LQOCProblem.hpp:70
std::vector< int > ng_
number of general inequality constraints
Definition: LQOCProblem.hpp:252
input_box_constr_array_t u_lb_
bounds of box constraints for input and state
Definition: LQOCProblem.hpp:225
Eigen::Matrix< SCALAR, -1, -1 > constr_state_jac_t
Definition: LQOCProblem.hpp:63
void setInputBoxConstraints(const int nConstr, const constr_vec_t &u_lb, const constr_vec_t &u_ub, const VectorXi &sp, const ct::core::ControlVectorArray< CONTROL_DIM, SCALAR > &u_nom_abs)
set uniform input box constraints, with the same constraint being applied at each intermediate stage ...
Definition: LQOCProblem-impl.hpp:161
Eigen::Matrix< SCALAR, -1, -1 > constr_control_jac_t
Definition: LQOCProblem.hpp:64
ct::core::StateMatrixArray< STATE_DIM, SCALAR > Q_
Definition: LQOCProblem.hpp:215
void setGeneralConstraints(const constr_vec_t &d_lb, const constr_vec_t &d_ub, const constr_state_jac_t &C, const constr_control_jac_t &D)
set general (in)equaltiy constraints, with the same constraint applied at each stage ...
Definition: LQOCProblem-impl.hpp:248
constr_vec_array_t d_ub_
general constraint upper bound
Definition: LQOCProblem.hpp:247
const double dt
Definition: LQOCSolverTiming.cpp:18
Describes a cost function with a quadratic approximation, i.e. one that can compute first and second ...
Definition: CostFunctionQuadratic.hpp:29
std::vector< int > nbx_
the number of state box constraints at every stage.
Definition: LQOCProblem.hpp:242
CppAD::AD< CppAD::cg::CG< double > > SCALAR
Eigen::Matrix< int, CONTROL_DIM, 1 > input_box_constr_sparsity_t
Definition: LQOCProblem.hpp:77
void setIntermediateStateBoxConstraint(const int index, const int nConstr, const constr_vec_t &x_lb, const constr_vec_t &x_ub, const VectorXi &sp, const ct::core::StateVector< STATE_DIM, SCALAR > &x_nom_abs)
set state box constraints at a specific index
Definition: LQOCProblem-impl.hpp:173
input_box_constr_sparsity_array_t u_I_
container for the box constraint sparsity pattern An example for how an element of this array might l...
Definition: LQOCProblem.hpp:235
int getNumberOfStages()
returns the number of discrete time steps in the LQOCP, including terminal stage
Definition: LQOCProblem-impl.hpp:51
state_box_constr_array_t x_ub_
Definition: LQOCProblem.hpp:228
Defines a Linear-Quadratic Optimal Control Problem, which is optionally constrained.
Definition: LQOCProblem.hpp:57
Eigen::VectorXi VectorXi
Definition: LQOCProblem.hpp:82
Eigen::Matrix< int, STATE_DIM, 1 > state_box_constr_sparsity_t
a vector indicating which box constraints are active and which not
Definition: LQOCProblem.hpp:76
constr_state_jac_array_t C_
linear general constraint matrices
Definition: LQOCProblem.hpp:249
void setZero(const int &nGenConstr=0)
set all member variables to zero
Definition: LQOCProblem-impl.hpp:92
bool isConstrained() const
return a flag indicating whether this LQOC Problem is constrained or not
Definition: LQOCProblem-impl.hpp:19
LQOCProblem(int N=0)
constructor
Definition: LQOCProblem-impl.hpp:13
constr_vec_array_t d_lb_
general constraint lower bound
Definition: LQOCProblem.hpp:245
void setIntermediateStateBoxConstraints(const int nConstr, const constr_vec_t &x_lb, const constr_vec_t &x_ub, const VectorXi &sp, const ct::core::StateVectorArray< STATE_DIM, SCALAR > &x_nom_abs)
set uniform state box constraints, with the same constraint being applied at each intermediate stage ...
Definition: LQOCProblem-impl.hpp:205
ct::core::ControlVectorArray< CONTROL_DIM, SCALAR > rv_
LQ approximation of the pure control penalty.
Definition: LQOCProblem.hpp:218
std::vector< int > nbu_
the number of input box constraints at every stage.
Definition: LQOCProblem.hpp:239
ct::core::StateVectorArray< STATE_DIM, SCALAR > qv_
LQ approximation of the pure state penalty, including terminal state penalty.
Definition: LQOCProblem.hpp:214
bool isInputBoxConstrained() const
Definition: LQOCProblem-impl.hpp:24
void changeNumStages(int N)
change the number of discrete time steps in the LQOCP
Definition: LQOCProblem-impl.hpp:57
ct::core::ScalarArray< SCALAR > q_
constant term of in the LQ approximation of the cost function
Definition: LQOCProblem.hpp:211
Eigen::Matrix< SCALAR, -1, -1 > constr_vec_t
Definition: LQOCProblem.hpp:62
bool isStateBoxConstrained() const
Definition: LQOCProblem-impl.hpp:33
void setFromTimeInvariantLinearQuadraticProblem(ct::core::DiscreteLinearSystem< STATE_DIM, CONTROL_DIM, SCALAR > &linearSystem, ct::optcon::CostFunctionQuadratic< STATE_DIM, CONTROL_DIM, SCALAR > &costFunction, const ct::core::StateVector< STATE_DIM, SCALAR > &stateOffset, const double dt)
a convenience method which constructs an unconstrained LQOC Problem from an LTI system and continuous...
Definition: LQOCProblem-impl.hpp:271
state_box_constr_array_t x_lb_
Definition: LQOCProblem.hpp:227
input_box_constr_array_t u_ub_
Definition: LQOCProblem.hpp:226