ocra-recipes
Doxygen documentation for the ocra-recipes repository
main.cpp
Go to the documentation of this file.
1 
2 #include <iostream>
3 #include <map>
4 
5 #include <Eigen/Eigen>
6 
7 #include "Model3T.h"
9 
10 #include "gocra/GHCJTController.h"
11 #include "gocra/Solvers/OneLevelSolver.h"
12 #include "ocra/control/Feature.h"
13 #include "ocra/control/FullState.h"
16 
17 
18 
19 
20 int main(int argc, char** argv)
21 {
22  std::cout<<"SET PARAMETERS\n";
23 
24  bool useGSHC = true;
25  bool useGrav = true;
26 
27  gocra::OneLevelSolverWithQuadProg internalSolver;
28 
29  // INITIALIZE ISIR MODEL, CONTROLLER & TASK MANAGER
30  std::cout<<"INITIALIZE ISIR MODEL, CONTROLLER\n";
31  Model3T model("Model3T");
32  gocra::GHCJTController ctrl("myCtrl", model, internalSolver, useGrav);
33 
34 
35  //CREATE SOME TASKS
36  std::cout<<"CREATE SOME TASKS\n";
37  ocra::FullModelState FMS("fullTask.FModelState" , model, ocra::FullState::INTERNAL); //INTERNAL, FREE_FLYER
38  ocra::FullTargetState FTS("fullTask.FTargetState", model, ocra::FullState::INTERNAL);
39  ocra::FullStateFeature feat("fullTask.feat", FMS);
40  ocra::FullStateFeature featDes("fullTask.featDes", FTS);
41  FTS.set_q(Eigen::VectorXd::Zero(model.nbInternalDofs()));
42 
43  gocra::GHCJTTask& accTask = ctrl.createGHCJTTask("fullTask", feat, featDes);
44 
45  ctrl.addTask(accTask);
46  accTask.activateAsObjective();
47  accTask.setStiffness(9);
48  accTask.setDamping(6);
49  accTask.setWeight(1.);
50 
51  ocra::SegmentFrame SF("frameTask.SFrame", model, "Model3T.segment_3", Eigen::Displacementd());
52  ocra::TargetFrame TF("frameTask.TFrame", model);
53  ocra::PositionFeature feat2("frameTask.feat", SF, ocra::XYZ);
54  ocra::PositionFeature featDes2("frameTask.featDes", TF, ocra::XYZ);
55 
56  TF.setPosition(Eigen::Displacementd(0.2,0.3,0.4));
57  TF.setVelocity(Eigen::Twistd());
58  TF.setAcceleration(Eigen::Twistd());
59 
60 
61  gocra::GHCJTTask& accTask2 = ctrl.createGHCJTTask("frameTask", feat2, featDes2);
62 
63  ctrl.addTask(accTask2);
64  accTask2.activateAsObjective();
65  accTask2.setStiffness(9);
66  accTask2.setDamping(6);
67  accTask2.setWeight(1);
68 
69  ctrl.setActiveTaskVector();
70 
71  // SET TASK PRIORITIES, COMPUTE TASK PROJECTORS
72  int nt = ctrl.getNbActiveTask();
73 
74  MatrixXd param_priority(nt,nt);
75 // std::vector< gocra::GHCJTTask* >& activeTask = ctrl.getActiveTask();
76 
77  param_priority<<0,1,0,0;
78  ctrl.setTaskProjectors(param_priority);
79 
80 
81  //SIMULATE
82  VectorXd q = Eigen::VectorXd::Constant(model.nbInternalDofs(), 0.1);
83  VectorXd dq = Eigen::VectorXd::Zero(model.nbInternalDofs());
84  VectorXd tau = Eigen::VectorXd::Zero(model.nbInternalDofs());
85  VectorXd ddq;
86  double dt = 0.01;
87 
88  std::cout<<"SIMULATE\n";
89  for (int i=0; i<1000; i++)
90  {
91  if (i==600)
92  {
93  param_priority(0,1)=0;
94  param_priority(1,0)=1;
95  }
96  ctrl.setTaskProjectors(param_priority);
97  ctrl.doUpdateProjector();
98  ctrl.computeOutput(tau);
99  ddq = model.getInertiaMatrixInverse() * ( tau - model.getNonLinearTerms() - model.getLinearTerms() - model.getGravityTerms());
100 
101  dq += ddq * dt;
102  q += dq * dt;
103 
104 
105 
106  model.setJointPositions(q);
107  model.setJointVelocities(dq);
108  if (i==1||i==599||i==999)
109  {
110  std::cout<<"- - --- - - - -- - - -- - "<<i<<"\n";
111 
112  std::cout<<"pos seg3: "<< model.getSegmentPosition(3).getTranslation().transpose()<<"\n";
113 
114  }
115 
116  }
117 
118 
119  return 0;
120 }
121 
122 
123 
int nbInternalDofs() const
Definition: Model.cpp:59
Classes that represent frames.
void setDamping(double B)
Definition: Task.cpp:378
void setJointVelocities(const Eigen::VectorXd &q_dot)
Definition: Model.cpp:80
int main(int argc, char **argv)
Definition: main.cpp:20
Definition: Model3T.h:7
void set_q(const Eigen::VectorXd &q)
Definition: FullState.cpp:208
A class hierarchy to compute task errors based on control frames.
gOcra Controller based on LQP solver for the ocra framework.
virtual const Eigen::VectorXd & getGravityTerms() const
Definition: Model3T.cpp:273
void setJointPositions(const Eigen::VectorXd &q)
Definition: Model.cpp:72
Used to build positioning tasks.
Definition: Feature.h:101
Define the Generalized Hierarchical Controller based on Jacobian transpose (GHCJT) in quasi-static ca...
void setPosition(const Eigen::Displacementd &H)
Used to build tasks in the manikin configuration space.
Definition: Feature.h:326
A frame attached to a segment of a model.
Definition: ControlFrame.h:104
A generic abstract task for the GHCJT controller.
Definition: GHCJTTask.h:41
void setAcceleration(const Eigen::Twistd &gamma)
void setTaskProjectors(Eigen::MatrixXd &param)
virtual const Eigen::Displacementd & getSegmentPosition(int index) const
Definition: Model3T.cpp:279
void setVelocity(const Eigen::Twistd &T)
void setWeight(double weight)
Definition: Task.cpp:501
void setStiffness(double K)
Definition: Task.cpp:395
virtual const Eigen::MatrixXd & getInertiaMatrixInverse() const
Definition: Model3T.cpp:253
virtual const Eigen::VectorXd & getNonLinearTerms() const
Definition: Model3T.cpp:263
void computeOutput(Eigen::VectorXd &tau)
Computation of output torques based on the tasks added to the controller.
Definition: Controller.cpp:258
void addTask(std::shared_ptr< Task > task)
Definition: Controller.cpp:184
void activateAsObjective()
Definition: Task.cpp:298
GHCJTTask & createGHCJTTask(const std::string &name, Feature::Ptr feature, Feature::Ptr featureDes) const
Represents a &#39;target&#39;, i.e. something that does not depend on a model but must match with another fra...
Definition: ControlFrame.h:75
virtual const Eigen::VectorXd & getLinearTerms() const
Definition: Model3T.cpp:268
Some enumerations for the control.