12 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR>
16 Eigen::initParallel();
21 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR>
27 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR>
35 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR>
48 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR>
55 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR>
62 for (
int k = 0; k < this->
lqocProblem_->getNumberOfStages(); k++)
68 this->x_sol_[k + 1] = p.
A_[k] * this->x_sol_[k] + p.
B_[k] * (this->
u_sol_[k]) + p.
b_[k];
72 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR>
77 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR>
82 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR>
88 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR>
91 if (lqocProblem->isConstrained())
93 throw std::runtime_error(
94 "Selected wrong solver - GNRiccatiSolver cannot handle constrained problems. Use a different solver");
97 const int& N = lqocProblem->getNumberOfStages();
102 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR>
121 this->
x_sol_.resize(N + 1);
131 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR>
146 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR>
152 S_[k].noalias() += p.
A_[k].transpose() *
S_[k + 1] * p.
A_[k];
153 S_[k].noalias() -= this->
L_[k].transpose() *
Hi_[k] * this->
L_[k];
155 S_[k] = 0.5 * (
S_[k] +
S_[k].transpose()).eval();
158 sv_[k].noalias() += p.
A_[k].transpose() *
sv_[k + 1];
159 sv_[k].noalias() += p.
A_[k].transpose() *
S_[k + 1] * p.
b_[k];
160 sv_[k].noalias() += this->L_[k].transpose() *
Hi_[k] * this->
lv_[k];
161 sv_[k].noalias() += this->L_[k].transpose() *
gv_[k];
162 sv_[k].noalias() +=
G_[k].transpose() * this->lv_[k];
166 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR>
172 gv_[k].noalias() += p.
B_[k].transpose() *
sv_[k + 1];
173 gv_[k].noalias() += p.
B_[k].transpose() *
S_[k + 1].template selfadjointView<Eigen::Lower>() * p.
b_[k];
177 G_[k].noalias() += p.
B_[k].transpose() *
S_[k + 1].template selfadjointView<Eigen::Lower>() * p.
A_[k];
181 H_[k].noalias() += p.
B_[k].transpose() *
S_[k + 1].template selfadjointView<Eigen::Lower>() * p.
B_[k];
210 D_inverse.diagonal() = -1.0 * D.diagonal().cwiseInverse();
211 ControlMatrix Hi_inverse_regular = V * D_inverse * V.transpose();
213 if (!
Hi_inverse_[k].isApprox(Hi_inverse_regular, 1e-4))
215 std::cout <<
"warning, inverses not identical at " << k << std::endl;
216 std::cout <<
"Hi_inverse_fixed - Hi_inverse_regular: " << std::endl
217 <<
Hi_inverse_[k] - Hi_inverse_regular << std::endl
222 Hi_inverse_[k] = -
Hi_[k].template selfadjointView<Eigen::Lower>().llt().solve(ControlMatrix::Identity());
225 this->
L_[k].noalias() =
Hi_inverse_[k].template selfadjointView<Eigen::Lower>() *
G_[k];
228 this->
lv_[k].noalias() =
Hi_inverse_[k].template selfadjointView<Eigen::Lower>() *
gv_[k];
248 Hi_[k].noalias() = V * D * V.transpose();
253 D_inverse.diagonal() = -1.0 * D.diagonal().cwiseInverse();
254 Hi_inverse_[k].noalias() = V * D_inverse * V.transpose();
265 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR>
268 #ifdef MATLAB_FULL_LOG 270 matFile_.open(
"GNRiccatiSolver.mat");
274 matFile_.put(
"L", this->
L_.toImplementation());
285 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR>
ct::core::StateControlMatrixArray< STATE_DIM, CONTROL_DIM, SCALAR > B_
Definition: LQOCProblem.hpp:207
ct::core::StateMatrixArray< STATE_DIM, SCALAR > A_
affine, time-varying system dynamics in discrete time
Definition: LQOCProblem.hpp:206
void changeNumberOfStages(int N)
Definition: GNRiccatiSolver-impl.hpp:103
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
virtual void compute_lv() override
compute iLQR-style lv
Definition: GNRiccatiSolver-impl.hpp:78
size_t nThreadsEigen
number of threads, for MP version
Definition: NLOptConSettings.hpp:274
ControlMatrix H_corrFix_
Definition: GNRiccatiSolver.hpp:88
virtual void setProblemImpl(std::shared_ptr< LQOCProblem_t > lqocProblem) override
Definition: GNRiccatiSolver-impl.hpp:89
SCALAR smallestEigenvalue_
Definition: GNRiccatiSolver.hpp:95
ct::core::FeedbackArray< STATE_DIM, CONTROL_DIM, SCALAR > L_
Definition: LQOCSolver.hpp:111
ct::core::StateVectorArray< STATE_DIM, SCALAR > b_
Definition: LQOCProblem.hpp:208
virtual void solve() override
solve the LQOC problem
Definition: GNRiccatiSolver-impl.hpp:28
virtual SCALAR getSmallestEigenvalue() override
return the smallest eigenvalue
Definition: GNRiccatiSolver-impl.hpp:83
virtual void configure(const NLOptConSettings &settings) override
Definition: GNRiccatiSolver-impl.hpp:49
double epsilon
the prefix to be stored before the matfile name for logging
Definition: NLOptConSettings.hpp:261
ct::core::StateMatrixArray< STATE_DIM, SCALAR > Q_
Definition: LQOCProblem.hpp:215
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
void initializeCostToGo()
Definition: GNRiccatiSolver-impl.hpp:132
void designController(size_t k)
Definition: GNRiccatiSolver-impl.hpp:167
Defines a Linear-Quadratic Optimal Control Problem, which is optionally constrained.
Definition: LQOCProblem.hpp:57
void logToMatlab()
Definition: GNRiccatiSolver-impl.hpp:266
GNRiccatiSolver(const std::shared_ptr< LQOCProblem_t > &lqocProblem=nullptr)
Definition: GNRiccatiSolver-impl.hpp:13
for i
Definition: mpc_unittest_plotting.m:14
bool fixedHessianCorrection
the maximum admissible number of NLOptCon main iterations
Definition: NLOptConSettings.hpp:270
ControlMatrixArray H_
Definition: GNRiccatiSolver.hpp:85
StateMatrixArray S_
Definition: GNRiccatiSolver.hpp:91
ControlMatrixArray Hi_inverse_
Definition: GNRiccatiSolver.hpp:87
core::ControlVectorArray< CONTROL_DIM, SCALAR > u_sol_
Definition: LQOCSolver.hpp:110
void computeCostToGo(size_t k)
Definition: GNRiccatiSolver-impl.hpp:147
virtual void computeStatesAndControls() override
extract the solution (can be overriden if additional extraction steps required in specific solver) ...
Definition: GNRiccatiSolver-impl.hpp:56
Base & toImplementation()
virtual void computeFeedbackMatrices() override
return TVLQR feedback matrices
Definition: GNRiccatiSolver-impl.hpp:73
ct::core::ControlVectorArray< CONTROL_DIM, SCALAR > lv_
Definition: LQOCSolver.hpp:112
ControlMatrixArray Hi_
Definition: GNRiccatiSolver.hpp:86
ct::core::ControlVectorArray< CONTROL_DIM, SCALAR > rv_
LQ approximation of the pure control penalty.
Definition: LQOCProblem.hpp:218
ct::core::StateVectorArray< STATE_DIM, SCALAR > qv_
LQ approximation of the pure state penalty, including terminal state penalty.
Definition: LQOCProblem.hpp:214
FeedbackArray G_
Definition: GNRiccatiSolver.hpp:83
bool recordSmallestEigenvalue
perform Hessian regularization by incrementing the eigenvalues by epsilon.
Definition: NLOptConSettings.hpp:271
ControlVectorArray gv_
Definition: GNRiccatiSolver.hpp:82
virtual void initializeAndAllocate() override
a method reserved for memory allocation (e.g. required for HPIPM)
Definition: GNRiccatiSolver-impl.hpp:286
int N_
Definition: GNRiccatiSolver.hpp:93
Eigen::SelfAdjointEigenSolver< Eigen::Matrix< SCALAR, CONTROL_DIM, CONTROL_DIM > > eigenvalueSolver_
Eigenvalue solver, used for inverting the Hessian and for regularization.
Definition: GNRiccatiSolver.hpp:98
core::StateVectorArray< STATE_DIM, SCALAR > x_sol_
Definition: LQOCSolver.hpp:109
NLOptConSettings settings_
Definition: GNRiccatiSolver.hpp:80
virtual void solveSingleStage(int N) override
Definition: GNRiccatiSolver-impl.hpp:36
StateVectorArray sv_
Definition: GNRiccatiSolver.hpp:90
Definition: LQOCSolver.hpp:22