autogenu-jupyter
An automatic code generator and the continuation/GMRES (C/GMRES) based numerical solvers for nonlinear MPC
Loading...
Searching...
No Matches
cgmres::OCP_cartpole Class Reference

Definition of the optimal control problem (OCP) of cartpole. More...

#include <ocp.hpp>

Public Member Functions

void disp (std::ostream &os) const
 
void synchronize ()
 Synchrozies the internal parameters of this OCP with the external references. This method is called at the beginning of each MPC update. More...
 
void eval_f (const double t, const double *x, const double *u, double *dx) const
 Computes the state equation dx = f(t, x, u). More...
 
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, x). More...
 
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, x, u, lmd). More...
 
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 constraints, i.e., hu = dH/du(t, x, u, lmd). More...
 
template<typename VectorType1 , typename VectorType2 , typename VectorType3 >
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). More...
 
template<typename VectorType1 , typename VectorType2 >
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, x). More...
 
template<typename VectorType1 , typename VectorType2 , typename VectorType3 , typename VectorType4 >
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., hx = dH/dx(t, x, u, lmd). More...
 
template<typename VectorType1 , typename VectorType2 , typename VectorType3 , typename VectorType4 >
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 constraints, i.e., hu = dH/du(t, x, u, lmd). More...
 

Public Attributes

double m_c = 2
 
double m_p = 0.2
 
double l = 0.5
 
double g = 9.80665
 
std::array< double, 4 > q = {2.5, 10, 0.01, 0.01}
 
std::array< double, 4 > q_terminal = {2.5, 10, 0.01, 0.01}
 
std::array< double, 4 > x_ref = {0, M_PI, 0, 0}
 
std::array< double, 1 > r = {1}
 
std::array< double, nubumin = {-15.0}
 
std::array< double, nubumax = {15.0}
 
std::array< double, nubdummy_weight = {0.1}
 

Static Public Attributes

static constexpr int nx = 4
 Dimension of the state. More...
 
static constexpr int nu = 1
 Dimension of the control input. More...
 
static constexpr int nc = 0
 Dimension of the equality constraints. More...
 
static constexpr int nh = 0
 Dimension of the Fischer-Burmeister function (already counded in nc). More...
 
static constexpr int nuc = nu + nc
 Dimension of the concatenation of the control input and equality constraints. More...
 
static constexpr int nub = 1
 Dimension of the bound constraints on the control input. More...
 
static constexpr std::array< int, nububound_indices = {0}
 

Friends

std::ostream & operator<< (std::ostream &os, const OCP_cartpole &ocp)
 

Detailed Description

Definition of the optimal control problem (OCP) of cartpole.

Member Function Documentation

◆ disp()

void cgmres::OCP_cartpole::disp ( std::ostream &  os) const
inline

◆ eval_f() [1/2]

void cgmres::OCP_cartpole::eval_f ( const double  t,
const double *  x,
const double *  u,
double *  dx 
) const
inline

Computes the state equation dx = f(t, x, u).

Parameters
[in]tTime.
[in]xState.
[in]uControl input.
[out]dxEvaluated value of the state equation.
Remarks
This method is intended to be used inside of the cgmres solvers and does not check size of each argument. Use the overloaded method if you call this outside of the cgmres solvers.

◆ eval_f() [2/2]

template<typename VectorType1 , typename VectorType2 , typename VectorType3 >
void cgmres::OCP_cartpole::eval_f ( const double  t,
const MatrixBase< VectorType1 > &  x,
const MatrixBase< VectorType2 > &  u,
const MatrixBase< VectorType3 > &  dx 
) const
inline

Computes the state equation dx = f(t, x, u).

Parameters
[in]tTime.
[in]xState. Size must be nx.
[in]uControl input. Size must be nu.
[out]dxEvaluated value of the state equation. Size must be nx.

◆ eval_hu() [1/2]

void cgmres::OCP_cartpole::eval_hu ( const double  t,
const double *  x,
const double *  u,
const double *  lmd,
double *  hu 
) const
inline

Computes the partial derivative of the Hamiltonian with respect to control input and the equality constraints, i.e., hu = dH/du(t, x, u, lmd).

Parameters
[in]tTime.
[in]xState.
[in]uConcatenatin of the control input and Lagrange multiplier with respect to the equality constraints.
[in]lmdCostate.
[out]huEvaluated value of the partial derivative of the Hamiltonian.
Remarks
This method is intended to be used inside of the cgmres solvers and does not check size of each argument. Use the overloaded method if you call this outside of the cgmres solvers.

◆ eval_hu() [2/2]

template<typename VectorType1 , typename VectorType2 , typename VectorType3 , typename VectorType4 >
void cgmres::OCP_cartpole::eval_hu ( const double  t,
const MatrixBase< VectorType1 > &  x,
const MatrixBase< VectorType2 > &  uc,
const MatrixBase< VectorType3 > &  lmd,
const MatrixBase< VectorType4 > &  hu 
) const
inline

Computes the partial derivative of the Hamiltonian with respect to control input and the equality constraints, i.e., hu = dH/du(t, x, u, lmd).

