momentumopt
DynamicsOptimizer.hpp
Go to the documentation of this file.
1 
9 #pragma once
10 
11 #include <string>
12 #include <vector>
13 #include <iostream>
14 #include <Eigen/Eigen>
15 
16 #include <solver/interface/Solver.hpp>
21 
22 namespace momentumopt {
23 
27  struct FrictionCone
28  {
29  typedef Eigen::Matrix< double, 4, 3> ConeMat;
30  void getCone(double fcoeff, FrictionCone::ConeMat& cone_mat)
31  {
32  if (fcoeff <= 0.001) { fcoeff = 0.001; }
33  Eigen::Vector3d fconevec = Eigen::Vector3d(0.5*sqrt(2.0), 0.5*sqrt(2.0), -fcoeff); fconevec.normalize();
34  Eigen::Matrix3d fconemat = Eigen::Matrix3d::Identity();
35  double angle = 2*M_PI/4;
36  fconemat(0,0) = cos(angle); fconemat(0,1) = -sin(angle);
37  fconemat(1,0) = sin(angle); fconemat(1,1) = cos(angle);
38  for (int i=0; i<4; i++) {
39  cone_mat.row(i) = fconevec;
40  fconevec = fconemat * fconevec;
41  }
42  }
43  };
44 
47  {
48  public:
49  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
50 
51  public:
55 
60  void initialize(PlannerSetting& planner_setting);
61 
70  solver::ExitCode optimize(const DynamicsState& ini_state, ContactPlanInterface* contact_plan,
71  const KinematicsSequence& kin_sequence, bool update_tracking_objective = false);
72 
79  DynamicsSequence& dynamicsSequence() { return dyn_sequence_; }
80  const DynamicsSequence& dynamicsSequence() const { return dyn_sequence_; }
81 
83  const double& solveTime() const { return solve_time_; }
84 
85  private:
87  inline PlannerSetting& getSetting() { return *planner_setting_; }
88  inline const PlannerSetting& getSetting() const { return *planner_setting_; }
89 
91  const ContactType contactType(int time_id, int eff_id) const;
92  const Eigen::Matrix3d contactRotation(int time_id, int eff_id) const;
93  const double contactLocation(int time_id, int eff_id, int axis_id) const;
94 
99  void initializeOptimizationVariables();
100 
108  void addVariableToModel(const solver::OptimizationVariable& opt_var, solver::Model& model, std::vector<solver::Var>& vars);
109 
116  void internalOptimize(const KinematicsSequence& kin_sequence, bool is_first_time = false);
117  void updateTrackingObjective();
118 
126  void saveSolution(solver::OptimizationVariable& opt_var);
127  void storeSolution();
128  void saveToFile(const KinematicsSequence& kin_sequence);
129 
130  private:
133 
138  solver::Model model_;
139 
141  solver::LinExpr lin_cons_;
142  solver::DCPQuadExpr quad_objective_, quad_cons_;
143 
145  solver::ExitCode exitcode_;
146 
151  std::vector<solver::Var> vars_;
152 
158 
161  FrictionCone::ConeMat cone_matrix_;
162 
168 
174 
177 
180 
183 
185  int size_, num_vars_;
186 
188  double solve_time_, convergence_err_, last_convergence_err_;
189 
191  Eigen::Vector3d com_pos_goal_, weight_desired_com_tracking_;
192 
194  solver::OptimizationVariable dt_, com_, lmom_, amom_, lmomd_, amomd_;
195  std::array<solver::OptimizationVariable, Problem::n_endeffs_> frc_world_, trq_local_, cop_local_, ub_var_, lb_var_;
196 
198  solver::OptimizationVariable::OptVector solution_;
199  solver::OptimizationVariable::OptMatrix mat_lb_, mat_ub_, mat_guess_, com_guess_, lmom_guess_, amom_guess_;
200  };
201 
202 }
Helper class to define a linear approximation of a friction cone.
Definition: DynamicsOptimizer.hpp:27
char variable_type_
Definition: DynamicsOptimizer.hpp:179
ContactPlanInterface * contact_plan_
helper class to store information about the contact plan, such as surfaces, position and orientation ...
Definition: DynamicsOptimizer.hpp:173
solver::OptimizationVariable::OptVector solution_
Definition: DynamicsOptimizer.hpp:198
ContactType
Definition of contact type: FlatContact: forces subject to friction cone constrains of flat surface F...
Definition: ContactState.hpp:26
solver::ExitCode exitcode_
Definition: DynamicsOptimizer.hpp:145
DynamicsState ini_state_
initial configuration of the robot, including center of mass position, linear and angular momenta...
Definition: DynamicsOptimizer.hpp:157
This class is a container for all variables required to define a dynamic state: center of mass positi...
Definition: DynamicsState.hpp:29
double solve_time_
Definition: DynamicsOptimizer.hpp:188
PlannerSetting & getSetting()
Definition: DynamicsOptimizer.hpp:87
bool has_converged_
Definition: DynamicsOptimizer.hpp:182
Definition: DynamicsOptimizer.hpp:46
DynamicsSequence & dynamicsSequence()
this function gives access to the optimized motion plan
Definition: DynamicsOptimizer.hpp:79
DynamicsSequence dyn_sequence_
dynamics sequence of dynamic states.
Definition: DynamicsOptimizer.hpp:167
Definition: PlannerSetting.hpp:22
This class implements a simple interface to store a sequence of contacts, including its activation an...
Definition: ContactPlanInterface.hpp:36
FrictionCone friction_cone_
Definition: DynamicsOptimizer.hpp:160
solver::Model model_
class that stores all information about the problem, interfaces between high level definition of the ...
Definition: DynamicsOptimizer.hpp:138
This class is a container for a sequence of dynamic states, for all time steps in the optimization...
Definition: DynamicsState.hpp:123
Helper class to measure time required to run an optimization procedure.
Definition: Clock.hpp:18
const double & solveTime() const
Definition: DynamicsOptimizer.hpp:83
std::vector< solver::Var > vars_
c++ vector containing all problem variables defined by the user.
Definition: DynamicsOptimizer.hpp:151
This class is a container for a sequence of kinematic states.
Definition: KinematicsState.hpp:211
solver::OptimizationVariable dt_
Definition: DynamicsOptimizer.hpp:194
Clock timer_
Definition: DynamicsOptimizer.hpp:176
Eigen::Vector3d com_pos_goal_
Definition: DynamicsOptimizer.hpp:191
DynamicsOptimizer()
Definition: DynamicsOptimizer.hpp:53
solver::LinExpr lin_cons_
Definition: DynamicsOptimizer.hpp:141
int size_
Definition: DynamicsOptimizer.hpp:185
PlannerSetting * planner_setting_
Definition: DynamicsOptimizer.hpp:132