nmpc_fmpc
FmpcProblem.h
Go to the documentation of this file.
1 /* Author: Masaki Murooka */
2 
3 #pragma once
4 
5 #include <nmpc_ddp/DDPProblem.h>
6 
7 namespace nmpc_fmpc
8 {
14 template<int StateDim, int InputDim, int IneqDim>
15 class FmpcProblem : public nmpc_ddp::DDPProblem<StateDim, InputDim>
16 {
17 public:
19  using StateDimVector = typename nmpc_ddp::DDPProblem<StateDim, InputDim>::StateDimVector;
20 
22  using InputDimVector = typename nmpc_ddp::DDPProblem<StateDim, InputDim>::InputDimVector;
23 
25  using IneqDimVector = Eigen::Matrix<double, IneqDim, 1>;
26 
28  using StateStateDimMatrix = typename nmpc_ddp::DDPProblem<StateDim, InputDim>::StateStateDimMatrix;
29 
31  using InputInputDimMatrix = typename nmpc_ddp::DDPProblem<StateDim, InputDim>::InputInputDimMatrix;
32 
34  using StateInputDimMatrix = typename nmpc_ddp::DDPProblem<StateDim, InputDim>::StateInputDimMatrix;
35 
37  using InputStateDimMatrix = typename nmpc_ddp::DDPProblem<StateDim, InputDim>::InputStateDimMatrix;
38 
40  using IneqStateDimMatrix = Eigen::Matrix<double, IneqDim, StateDim>;
41 
43  using IneqInputDimMatrix = Eigen::Matrix<double, IneqDim, InputDim>;
44 
45 public:
46  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
47 
51  FmpcProblem(double dt) : nmpc_ddp::DDPProblem<StateDim, InputDim>(dt)
52  {
53  // Check dimension
54  static_assert(IneqDim >= 0 || IneqDim == Eigen::Dynamic,
55  "[FMPC] Template param IneqDim should be non-negative or Eigen::Dynamic.");
56  }
57 
62  inline virtual int ineqDim() const
63  {
64  if constexpr(IneqDim == Eigen::Dynamic)
65  {
66  throw std::runtime_error("Since ineq dimension is dynamic, time must be passed to ineqDim().");
67  }
68  return IneqDim;
69  }
70 
75  inline virtual int ineqDim(double // t
76  ) const
77  {
78  if constexpr(IneqDim == Eigen::Dynamic)
79  {
80  throw std::runtime_error("ineqDim(t) must be overridden if ineq dimension is dynamic.");
81  }
82  else
83  {
84  return ineqDim();
85  }
86  }
87 
94  virtual IneqDimVector ineqConst(double t, const StateDimVector & x, const InputDimVector & u) const = 0;
95 
103  virtual void calcIneqConstDeriv(double t,
104  const StateDimVector & x,
105  const InputDimVector & u,
106  Eigen::Ref<IneqStateDimMatrix> ineq_const_deriv_x,
107  Eigen::Ref<IneqInputDimMatrix> ineq_const_deriv_u) const = 0;
108 
109  using nmpc_ddp::DDPProblem<StateDim, InputDim>::calcStateEqDeriv;
110 
111 private:
122  inline virtual void calcStateEqDeriv(double, // t
123  const StateDimVector &, // x
124  const InputDimVector &, // u
125  Eigen::Ref<StateStateDimMatrix>, // state_eq_deriv_x
126  Eigen::Ref<StateInputDimMatrix>, // state_eq_deriv_u
127  std::vector<StateStateDimMatrix> &, // state_eq_deriv_xx
128  std::vector<InputInputDimMatrix> &, // state_eq_deriv_uu
129  std::vector<StateInputDimMatrix> & // state_eq_deriv_xu
130  ) const override
131  {
132  throw std::runtime_error("[FMPC] Second-order derivatives of state equation is not used.");
133  }
134 };
135 } // namespace nmpc_fmpc
nmpc_fmpc::FmpcProblem::FmpcProblem
EIGEN_MAKE_ALIGNED_OPERATOR_NEW FmpcProblem(double dt)
Constructor.
Definition: FmpcProblem.h:51
nmpc_fmpc::FmpcProblem::StateDimVector
typename nmpc_ddp::DDPProblem< StateDim, InputDim >::StateDimVector StateDimVector
Type of vector of state dimension.
Definition: FmpcProblem.h:19
nmpc_fmpc::FmpcProblem::calcIneqConstDeriv
virtual void calcIneqConstDeriv(double t, const StateDimVector &x, const InputDimVector &u, Eigen::Ref< IneqStateDimMatrix > ineq_const_deriv_x, Eigen::Ref< IneqInputDimMatrix > ineq_const_deriv_u) const =0
Calculate first-order derivatives of inequality constraints.
nmpc_fmpc::FmpcProblem::IneqDimVector
Eigen::Matrix< double, IneqDim, 1 > IneqDimVector
Type of vector of inequality dimension.
Definition: FmpcProblem.h:25
nmpc_fmpc::FmpcProblem::InputDimVector
typename nmpc_ddp::DDPProblem< StateDim, InputDim >::InputDimVector InputDimVector
Type of vector of input dimension.
Definition: FmpcProblem.h:22
nmpc_fmpc::FmpcProblem::StateInputDimMatrix
typename nmpc_ddp::DDPProblem< StateDim, InputDim >::StateInputDimMatrix StateInputDimMatrix
Type of matrix of state x input dimension.
Definition: FmpcProblem.h:34
nmpc_fmpc::FmpcProblem
Fast MPC problem.
Definition: FmpcProblem.h:15
nmpc_fmpc::FmpcProblem::IneqInputDimMatrix
Eigen::Matrix< double, IneqDim, InputDim > IneqInputDimMatrix
Type of matrix of inequality x input dimension.
Definition: FmpcProblem.h:43
nmpc_fmpc::FmpcProblem::IneqStateDimMatrix
Eigen::Matrix< double, IneqDim, StateDim > IneqStateDimMatrix
Type of matrix of inequality x state dimension.
Definition: FmpcProblem.h:40
nmpc_fmpc::FmpcProblem::ineqDim
virtual int ineqDim(double) const
Gets the inequality dimension.
Definition: FmpcProblem.h:75
nmpc_fmpc::FmpcProblem::ineqDim
virtual int ineqDim() const
Gets the inequality dimension.
Definition: FmpcProblem.h:62
nmpc_fmpc::FmpcProblem::InputStateDimMatrix
typename nmpc_ddp::DDPProblem< StateDim, InputDim >::InputStateDimMatrix InputStateDimMatrix
Type of matrix of input x state dimension.
Definition: FmpcProblem.h:37
nmpc_fmpc::FmpcProblem::StateStateDimMatrix
typename nmpc_ddp::DDPProblem< StateDim, InputDim >::StateStateDimMatrix StateStateDimMatrix
Type of matrix of state x state dimension.
Definition: FmpcProblem.h:28
nmpc_fmpc::FmpcProblem::InputInputDimMatrix
typename nmpc_ddp::DDPProblem< StateDim, InputDim >::InputInputDimMatrix InputInputDimMatrix
Type of matrix of input x input dimension.
Definition: FmpcProblem.h:31
nmpc_fmpc::FmpcProblem::ineqConst
virtual IneqDimVector ineqConst(double t, const StateDimVector &x, const InputDimVector &u) const =0
Calculate inequality constraints.
nmpc_fmpc
Definition: FmpcProblem.h:7