4#ifndef CGMRES__OCP_PENDUBOT_HPP_
5#define CGMRES__OCP_PENDUBOT_HPP_
7#define _USE_MATH_DEFINES
28 static constexpr int nx = 4;
33 static constexpr int nu = 1;
38 static constexpr int nc = 0;
43 static constexpr int nh = 0;
53 static constexpr int nub = 1;
65 std::array<double, 4>
q = {1, 1, 0.1, 0.1};
68 std::array<double, 1>
r = {0.1};
71 std::array<double, nub>
umin = {-5.0};
72 std::array<double, nub>
umax = {5.0};
76 os <<
"OCP_pendubot:" << std::endl;
77 os <<
" nx: " <<
nx << std::endl;
78 os <<
" nu: " <<
nu << std::endl;
79 os <<
" nc: " <<
nc << std::endl;
80 os <<
" nh: " <<
nh << std::endl;
81 os <<
" nuc: " <<
nuc << std::endl;
82 os <<
" nub: " <<
nub << std::endl;
84 os <<
" m1: " <<
m1 << std::endl;
85 os <<
" m2: " <<
m2 << std::endl;
86 os <<
" l1: " <<
l1 << std::endl;
87 os <<
" l2: " <<
l2 << std::endl;
88 os <<
" d1: " <<
d1 << std::endl;
89 os <<
" d2: " <<
d2 << std::endl;
90 os <<
" J1: " <<
J1 << std::endl;
91 os <<
" J2: " <<
J2 << std::endl;
92 os <<
" g: " <<
g << std::endl;
94 Eigen::IOFormat
fmt(4, 0,
", ",
"",
"[",
"]");
95 Eigen::IOFormat
intfmt(1, 0,
", ",
"",
"[",
"]");
129 void eval_f(
const double t,
const double* x,
const double*
u,
135 const double x4 =
x3*
cos(x[1]);
139 const double x8 = 1.0/(
x1 + 2.0*
x4 +
x6 +
x7);
143 const double x12 =
sin(x[0]);
144 const double x13 =
sin(x[1]);
145 const double x14 = 2.0*x[1];
146 const double x15 = 0.5*
l1;
149 const double x18 =
pow(x[2], 2.0);
150 const double x19 = x[2]*x[3];
151 const double x20 =
pow(x[3], 2.0);
187 void eval_hx(
const double t,
const double* x,
const double*
u,
188 const double* lmd,
double*
hx)
const {
189 const double x0 = x[0] + x[1];
190 const double x1 =
d2*
g;
195 const double x6 =
x4 +
x5;
196 const double x7 =
cos(x[0]);
199 const double x10 =
cos(x[1]);
208 const double x19 = lmd[2]*
x18;
209 const double x20 = 0.5*
l1;
212 const double x23 = 2.0*x[1];
213 const double x24 =
x23 + x[0];
215 const double x26 = x[0] - x[1];
217 const double x28 = 0.5*
x9;
221 const double x32 = lmd[3]/
x15;
223 const double x34 = x[2] + 0.5*x[3];
225 const double x36 =
sin(x[0]);
226 const double x37 =
sin(x[1]);
229 const double x40 =
pow(x[2], 2.0);
230 const double x41 = x[2]*x[3];
231 const double x42 =
pow(x[3], 2.0);
233 const double x44 = 2.0*
J2;
235 const double x46 = x[2] + x[3];
238 const double x49 =
x38*x[3];
239 const double x50 = 2.0*
pow(x[2], 1.0);
241 const double x52 =
pow(x[3], 1.0);
260 void eval_hu(
const double t,
const double* x,
const double*
u,
261 const double* lmd,
double*
hu)
const {
276 template <
typename VectorType1,
typename VectorType2,
typename VectorType3>
280 if (x.size() !=
nx) {
281 throw std::invalid_argument(
"[OCP]: x.size() must be " + std::to_string(
nx));
283 if (
u.size() !=
nu) {
284 throw std::invalid_argument(
"[OCP]: u.size() must be " + std::to_string(
nu));
286 if (
dx.size() !=
nx) {
287 throw std::invalid_argument(
"[OCP]: dx.size() must be " + std::to_string(
nx));
299 template <
typename VectorType1,
typename VectorType2>
302 if (x.size() !=
nx) {
303 throw std::invalid_argument(
"[OCP]: x.size() must be " + std::to_string(
nx));
306 throw std::invalid_argument(
"[OCP]: phix.size() must be " + std::to_string(
nx));
320 template <
typename VectorType1,
typename VectorType2,
typename VectorType3,
typename VectorType4>
325 if (x.size() !=
nx) {
326 throw std::invalid_argument(
"[OCP]: x.size() must be " + std::to_string(
nx));
328 if (
uc.size() !=
nuc) {
329 throw std::invalid_argument(
"[OCP]: uc.size() must be " + std::to_string(
nuc));
331 if (lmd.size() !=
nx) {
332 throw std::invalid_argument(
"[OCP]: lmd.size() must be " + std::to_string(
nx));
334 if (
hx.size() !=
nuc) {
335 throw std::invalid_argument(
"[OCP]: hx.size() must be " + std::to_string(
nx));
349 template <
typename VectorType1,
typename VectorType2,
typename VectorType3,
typename VectorType4>
354 if (x.size() !=
nx) {
355 throw std::invalid_argument(
"[OCP]: x.size() must be " + std::to_string(
nx));
357 if (
uc.size() !=
nuc) {
358 throw std::invalid_argument(
"[OCP]: uc.size() must be " + std::to_string(
nuc));
360 if (lmd.size() !=
nx) {
361 throw std::invalid_argument(
"[OCP]: lmd.size() must be " + std::to_string(
nx));
363 if (
hu.size() !=
nuc) {
364 throw std::invalid_argument(
"[OCP]: hu.size() must be " + std::to_string(
nuc));
Definition of the optimal control problem (OCP) of pendubot.
Definition ocp.hpp:22
static constexpr int nh
Dimension of the Fischer-Burmeister function (already counded in nc).
Definition ocp.hpp:43
friend std::ostream & operator<<(std::ostream &os, const OCP_pendubot &ocp)
Definition ocp.hpp:107
void eval_hx(const double t, const double *x, const double *u, const double *lmd, double *hx) const
Computes the partial derivative of the Hamiltonian with respect to state, i.e., hx = dH/dx(t,...
Definition ocp.hpp:187
void disp(std::ostream &os) const
Definition ocp.hpp:75
std::array< double, nub > umax
Definition ocp.hpp:72
double d1
Definition ocp.hpp:59
static constexpr int nu
Dimension of the control input.
Definition ocp.hpp:33
double l2
Definition ocp.hpp:58
static constexpr int nuc
Dimension of the concatenation of the control input and equality constraints.
Definition ocp.hpp:48
void eval_hu(const double t, const MatrixBase< VectorType1 > &x, const MatrixBase< VectorType2 > &uc, const MatrixBase< VectorType3 > &lmd, const MatrixBase< VectorType4 > &hu) const
Computes the partial derivative of the Hamiltonian with respect to control input and the equality con...
Definition ocp.hpp:350
void eval_hx(const double t, const MatrixBase< VectorType1 > &x, const MatrixBase< VectorType2 > &uc, const MatrixBase< VectorType3 > &lmd, const MatrixBase< VectorType4 > &hx) const
Computes the partial derivative of the Hamiltonian with respect to the state, i.e....
Definition ocp.hpp:321
std::array< double, nub > dummy_weight
Definition ocp.hpp:73
double g
Definition ocp.hpp:63
void eval_phix(const double t, const double *x, double *phix) const
Computes the partial derivative of terminal cost with respect to state, i.e., phix = dphi/dx(t,...
Definition ocp.hpp:168
std::array< double, 1 > r
Definition ocp.hpp:68
std::array< double, 4 > q
Definition ocp.hpp:65
std::array< double, 4 > x_ref
Definition ocp.hpp:67
double m1
Definition ocp.hpp:55
void eval_f(const double t, const double *x, const double *u, double *dx) const
Computes the state equation dx = f(t, x, u).
Definition ocp.hpp:129
void synchronize()
Synchrozies the internal parameters of this OCP with the external references. This method is called a...
Definition ocp.hpp:117
std::array< double, nub > umin
Definition ocp.hpp:71
double m2
Definition ocp.hpp:56
static constexpr int nub
Dimension of the bound constraints on the control input.
Definition ocp.hpp:53
double d2
Definition ocp.hpp:60
std::array< double, 4 > q_terminal
Definition ocp.hpp:66
double l1
Definition ocp.hpp:57
double J1
Definition ocp.hpp:61
double J2
Definition ocp.hpp:62
static constexpr std::array< int, nub > ubound_indices
Definition ocp.hpp:70
void eval_phix(const double t, const MatrixBase< VectorType1 > &x, const MatrixBase< VectorType2 > &phix) const
Computes the partial derivative of terminal cost with respect to state, i.e., phix = dphi/dx(t,...
Definition ocp.hpp:300
static constexpr int nx
Dimension of the state.
Definition ocp.hpp:28
static constexpr int nc
Dimension of the equality constraints.
Definition ocp.hpp:38
void eval_hu(const double t, const double *x, const double *u, const double *lmd, double *hu) const
Computes the partial derivative of the Hamiltonian with respect to control input and the equality con...
Definition ocp.hpp:260
void eval_f(const double t, const MatrixBase< VectorType1 > &x, const MatrixBase< VectorType2 > &u, const MatrixBase< VectorType3 > &dx) const
Computes the state equation dx = f(t, x, u).
Definition ocp.hpp:277
#define CGMRES_EIGEN_CONST_CAST(TYPE, OBJ)
Definition macros.hpp:7
Definition continuation_gmres.hpp:11
Eigen::Map< MatrixType > Map
Alias of Eigen::Map.
Definition types.hpp:54