nmpc_cgmres
CgmresSolver.h
Go to the documentation of this file.
1 /* Author: Masaki Murooka */
2 
3 #pragma once
4 
5 #include <fstream>
6 #include <iostream>
7 #include <memory>
8 
10 #include <nmpc_cgmres/OdeSolver.h>
11 
12 namespace nmpc_cgmres
13 {
23 {
24 public:
25  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
26 
28  CgmresSolver(std::shared_ptr<CgmresProblem> problem,
29  std::shared_ptr<OdeSolver> ode_solver,
30  std::shared_ptr<OdeSolver> sim_ode_solver = nullptr)
31  : problem_(problem), ode_solver_(ode_solver), sim_ode_solver_(sim_ode_solver)
32  {
33  if(!sim_ode_solver_)
34  {
36  }
37  }
38 
40  void setup();
41 
43  void run();
44 
46  void calcControlInput(double t,
47  const Eigen::Ref<const Eigen::VectorXd> & x,
48  const Eigen::Ref<const Eigen::VectorXd> & next_x,
49  Eigen::Ref<Eigen::VectorXd> u);
50 
52  void calcDhDuList(double t,
53  const Eigen::Ref<const Eigen::VectorXd> & x,
54  const Eigen::Ref<const Eigen::MatrixXd> & u_list,
55  Eigen::Ref<Eigen::MatrixXd> DhDu_list);
56 
58  Eigen::VectorXd eqAmulFunc(const Eigen::Ref<const Eigen::VectorXd> & vec);
59 
60 public:
61  std::shared_ptr<CgmresProblem> problem_;
62  std::shared_ptr<OdeSolver> ode_solver_;
63  std::shared_ptr<OdeSolver> sim_ode_solver_;
64 
66  double sim_duration_ = 10;
67 
71 
72  double dt_ = 0.001;
73 
74  double eq_zeta_ = 1000.0;
75  int k_max_ = 5;
76 
77  double finite_diff_delta_ = 0.002;
78 
79  int dump_step_ = 5;
80 
82  Eigen::VectorXd x_;
83  Eigen::VectorXd u_;
84 
85  double t_with_delta_;
86  Eigen::VectorXd x_with_delta_;
87 
88  Eigen::MatrixXd x_list_;
89  Eigen::MatrixXd lmd_list_;
90 
91  Eigen::MatrixXd u_list_;
92  Eigen::MatrixXd u_list_Amul_func_;
93 
94  Eigen::MatrixXd DhDu_list_;
95  Eigen::MatrixXd DhDu_list_with_delta_;
96  Eigen::MatrixXd DhDu_list_Amul_func_;
97  // Eigen::Map does not have a default constructor
98  std::shared_ptr<Eigen::Map<Eigen::VectorXd>> DhDu_vec_;
99  std::shared_ptr<Eigen::Map<Eigen::VectorXd>> DhDu_vec_with_delta_;
100  std::shared_ptr<Eigen::Map<Eigen::VectorXd>> DhDu_vec_Amul_func_;
101 
102  Eigen::VectorXd delta_u_vec_;
103 
105  std::ofstream ofs_x_;
106  std::ofstream ofs_u_;
107  std::ofstream ofs_err_;
108  const Eigen::IOFormat vecfmt_dump_ = Eigen::IOFormat(Eigen::StreamPrecision, 0, ", ", ", ", "", "", "", "");
109 };
110 } // namespace nmpc_cgmres
nmpc_cgmres::CgmresSolver::x_
Eigen::VectorXd x_
Definition: CgmresSolver.h:82
nmpc_cgmres
Definition: CgmresProblem.h:11
CgmresProblem.h
nmpc_cgmres::CgmresSolver::DhDu_vec_
std::shared_ptr< Eigen::Map< Eigen::VectorXd > > DhDu_vec_
Definition: CgmresSolver.h:98
nmpc_cgmres::CgmresSolver::DhDu_list_Amul_func_
Eigen::MatrixXd DhDu_list_Amul_func_
Definition: CgmresSolver.h:96
nmpc_cgmres::CgmresSolver::x_with_delta_
Eigen::VectorXd x_with_delta_
Definition: CgmresSolver.h:86
nmpc_cgmres::CgmresSolver::x_list_
Eigen::MatrixXd x_list_
Definition: CgmresSolver.h:88
nmpc_cgmres::CgmresSolver::horizon_increase_ratio_
double horizon_increase_ratio_
Definition: CgmresSolver.h:70
nmpc_cgmres::CgmresSolver::delta_u_vec_
Eigen::VectorXd delta_u_vec_
Definition: CgmresSolver.h:102
nmpc_cgmres::CgmresSolver::horizon_divide_num_
int horizon_divide_num_
Definition: CgmresSolver.h:69
nmpc_cgmres::CgmresSolver::DhDu_list_
Eigen::MatrixXd DhDu_list_
Definition: CgmresSolver.h:94
nmpc_cgmres::CgmresSolver::calcControlInput
void calcControlInput(double t, const Eigen::Ref< const Eigen::VectorXd > &x, const Eigen::Ref< const Eigen::VectorXd > &next_x, Eigen::Ref< Eigen::VectorXd > u)
Calculate the control input.
nmpc_cgmres::CgmresSolver::finite_diff_delta_
double finite_diff_delta_
Definition: CgmresSolver.h:77
nmpc_cgmres::CgmresSolver::steady_horizon_duration_
double steady_horizon_duration_
Definition: CgmresSolver.h:68
nmpc_cgmres::CgmresSolver::k_max_
int k_max_
Definition: CgmresSolver.h:75
nmpc_cgmres::CgmresSolver::DhDu_list_with_delta_
Eigen::MatrixXd DhDu_list_with_delta_
Definition: CgmresSolver.h:95
nmpc_cgmres::CgmresSolver::u_
Eigen::VectorXd u_
Definition: CgmresSolver.h:83
nmpc_cgmres::CgmresSolver::dt_
double dt_
Definition: CgmresSolver.h:72
nmpc_cgmres::CgmresSolver::eqAmulFunc
Eigen::VectorXd eqAmulFunc(const Eigen::Ref< const Eigen::VectorXd > &vec)
Function to return where is given.
nmpc_cgmres::CgmresSolver::ofs_err_
std::ofstream ofs_err_
Definition: CgmresSolver.h:107
nmpc_cgmres::CgmresSolver::u_list_Amul_func_
Eigen::MatrixXd u_list_Amul_func_
Definition: CgmresSolver.h:92
nmpc_cgmres::CgmresSolver::DhDu_vec_with_delta_
std::shared_ptr< Eigen::Map< Eigen::VectorXd > > DhDu_vec_with_delta_
Definition: CgmresSolver.h:99
nmpc_cgmres::CgmresSolver::problem_
std::shared_ptr< CgmresProblem > problem_
Definition: CgmresSolver.h:61
nmpc_cgmres::CgmresSolver
C/GMRES solver.
Definition: CgmresSolver.h:22
nmpc_cgmres::CgmresSolver::t_with_delta_
double t_with_delta_
Definition: CgmresSolver.h:85
nmpc_cgmres::CgmresSolver::ofs_u_
std::ofstream ofs_u_
Definition: CgmresSolver.h:106
nmpc_cgmres::CgmresSolver::eq_zeta_
double eq_zeta_
Definition: CgmresSolver.h:74
nmpc_cgmres::CgmresSolver::sim_ode_solver_
std::shared_ptr< OdeSolver > sim_ode_solver_
Definition: CgmresSolver.h:63
nmpc_cgmres::CgmresSolver::DhDu_vec_Amul_func_
std::shared_ptr< Eigen::Map< Eigen::VectorXd > > DhDu_vec_Amul_func_
Definition: CgmresSolver.h:100
nmpc_cgmres::CgmresSolver::u_list_
Eigen::MatrixXd u_list_
Definition: CgmresSolver.h:91
nmpc_cgmres::CgmresSolver::dump_step_
int dump_step_
Definition: CgmresSolver.h:79
nmpc_cgmres::CgmresSolver::setup
void setup()
Setup.
nmpc_cgmres::CgmresSolver::calcDhDuList
void calcDhDuList(double t, const Eigen::Ref< const Eigen::VectorXd > &x, const Eigen::Ref< const Eigen::MatrixXd > &u_list, Eigen::Ref< Eigen::MatrixXd > DhDu_list)
Calculate the list in the horizon.
nmpc_cgmres::CgmresSolver::sim_duration_
double sim_duration_
Definition: CgmresSolver.h:66
nmpc_cgmres::CgmresSolver::lmd_list_
Eigen::MatrixXd lmd_list_
Definition: CgmresSolver.h:89
nmpc_cgmres::CgmresSolver::CgmresSolver
EIGEN_MAKE_ALIGNED_OPERATOR_NEW CgmresSolver(std::shared_ptr< CgmresProblem > problem, std::shared_ptr< OdeSolver > ode_solver, std::shared_ptr< OdeSolver > sim_ode_solver=nullptr)
Constructor.
Definition: CgmresSolver.h:28
nmpc_cgmres::CgmresSolver::ofs_x_
std::ofstream ofs_x_
Definition: CgmresSolver.h:105
nmpc_cgmres::CgmresSolver::vecfmt_dump_
const Eigen::IOFormat vecfmt_dump_
Definition: CgmresSolver.h:108
nmpc_cgmres::CgmresSolver::run
void run()
Run NMPC.
OdeSolver.h
nmpc_cgmres::CgmresSolver::ode_solver_
std::shared_ptr< OdeSolver > ode_solver_
Definition: CgmresSolver.h:62