ocp.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_OCP_WALK_HPP_
10 #define SOBEC_OCP_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/states/multibody.hpp>
16 #include <pinocchio/spatial/force.hpp>
17 
19 #include "sobec/fwd.hpp"
20 
21 namespace sobec {
22 using namespace crocoddyl;
27 struct OCPWalkParams {
28  double DT;
29  std::vector<std::string> mainJointIds;
30  Eigen::Vector2d baumgartGains;
31  Eigen::VectorXd stateImportance;
32  Eigen::VectorXd stateTerminalImportance;
33  Eigen::VectorXd controlImportance;
34  Eigen::VectorXd vcomImportance;
35  Eigen::VectorXd forceImportance;
36 
37  Eigen::Vector3d vcomRef;
38 
39  double footSize;
42 
45  double comWeight;
46  double vcomWeight;
47  double copWeight;
56  double flyHighSlope;
57  double flyHighWeight;
61  double kktDamping;
65 
66  void readParamsFromYamlStr(std::string& StringToParse);
67  void readParamsFromYamlFile(const std::string& Filename);
68 };
69 
71  boost::shared_ptr<pinocchio::Model> model;
72  boost::shared_ptr<pinocchio::Data> data;
73  std::vector<pinocchio::FrameIndex> contactIds;
74  std::map<pinocchio::FrameIndex, pinocchio::FrameIndex> towIds, heelIds;
75  Eigen::VectorXd x0;
76  Eigen::Vector3d com0;
78 
79  OCPRobotWrapper(boost::shared_ptr<pinocchio::Model> model,
80  const std::string& contactKey,
81  const std::string& referencePosture = "half_sitting");
82 };
83 
84 Eigen::MatrixXd computeWeightShareSmoothProfile(
85  const Eigen::Ref<const Eigen::MatrixXd> contact_pattern, int duration,
86  double saturation);
87 
88 class OCPWalk {
89  typedef typename MathBaseTpl<double>::VectorXs VectorXd;
90  typedef typename MathBaseTpl<double>::VectorXs Vector3d;
91  typedef typename Eigen::Matrix<double, Eigen::Dynamic, 2> MatrixX2d;
92  typedef typename Eigen::Matrix<double, Eigen::Dynamic, 6> MatrixX6d;
93  typedef std::vector<AMA> ActionList;
94  typedef
95  typename crocoddyl::DifferentialActionModelContactFwdDynamicsTpl<double>
96  DAM;
97 
98  public:
99  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
100 
101  explicit OCPWalk(boost::shared_ptr<OCPRobotWrapper> robot,
102  boost::shared_ptr<OCPWalkParams> params,
103  const Eigen::Ref<const Eigen::MatrixXd> contact_pattern);
104 
105  virtual ~OCPWalk() {}
106 
107  std::vector<AMA> buildRunningModels();
108  AMA buildTerminalModel();
109  void buildSolver();
110  std::pair<std::vector<Eigen::VectorXd>, std::vector<Eigen::VectorXd>>
111  buildInitialGuess();
112 
113  void computeReferenceForces();
114 
115  public:
117  boost::shared_ptr<ShootingProblem> problem;
118 
120  boost::shared_ptr<SolverFDDP> solver;
121 
123  boost::shared_ptr<StateMultibody> state;
124 
125  boost::shared_ptr<ActuationModelFloatingBase> actuation;
126 
127  std::vector<std::vector<pinocchio::Force>> referenceForces;
128  Eigen::MatrixXd contact_pattern;
129 
130  protected:
131  boost::shared_ptr<OCPWalkParams> params;
132  boost::shared_ptr<OCPRobotWrapper> robot;
133 };
134 
135 } // namespace sobec
136 
137 #endif // SOBEC_OCP_WALK_HPP_
sobec::OCPWalkParams::footSize
double footSize
Definition: ocp.hpp:39
sobec::OCPWalkParams::impactVelocityWeight
double impactVelocityWeight
Definition: ocp.hpp:52
sobec::OCPRobotWrapper::com0
Eigen::Vector3d com0
Definition: ocp.hpp:76
sobec::OCPWalkParams::groundColWeight
double groundColWeight
Definition: ocp.hpp:58
sobec::OCPWalkParams::kktDamping
double kktDamping
Definition: ocp.hpp:61
sobec::computeWeightShareSmoothProfile
Eigen::MatrixXd computeWeightShareSmoothProfile(const Eigen::Ref< const Eigen::MatrixXd > contact_pattern, int duration, double saturation)
Definition: ocp-ref-forces.cpp:16
sobec::OCPWalkParams::refStateWeight
double refStateWeight
Definition: ocp.hpp:43
sobec::OCPWalkParams::stateTerminalImportance
Eigen::VectorXd stateTerminalImportance
Definition: ocp.hpp:32
sobec::OCPRobotWrapper::robotGravityForce
double robotGravityForce
Definition: ocp.hpp:77
sobec::OCPWalk
Definition: ocp.hpp:88
sobec::OCPRobotWrapper::contactIds
std::vector< pinocchio::FrameIndex > contactIds
Definition: ocp.hpp:73
sobec::OCPWalkParams::comWeight
double comWeight
Definition: ocp.hpp:45
sobec::OCPWalkParams::stateImportance
Eigen::VectorXd stateImportance
Definition: ocp.hpp:31
fwd.hpp
sobec::OCPWalk::params
boost::shared_ptr< OCPWalkParams > params
Definition: ocp.hpp:131
sobec::OCPWalkParams::baumgartGains
Eigen::Vector2d baumgartGains
Definition: ocp.hpp:30
sobec::OCPRobotWrapper::model
boost::shared_ptr< pinocchio::Model > model
Definition: ocp.hpp:71
sobec::OCPWalkParams::mainJointIds
std::vector< std::string > mainJointIds
Definition: ocp.hpp:29
sobec::OCPWalkParams::verticalFootVelWeight
double verticalFootVelWeight
Definition: ocp.hpp:55
sobec::OCPWalkParams
OCP builder.
Definition: ocp.hpp:27
sobec::OCPWalk::~OCPWalk
virtual ~OCPWalk()
Definition: ocp.hpp:105
sobec::OCPWalk::actuation
boost::shared_ptr< ActuationModelFloatingBase > actuation
Definition: ocp.hpp:125
sobec::OCPWalkParams::flyHighSlope
double flyHighSlope
Definition: ocp.hpp:56
sobec::OCPRobotWrapper::x0
Eigen::VectorXd x0
Definition: ocp.hpp:75
sobec::OCPWalkParams::copWeight
double copWeight
Definition: ocp.hpp:47
sobec::OCPWalkParams::feetCollisionWeight
double feetCollisionWeight
Definition: ocp.hpp:60
sobec::OCPWalkParams::refMainJointsAtImpactWeight
double refMainJointsAtImpactWeight
Definition: ocp.hpp:54
sobec::OCPWalkParams::conePenaltyWeight
double conePenaltyWeight
Definition: ocp.hpp:48
sobec::OCPWalkParams::DT
double DT
Definition: ocp.hpp:28
sobec::DAM
boost::shared_ptr< crocoddyl::DifferentialActionModelContactFwdDynamics > DAM
Definition: fwd.hpp:150
sobec::OCPWalk::contact_pattern
Eigen::MatrixXd contact_pattern
Definition: ocp.hpp:128
sobec::OCPWalkParams::forceImportance
Eigen::VectorXd forceImportance
Definition: ocp.hpp:35
sobec::AMA
boost::shared_ptr< crocoddyl::ActionModelAbstract > AMA
Definition: fwd.hpp:147
sobec::OCPWalkParams::withNormalForceBoundOnly
bool withNormalForceBoundOnly
Definition: ocp.hpp:40
sobec::OCPWalkParams::solver_th_stop
double solver_th_stop
Definition: ocp.hpp:63
sobec::OCPWalkParams::refForceWeight
double refForceWeight
Definition: ocp.hpp:50
sobec::OCPWalk::solver
boost::shared_ptr< SolverFDDP > solver
the OCP solver.
Definition: ocp.hpp:120
sobec
Definition: activation-quad-ref.hpp:19
sobec::OCPWalkParams::vcomImportance
Eigen::VectorXd vcomImportance
Definition: ocp.hpp:34
sobec::OCPWalkParams::refTorqueWeight
double refTorqueWeight
Definition: ocp.hpp:44
sobec::OCPWalkParams::impactAltitudeWeight
double impactAltitudeWeight
Definition: ocp.hpp:51
sobec::OCPWalkParams::flyHighWeight
double flyHighWeight
Definition: ocp.hpp:57
sobec::OCPWalkParams::vcomWeight
double vcomWeight
Definition: ocp.hpp:46
sobec::OCPWalkParams::coneAxisWeight
double coneAxisWeight
Definition: ocp.hpp:49
sobec::OCPWalkParams::impactRotationWeight
double impactRotationWeight
Definition: ocp.hpp:53
sobec::OCPWalk::state
boost::shared_ptr< StateMultibody > state
Keep a direct reference to the terminal state.
Definition: ocp.hpp:123
sobec::OCPRobotWrapper
Definition: ocp.hpp:70
sobec::OCPWalk::referenceForces
std::vector< std::vector< pinocchio::Force > > referenceForces
Definition: ocp.hpp:127
sobec::OCPWalkParams::minimalNormalForce
double minimalNormalForce
Definition: ocp.hpp:41
sobec::OCPRobotWrapper::towIds
std::map< pinocchio::FrameIndex, pinocchio::FrameIndex > towIds
Definition: ocp.hpp:74
sobec::OCPWalkParams::footMinimalDistance
double footMinimalDistance
Definition: ocp.hpp:59
sobec::OCPWalk::problem
boost::shared_ptr< ShootingProblem > problem
the OCP problem used for solving.
Definition: ocp.hpp:117
sobec::OCPRobotWrapper::data
boost::shared_ptr< pinocchio::Data > data
Definition: ocp.hpp:72
sobec::OCPWalkParams::controlImportance
Eigen::VectorXd controlImportance
Definition: ocp.hpp:33
sobec::OCPWalkParams::stateTerminalWeight
double stateTerminalWeight
Definition: ocp.hpp:62
residual-cop.hpp
sobec::OCPWalkParams::transitionDuration
int transitionDuration
Definition: ocp.hpp:64
sobec::OCPWalkParams::vcomRef
Eigen::Vector3d vcomRef
Definition: ocp.hpp:37
sobec::OCPWalk::robot
boost::shared_ptr< OCPRobotWrapper > robot
Definition: ocp.hpp:132