Parameters
[in]tTime.
[in]xState. Size must be nx.
[in]ucConcatenatin of the control input and Lagrange multiplier with respect to the equality constraints. Size must be nuc.
[in]lmdCostate. Size must be nx.
[out]huEvaluated value of the partial derivative of the Hamiltonian. Size must be nuc.

◆ eval_hx() [1/2]

void cgmres::OCP_cartpole::eval_hx ( const double  t,
const double *  x,
const double *  u,
const double *  lmd,
double *  hx 
) const
inline

Computes the partial derivative of the Hamiltonian with respect to state, i.e., hx = dH/dx(t, x, u, lmd).

Parameters
[in]tTime.
[in]xState.
[in]uConcatenatin of the control input and Lagrange multiplier with respect to the equality constraints.
[in]lmdCostate.
[out]hxEvaluated value of the partial derivative of the Hamiltonian.
Remarks
This method is intended to be used inside of the cgmres solvers and does not check size of each argument. Use the overloaded method if you call this outside of the cgmres solvers.

◆ eval_hx() [2/2]

template<typename VectorType1 , typename VectorType2 , typename VectorType3 , typename VectorType4 >
void cgmres::OCP_cartpole::eval_hx ( const double  t,
const MatrixBase< VectorType1 > &  x,
const MatrixBase< VectorType2 > &  uc,
const MatrixBase< VectorType3 > &  lmd,
const MatrixBase< VectorType4 > &  hx 
) const
inline

Computes the partial derivative of the Hamiltonian with respect to the state, i.e., hx = dH/dx(t, x, u, lmd).

Parameters
[in]tTime.
[in]xState. Size must be nx.
[in]ucConcatenatin of the control input and Lagrange multiplier with respect to the equality constraints. Size must be nuc.
[in]lmdCostate. Size must be nx.
[out]hxEvaluated value of the partial derivative of the Hamiltonian. Size must be nx.

◆ eval_phix() [1/2]

void cgmres::OCP_cartpole::eval_phix ( const double  t,
const double *  x,
double *  phix 
) const
inline

Computes the partial derivative of terminal cost with respect to state, i.e., phix = dphi/dx(t, x).

Parameters
[in]tTime.
[in]xState.
[out]phixEvaluated value of the partial derivative of terminal cost.
Remarks
This method is intended to be used inside of the cgmres solvers and does not check size of each argument. Use the overloaded method if you call this outside of the cgmres solvers.

◆ eval_phix() [2/2]

template<typename VectorType1 , typename VectorType2 >
void cgmres::OCP_cartpole::eval_phix ( const double  t,
const MatrixBase< VectorType1 > &  x,
const MatrixBase< VectorType2 > &  phix 
) const
inline

Computes the partial derivative of terminal cost with respect to state, i.e., phix = dphi/dx(t, x).

Parameters
[in]tTime.
[in]xState. Size must be nx.
[out]phixEvaluated value of the partial derivative of terminal cost. Size must be nx.

◆ synchronize()

void cgmres::OCP_cartpole::synchronize ( )
inline

Synchrozies the internal parameters of this OCP with the external references. This method is called at the beginning of each MPC update.

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const OCP_cartpole ocp 
)
friend

Member Data Documentation

◆ dummy_weight

std::array<double, nub> cgmres::OCP_cartpole::dummy_weight = {0.1}

◆ g

double cgmres::OCP_cartpole::g = 9.80665

◆ l

double cgmres::OCP_cartpole::l = 0.5

◆ m_c

double cgmres::OCP_cartpole::m_c = 2

◆ m_p

double cgmres::OCP_cartpole::m_p = 0.2

◆ nc

constexpr int cgmres::OCP_cartpole::nc = 0
staticconstexpr

Dimension of the equality constraints.

◆ nh

constexpr int cgmres::OCP_cartpole::nh = 0
staticconstexpr

Dimension of the Fischer-Burmeister function (already counded in nc).

◆ nu

constexpr int cgmres::OCP_cartpole::nu = 1
staticconstexpr

Dimension of the control input.

◆ nub

constexpr int cgmres::OCP_cartpole::nub = 1
staticconstexpr

Dimension of the bound constraints on the control input.

◆ nuc

constexpr int cgmres::OCP_cartpole::nuc = nu + nc
staticconstexpr

Dimension of the concatenation of the control input and equality constraints.

◆ nx

constexpr int cgmres::OCP_cartpole::nx = 4
staticconstexpr

Dimension of the state.

◆ q

std::array<double, 4> cgmres::OCP_cartpole::q = {2.5, 10, 0.01, 0.01}

◆ q_terminal

std::array<double, 4> cgmres::OCP_cartpole::q_terminal = {2.5, 10, 0.01, 0.01}

◆ r

std::array<double, 1> cgmres::OCP_cartpole::r = {1}

◆ ubound_indices

constexpr std::array<int, nub> cgmres::OCP_cartpole::ubound_indices = {0}
staticconstexpr

◆ umax

std::array<double, nub> cgmres::OCP_cartpole::umax = {15.0}

◆ umin

std::array<double, nub> cgmres::OCP_cartpole::umin = {-15.0}

◆ x_ref

std::array<double, 4> cgmres::OCP_cartpole::x_ref = {0, M_PI, 0, 0}

The documentation for this class was generated from the following file: