momentumopt
KinematicsOptimizer.hpp
Go to the documentation of this file.
1 
9 #pragma once
10 
11 #include <string>
12 #include <vector>
13 #include <memory>
14 #include <iostream>
15 #include <Eigen/Eigen>
16 
17 #include <solver/interface/Solver.hpp>
18 //#include <solver/optimizer/LbfgsSolver.hpp>
21 //#include <momentumopt/cntopt/ContactPlanFromFile.hpp>
24 
25 namespace momentumopt {
26 
29  {
30  public:
31  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
32 
33  public:
37 
43  void initialize(PlannerSetting& planner_setting, KinematicsInterface* kin_interface);
44 
51  void optimize(const DynamicsState& ini_state, ContactPlanInterface* contact_plan, DynamicsSequence& dyn_sequence, bool is_first_kinopt);
52 
60  const KinematicsSequence& kinematicsSequence() const { return kin_sequence_; }
61 
62 // /**
63 // * helper function to replay a motion
64 // * @param[in] PlannerSetting setting of planner configuration variables
65 // * @param[in] kin_interface implementation of robot specific functions needed by the optimizer
66 // * @param[in] load_file file where the kinematic parameters have been stored
67 // */
68 // void displayMotion(PlannerSetting& planner_setting, KinematicsInterface* kin_interface, const std::string& load_file);
69 //
70 // /**
71 // * function to load a kinematic solution from a file and fill a sequence with it
72 // * @param[in] load_file name of configuration file from where to load the solution
73 // */
74 // void loadSolution(const std::string& load_file);
75 
76  private:
79  inline const PlannerSetting& getSetting() const { return *planner_setting_; }
80 
86  void initializeTrajectoryKinematicVariables();
87 
95  void addVariableToModel(const solver::OptimizationVariable& opt_var, solver::Model& model, std::vector<solver::Var>& vars);
96 
102  void saveSolution(solver::OptimizationVariable& opt_var);
103  void storeSolution(const DynamicsState& ini_state, DynamicsSequence& dyn_sequence);
104 
112  void optimizeTrajectory(const DynamicsState& ini_state, DynamicsSequence& dyn_sequence);
113  void optimizePosture(KinematicsState& current_state, const DynamicsState& desired_state, bool is_initial_state = false);
114 
116  void displayMotion(const DynamicsSequence& dyn_sequence);
117 
123 
124  // quaternion to rotation vector
125  Eigen::Vector3d quaternionToRotationVector(const Eigen::Quaternion<double>& q) const;
126 
127  private:
130 
135  solver::Model model_;
136 
138  solver::LinExpr lin_cons_;
139 
141  solver::ExitCode exitcode_;
142 
147  std::vector<solver::Var> vars_;
148 
154  KinematicsState *ini_state_, *current_state_;
155 
161 
168 
171 
174 
176  int size_, num_vars_;
177 
179  std::array<solver::OptimizationVariable, Problem::n_endeffs_> eef_pos_, eef_vel_, eef_ang_vel_;
180  solver::OptimizationVariable jnt_q_, jnt_qd_, jnt_qdd_, total_qd_, total_qdd_, com_, comd_,
181  lmom_, amom_, base_position_, base_ang_vel_, slack_vars_;
182 
184  solver::OptimizationVariable::OptVector solution_;
185  solver::OptimizationVariable::OptMatrix mat_guess_, mat_lb_, mat_ub_;
186 
187  std::array<Eigen::Vector3d, Problem::n_endeffs_> desired_eff_velocity_;
188  Eigen::Vector3d desired_com_velocity_, desired_lmom_velocity_, desired_amom_velocity_;
189  };
190 
191 }
PlannerSetting * planner_setting_
Definition: KinematicsOptimizer.hpp:129
solver::LinExpr lin_cons_
Definition: KinematicsOptimizer.hpp:138
KinematicsInterface * kin_interface_
Definition: KinematicsOptimizer.hpp:170
void initializePostureKinematicVariables()
function to initialize optimization variables: type [continuous or binary], guess value [if any]...
Definition: KinematicsOptimizer.cpp:282
std::array< solver::OptimizationVariable, Problem::n_endeffs_ > eef_pos_
Definition: KinematicsOptimizer.hpp:179
KinematicsState * ini_state_
configuration of the robot, including center of mass position, linear and angular momenta...
Definition: KinematicsOptimizer.hpp:154
char variable_type_
Definition: KinematicsOptimizer.hpp:173
solver::OptimizationVariable::OptVector solution_
Definition: KinematicsOptimizer.hpp:184
This class is a container for all variables required to define a dynamic state: center of mass positi...
Definition: DynamicsState.hpp:29
solver::ExitCode exitcode_
Definition: KinematicsOptimizer.hpp:141
solver::Model model_
class that stores all information about the problem, interfaces between high level definition of the ...
Definition: KinematicsOptimizer.hpp:135
void addVariableToModel(const solver::OptimizationVariable &opt_var, solver::Model &model, std::vector< solver::Var > &vars)
function to add each variable to the Model and assign a unique identifier to it, to be used by the op...
Definition: KinematicsOptimizer.cpp:459
KinematicsSequence & kinematicsSequence()
this function gives access to the optimized motion plan
Definition: KinematicsOptimizer.hpp:59
Definition: KinematicsInterface.hpp:24
Definition: PlannerSetting.hpp:22
This class implements a simple interface to store a sequence of contacts, including its activation an...
Definition: ContactPlanInterface.hpp:36
This class is a container for a sequence of dynamic states, for all time steps in the optimization...
Definition: DynamicsState.hpp:123
int size_
Definition: KinematicsOptimizer.hpp:176
void displayMotion(const DynamicsSequence &dyn_sequence)
Definition: KinematicsOptimizer.cpp:486
void updateEndeffectorTrajectories(DynamicsSequence &dyn_sequence)
function to update the tracking endeffector trajectories
void optimize(const DynamicsState &ini_state, ContactPlanInterface *contact_plan, DynamicsSequence &dyn_sequence, bool is_first_kinopt)
function to parse equations and objective into optimization problem and attempt to find a solution ...
Definition: KinematicsOptimizer.cpp:39
PlannerSetting & getSetting()
helper function to replay a motion
Definition: KinematicsOptimizer.hpp:78
This class is a container for a sequence of kinematic states.
Definition: KinematicsState.hpp:211
Definition: KinematicsOptimizer.hpp:28
void optimizeTrajectory(const DynamicsState &ini_state, DynamicsSequence &dyn_sequence)
function that implements iterative inverse kinematics to track momentum, end-effector motions...
Definition: KinematicsOptimizer.cpp:87
std::vector< solver::Var > vars_
c++ vector containing all problem variables defined by the user.
Definition: KinematicsOptimizer.hpp:147
KinematicsSequence kin_sequence_
kinematics sequence of kinematics states.
Definition: KinematicsOptimizer.hpp:167
KinematicsOptimizer()
Definition: KinematicsOptimizer.hpp:35
void saveSolution(solver::OptimizationVariable &opt_var)
functions that transfers optimal solution from model to helper class OptimizationVariable, and from helper class OptimizationVariable to dynamics sequence to be accessed by the user
Definition: KinematicsOptimizer.cpp:475
This class is a container for all variables required to define a kinematics state: joint posture...
Definition: KinematicsState.hpp:146
ContactPlanInterface * contact_plan_
helper class to store information about the contact plan, such as surfaces, position and orientation ...
Definition: KinematicsOptimizer.hpp:160
void initialize(PlannerSetting &planner_setting, KinematicsInterface *kin_interface)
function to initialize and configure the optimization
Definition: KinematicsOptimizer.cpp:25