4#ifndef CGMRES__OCP_HEXACOPTER_HPP_
5#define CGMRES__OCP_HEXACOPTER_HPP_
7#define _USE_MATH_DEFINES
28 static constexpr int nx = 12;
33 static constexpr int nu = 6;
38 static constexpr int nc = 0;
43 static constexpr int nh = 0;
53 static constexpr int nub = 6;
65 std::array<double, 12>
q = {1, 1, 1, 0.01, 0.01, 0, 0.01, 0.01, 0.01, 0.1, 0.1, 0.001};
66 std::array<double, 12>
q_terminal = {1, 1, 1, 0.01, 0.01, 0, 0.01, 0.01, 0.01, 0.1, 0.1, 0.001};
67 std::array<double, 6>
r = {0.01, 0.01, 0.01, 0.01, 0.01, 0.01};
70 std::array<double, nub>
umin = {0.144, 0.144, 0.144, 0.144, 0.144, 0.144};
71 std::array<double, nub>
umax = {6.0, 6.0, 6.0, 6.0, 6.0, 6.0};
72 std::array<double, nub>
dummy_weight = {0.1, 0.1, 0.1, 0.1, 0.1, 0.1};
75 os <<
"OCP_hexacopter:" << std::endl;
76 os <<
" nx: " <<
nx << std::endl;
77 os <<
" nu: " <<
nu << std::endl;
78 os <<
" nc: " <<
nc << std::endl;
79 os <<
" nh: " <<
nh << std::endl;
80 os <<
" nuc: " <<
nuc << std::endl;
81 os <<
" nub: " <<
nub << std::endl;
83 os <<
" m: " <<
m << std::endl;
84 os <<
" l: " <<
l << std::endl;
85 os <<
" k: " <<
k << std::endl;
86 os <<
" Ixx: " <<
Ixx << std::endl;
87 os <<
" Iyy: " <<
Iyy << std::endl;
88 os <<
" Izz: " <<
Izz << std::endl;
89 os <<
" gamma: " <<
gamma << std::endl;
90 os <<
" g: " <<
g << std::endl;
91 os <<
" z_ref: " <<
z_ref << std::endl;
93 Eigen::IOFormat
fmt(4, 0,
", ",
"",
"[",
"]");
94 Eigen::IOFormat
intfmt(1, 0,
", ",
"",
"[",
"]");
127 void eval_f(
const double t,
const double* x,
const double*
u,
129 const double x0 =
sin(x[3]);
130 const double x1 =
sin(x[5]);
131 const double x2 =
cos(x[5]);
132 const double x3 =
cos(x[3]);
133 const double x4 =
sin(x[4]);
134 const double x5 = 1.0/
m;
135 const double x6 =
u[0] +
u[2] +
u[4];
136 const double x7 =
u[1] +
u[3] +
u[5] +
x6;
138 const double x9 = 1.0/
Ixx;
140 const double x11 = (1.0/2.0)*
u[0];
141 const double x12 = 1.0/
Iyy;
143 const double x14 = 1.0/
Izz;
153 dx[9] =
l*
x9*(-
u[1] - 1.0/2.0*
u[2] + (1.0/2.0)*
u[3] +
u[4] + (1.0/2.0)*
u[5] -
x11) +
x9*x[10]*x[11]*(
Iyy +
x10);
169 const double x0 = 2*
t;
198 void eval_hx(
const double t,
const double* x,
const double*
u,
199 const double* lmd,
double*
hx)
const {
200 const double x0 = 2*
t;
203 const double x3 =
sin(x[3]);
204 const double x4 =
cos(x[4]);
205 const double x5 = (
u[0] +
u[1] +
u[2] +
u[3] +
u[4] +
u[5])/
m;
206 const double x6 = lmd[8]*
x5;
207 const double x7 =
sin(x[5]);
208 const double x8 =
cos(x[3]);
209 const double x9 =
sin(x[4]);
210 const double x10 =
cos(x[5]);
212 const double x12 = lmd[6]*
x5;
215 const double x15 = lmd[7]*
x5;
219 const double x19 = lmd[11]/
Izz;
222 hx[0] = (1.0/2.0)*
q[0]*(-2*
x1 + 2*x[0]);
223 hx[1] = (1.0/2.0)*
q[1]*(2*
x2 + 2*x[1] - 2);
228 hx[6] = lmd[0] + (1.0/2.0)*
q[6]*(-4*
x2 + 2*x[6]);
229 hx[7] = lmd[1] + (1.0/2.0)*
q[7]*(-4*
x1 + 2*x[7]);
230 hx[8] = lmd[2] + (1.0/2.0)*
q[8]*(2*x[8] - 4*
cos(
t));
231 hx[9] = lmd[3] +
q[9]*x[9] +
x18*x[11] +
x20*x[10];
232 hx[10] = lmd[4] +
q[10]*x[10] +
x20*x[9] +
x21*x[11];
248 void eval_hu(
const double t,
const double* x,
const double*
u,
249 const double* lmd,
double*
hu)
const {
250 const double x0 = (1.0/3.0)*
g*
m;
251 const double x1 = (1.0/2.0)*
sqrt(3)*
l*lmd[10]/
Iyy;
252 const double x2 = -
x1;
253 const double x3 =
l*lmd[9]/
Ixx;
254 const double x4 = (1.0/2.0)*
x3;
255 const double x5 =
k*lmd[11]/
Izz;
256 const double x6 = 1.0/
m;
257 const double x7 =
sin(x[3]);
258 const double x8 =
sin(x[5]);
259 const double x9 =
cos(x[5]);
260 const double x10 =
cos(x[3]);
261 const double x11 =
sin(x[4]);
283 template <
typename VectorType1,
typename VectorType2,
typename VectorType3>
287 if (x.size() !=
nx) {
288 throw std::invalid_argument(
"[OCP]: x.size() must be " + std::to_string(
nx));
290 if (
u.size() !=
nu) {
291 throw std::invalid_argument(
"[OCP]: u.size() must be " + std::to_string(
nu));
293 if (
dx.size() !=
nx) {
294 throw std::invalid_argument(
"[OCP]: dx.size() must be " + std::to_string(
nx));
306 template <
typename VectorType1,
typename VectorType2>
309 if (x.size() !=
nx) {
310 throw std::invalid_argument(
"[OCP]: x.size() must be " + std::to_string(
nx));
313 throw std::invalid_argument(
"[OCP]: phix.size() must be " + std::to_string(
nx));
327 template <
typename VectorType1,
typename VectorType2,
typename VectorType3,
typename VectorType4>
332 if (x.size() !=
nx) {
333 throw std::invalid_argument(
"[OCP]: x.size() must be " + std::to_string(
nx));
335 if (
uc.size() !=
nuc) {
336 throw std::invalid_argument(
"[OCP]: uc.size() must be " + std::to_string(
nuc));
338 if (lmd.size() !=
nx) {
339 throw std::invalid_argument(
"[OCP]: lmd.size() must be " + std::to_string(
nx));
341 if (
hx.size() !=
nuc) {
342 throw std::invalid_argument(
"[OCP]: hx.size() must be " + std::to_string(
nx));
356 template <
typename VectorType1,
typename VectorType2,
typename VectorType3,
typename VectorType4>
361 if (x.size() !=
nx) {
362 throw std::invalid_argument(
"[OCP]: x.size() must be " + std::to_string(
nx));
364 if (
uc.size() !=
nuc) {
365 throw std::invalid_argument(
"[OCP]: uc.size() must be " + std::to_string(
nuc));
367 if (lmd.size() !=
nx) {
368 throw std::invalid_argument(
"[OCP]: lmd.size() must be " + std::to_string(
nx));
370 if (
hu.size() !=
nuc) {
371 throw std::invalid_argument(
"[OCP]: hu.size() must be " + std::to_string(
nuc));
Definition of the optimal control problem (OCP) of hexacopter.
Definition ocp.hpp:22
std::array< double, nub > umin
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:307
std::array< double, 12 > q_terminal
Definition ocp.hpp:66
double Iyy
Definition ocp.hpp:59
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:198
static constexpr int nh
Dimension of the Fischer-Burmeister function (already counded in nc).
Definition ocp.hpp:43
double Izz
Definition ocp.hpp:60
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:127
double z_ref
Definition ocp.hpp:63
double Ixx
Definition ocp.hpp:58
void disp(std::ostream &os) const
Definition ocp.hpp:74
void synchronize()
Synchrozies the internal parameters of this OCP with the external references. This method is called a...
Definition ocp.hpp:115
static constexpr std::array< int, nub > ubound_indices
Definition ocp.hpp:69
std::array< double, nub > dummy_weight
Definition ocp.hpp:72
std::array< double, nub > umax
Definition ocp.hpp:71
static constexpr int nub
Dimension of the bound constraints on the control input.
Definition ocp.hpp:53
static constexpr int nc
Dimension of the equality constraints.
Definition ocp.hpp:38
double k
Definition ocp.hpp:57
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:248
double gamma
Definition ocp.hpp:61
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:328
std::array< double, 12 > q
Definition ocp.hpp:65
double g
Definition ocp.hpp:62
friend std::ostream & operator<<(std::ostream &os, const OCP_hexacopter &ocp)
Definition ocp.hpp:105
double l
Definition ocp.hpp:56
std::array< double, 6 > r
Definition ocp.hpp:67
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:357
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:284
static constexpr int nu
Dimension of the control input.
Definition ocp.hpp:33
static constexpr int nx
Dimension of the state.
Definition ocp.hpp:28
double m
Definition ocp.hpp:55
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
#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