mpc.hpp
Go to the documentation of this file.
1 // BSD 3-Clause License
3 //
4 // Copyright (C) 2022 LAAS-CNRS
5 // Copyright note valid unless otherwise stated in individual files.
6 // All rights reserved.
8 
9 #ifndef SOBEC_MPC_WALK_HPP_
10 #define SOBEC_MPC_WALK_HPP_
11 
12 #include <crocoddyl/core/fwd.hpp>
13 #include <crocoddyl/core/solvers/fddp.hpp>
14 #include <crocoddyl/multibody/fwd.hpp>
15 // #include <crocoddyl/multibody/data/multibody.hpp>
16 #include <crocoddyl/multibody/states/multibody.hpp>
17 
18 #include "sobec/fwd.hpp"
19 
20 namespace sobec {
21 using namespace crocoddyl;
26 struct MPCWalkParams {
28  Eigen::Vector3d vcomRef;
30  Eigen::VectorXd x0;
32  int Tmpc;
34  int Tstart;
36  int Tdouble;
38  int Tsingle;
40  int Tend;
42  double DT;
49 
51  std::string stateRegCostName;
52 
53  MPCWalkParams();
54  virtual ~MPCWalkParams() {}
55 
57  void readParamsFromYamlString(std::string& StringToParse);
59  void readParamsFromYamlFile(const std::string& Filename);
60 };
61 
62 class MPCWalk {
63  typedef typename MathBaseTpl<double>::VectorXs VectorXd;
64  typedef typename MathBaseTpl<double>::VectorXs Vector3d;
65  typedef std::vector<AMA> ActionList;
66  // typedef typename
67  // crocoddyl::DifferentialActionModelContactFwdDynamicsTpl<double> DAM;
68 
69  public:
70  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
71 
72  explicit MPCWalk(boost::shared_ptr<MPCWalkParams> params,
73  boost::shared_ptr<ShootingProblem> problem);
74 
75  virtual ~MPCWalk() {}
76 
78  void initialize(const std::vector<Eigen::VectorXd>& xs,
79  const std::vector<Eigen::VectorXd>& us);
80 
82  void calc(const Eigen::Ref<const VectorXd>& x, const int t);
83 
85  void updateTerminalCost(const int t);
86  void findTerminalStateResidualModel();
87  void findStateModel();
88 
89  public:
91  boost::shared_ptr<MPCWalkParams> params;
92 
94  boost::shared_ptr<ShootingProblem> storage;
95 
97  boost::shared_ptr<ShootingProblem> problem;
98 
100  boost::shared_ptr<SolverFDDP> solver;
101 
103  boost::shared_ptr<ResidualModelState> terminalStateResidual;
104 
106  boost::shared_ptr<StateMultibody> state;
107 
108  protected:
109  double reg;
110 };
111 
112 } // namespace sobec
113 
114 /* --- Details -------------------------------------------------------------- */
115 /* --- Details -------------------------------------------------------------- */
116 /* --- Details -------------------------------------------------------------- */
117 
119 
120 #endif // SOBEC_MPC_WALK_HPP_
sobec::MPCWalkParams::solver_th_stop
double solver_th_stop
stop threshold to configure the solver
Definition: mpc.hpp:44
sobec::MPCWalk::solver
boost::shared_ptr< SolverFDDP > solver
Solver for MPC.
Definition: mpc.hpp:100
sobec::MPCWalkParams::DT
double DT
timestep in problem shooting nodes
Definition: mpc.hpp:42
sobec::MPCWalk::~MPCWalk
virtual ~MPCWalk()
Definition: mpc.hpp:75
sobec::MPCWalkParams::Tdouble
int Tdouble
Duration of double-support phases of the OCP.
Definition: mpc.hpp:36
sobec::MPCWalk::terminalStateResidual
boost::shared_ptr< ResidualModelState > terminalStateResidual
Keep a direct reference to the terminal residual.
Definition: mpc.hpp:103
fwd.hpp
sobec::MPCWalk::state
boost::shared_ptr< StateMultibody > state
Keep a direct reference to the terminal state.
Definition: mpc.hpp:106
sobec::MPCWalkParams::Tmpc
int Tmpc
Duration of the MPC horizon.
Definition: mpc.hpp:32
sobec::MPCWalkParams::Tend
int Tend
Duration of the end phase of the OCP.
Definition: mpc.hpp:40
sobec::MPCWalkParams::solver_reg_min
double solver_reg_min
solver param reg_min
Definition: mpc.hpp:46
sobec::MPCWalkParams::Tstart
int Tstart
Duration of start phase of the OCP.
Definition: mpc.hpp:34
sobec::MPCWalk
Definition: mpc.hpp:62
sobec::MPCWalkParams
MPC manager, calling iterative subpart of a larger OCP.
Definition: mpc.hpp:26
sobec::MPCWalk::storage
boost::shared_ptr< ShootingProblem > storage
The reference shooting problem storing all shooting nodes.
Definition: mpc.hpp:94
mpc.hxx
sobec::MPCWalkParams::solver_maxiter
int solver_maxiter
Solver max number of iteration.
Definition: mpc.hpp:48
sobec::MPCWalkParams::Tsingle
int Tsingle
Duration of single-support phases of the OCP.
Definition: mpc.hpp:38
sobec
Definition: activation-quad-ref.hpp:19
sobec::MPCWalkParams::vcomRef
Eigen::Vector3d vcomRef
reference COM velocity
Definition: mpc.hpp:28
sobec::newcontacts::x
@ x
Definition: contact1d.hpp:26
sobec::MPCWalkParams::stateRegCostName
std::string stateRegCostName
name of the regularization cost that is modified by mpc update.
Definition: mpc.hpp:51
sobec::MPCWalk::params
boost::shared_ptr< MPCWalkParams > params
Parameters to tune the algorithm, given at init.
Definition: mpc.hpp:91
sobec::MPCWalk::reg
double reg
Definition: mpc.hpp:109
sobec::MPCWalkParams::~MPCWalkParams
virtual ~MPCWalkParams()
Definition: mpc.hpp:54
sobec::MPCWalk::problem
boost::shared_ptr< ShootingProblem > problem
the MPC problem used for solving.
Definition: mpc.hpp:97
sobec::MPCWalkParams::x0
Eigen::VectorXd x0
reference 0 state
Definition: mpc.hpp:30