test_djj.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2010,
3  * François Bleibel,
4  * Olivier Stasse,
5  *
6  * CNRS/AIST
7  *
8  */
9 
10 #include <cstdio>
11 #include <jrl/mal/matrixabstractlayer.hh>
12 #include <string>
13 
14 #include "jrl/dynamics/dynamicsfactory.hh"
15 using namespace std;
16 using namespace dynamicsJRLJapan;
17 
18 /* --- DISPLAY TREE --------------------------------------------------------- */
19 void RecursiveDisplayOfJoints(const CjrlJoint *aJoint) {
20  if (aJoint == 0) return;
21  int NbChildren = aJoint->countChildJoints();
22  cout << " rank : " << aJoint->rankInConfiguration() << endl;
23 
24  for (int i = 0; i < NbChildren; i++) {
25  RecursiveDisplayOfJoints(aJoint->childJoint(i));
26  }
27 }
28 
29 void DisplayDynamicRobotInformation(CjrlDynamicRobot *aDynamicRobot) {
30  std::vector<CjrlJoint *> aVec = aDynamicRobot->jointVector();
31  int r = aVec.size();
32  cout << "Number of joints :" << r << endl;
33  for (int i = 0; i < r; i++) {
34  cout << aVec[i]->rankInConfiguration() << endl;
35  }
36 }
37 
38 void DisplayMatrix(MAL_MATRIX(&aJ, double)) {
39  for (unsigned int i = 0; i < 6; i++) {
40  for (unsigned int j = 0; j < MAL_MATRIX_NB_COLS(aJ); j++) {
41  if (aJ(i, j) == 0.0)
42  printf("0 ");
43  else
44  printf("%10.5f ", aJ(i, j));
45  }
46  printf("\n");
47  }
48 }
49 
50 /* --- DISPLAY MASS PROPERTIES OF A CHAIN --- */
51 void GoDownTree(const CjrlJoint *startJoint) {
52  cout << "Mass-inertie property of joint ranked :"
53  << startJoint->rankInConfiguration() << endl;
54  cout << "Mass of the body: " << startJoint->linkedBody()->mass() << endl;
55  cout << "llimit: " << startJoint->lowerBound(0) * 180 / M_PI
56  << " ulimit: " << startJoint->upperBound(0) * 180 / M_PI << endl;
57  cout << startJoint->currentTransformation() << endl;
58 
59  if (startJoint->countChildJoints() != 0) {
60  const CjrlJoint *childJoint = startJoint->childJoint(0);
61  GoDownTree(childJoint);
62  }
63 }
64 
65 /* --- MAIN ----------------------------------------------------------------- */
66 /* --- MAIN ----------------------------------------------------------------- */
67 /* --- MAIN ----------------------------------------------------------------- */
68 int main(int argc, char *argv[]) {
69  if (argc != 4) {
70  cerr << " This program takes 3 arguments: " << endl;
71  cerr << "./TestHumanoidDynamicRobot PATH_TO_VRML_FILE "
72  << "VRML_FILE_NAME PATH_TO_SPECIFICITIES_XML" << endl;
73  exit(0);
74  }
75 
76  string aPath = argv[1];
77  string aName = argv[2];
78 
79  // DynamicMultiBody * aDMB
80  // = new DynamicMultiBody();
81  // aDMB->parserVRML(aPath,aName,"");
82  // HumanoidDynamicMultiBody *aHDMB
83  // = new HumanoidDynamicMultiBody(aDMB,aSpecificitiesFileName);
84 
85  /* ------------------------------------------------------------------------ */
86  dynamicsJRLJapan::ObjectFactory aRobotDynamicsObjectConstructor;
87  CjrlHumanoidDynamicRobot *aHDR =
88  aRobotDynamicsObjectConstructor.createHumanoidDynamicRobot();
89 
90  // DynamicMultiBody * aDMB
91  // = (DynamicMultiBody *) aHDMB->getDynamicMultiBody();
92  string SpecificitiesFile = argv[3];
93  string RankFile = argv[3];
94  // Parsing the file.
95  string RobotFileName = aPath + aName;
96  dynamicsJRLJapan::parseOpenHRPVRMLFile(*aHDR, RobotFileName, RankFile,
97  SpecificitiesFile);
98 
99  cout << "-> Finished the initialization" << endl;
100  /* ------------------------------------------------------------------------ */
101 
102  // Display tree of the joints.
103  CjrlJoint *rootJoint = aHDR->rootJoint();
104  RecursiveDisplayOfJoints(rootJoint);
105 
106  // Test the computation of the jacobian.
107  double dInitPos[40] = {
108  0.0, 0.0, -26.0, 50.0, -24.0, 0.0, 0.0,
109  0.0, -26.0, 50.0, -24.0, 0.0, // legs
110 
111  0.0, 0.0, 0.0, 0.0, // chest and head
112 
113  15.0, -10.0, 0.0, -30.0, 0.0, 0.0, 10.0, // right arm
114  15.0, 10.0, 0.0, -30.0, 0.0, 0.0, 10.0, // left arm
115 
116  -20.0, 20.0, -20.0, 20.0, -20.0, // right hand
117  -10.0, 10.0, -10.0, 10.0, -10.0 // left hand
118  };
119 
120  int NbOfDofs = aHDR->numberDof();
121  cout << "NbOfDofs :" << NbOfDofs << endl;
122 
123  /* Set current conf to dInitPos. */
124  MAL_VECTOR_DIM(aCurrentConf, double, NbOfDofs);
125  for (int i = 0; i < ((NbOfDofs < 46) ? NbOfDofs : 46); ++i)
126  if (i < 6)
127  aCurrentConf[i] = 0.0;
128  else
129  aCurrentConf[i] = dInitPos[i - 6] * M_PI / 180.0;
130  aHDR->currentConfiguration(aCurrentConf);
131 
132  /* Set current velocity to 0. */
133  MAL_VECTOR_DIM(aCurrentVel, double, NbOfDofs);
134  for (int i = 0; i < NbOfDofs; i++) aCurrentVel[i] = 0.0;
135  aHDR->currentVelocity(aCurrentVel);
136 
137  /* Compute ZMP and CoM */
138  MAL_S3_VECTOR(ZMPval, double);
139  string Property("ComputeZMP");
140  string Value("true");
141  aHDR->setProperty(Property, Value);
142  aHDR->computeForwardKinematics();
143  ZMPval = aHDR->zeroMomentumPoint();
144  cout << "First value of ZMP : " << ZMPval << endl;
145  cout << "Should be equal to the CoM (on x-y): "
146  << aHDR->positionCenterOfMass() << endl;
147 
148  /* Get Rhand joint. */
149 
150  cout << "****************************" << endl;
151  cout << "Rank of the left hand " << endl;
152  cout << aHDR->leftWrist()->rankInConfiguration() << endl;
153 
154  vector<CjrlJoint *> aVec = aHDR->jointVector();
155  CjrlJoint *aJoint = aVec[22];
156  aJoint->computeJacobianJointWrtConfig();
157  MAL_MATRIX(aJ, double);
158  aJ = aJoint->jacobianJointWrtConfig();
159  DisplayMatrix(aJ);
160 
161  /* Get Waist joint. */
162  cout << "****************************" << endl;
163  rootJoint->computeJacobianJointWrtConfig();
164  aJ = rootJoint->jacobianJointWrtConfig();
165  cout << "Rank of Root: " << rootJoint->rankInConfiguration() << endl;
166  aJoint = aHDR->waist();
167 
168  /* Get CoM jacobian. */
169  cout << "****************************" << endl;
170  matrixNxP jacobian;
171  aHDR->getJacobianCenterOfMass(*aHDR->rootJoint(), jacobian);
172  cout << "Value of the CoM's Jacobian:" << endl << jacobian << endl;
173 
174  /* Display the mass property of the leg. */
175  cout << "****************************" << endl;
176  GoDownTree(aHDR->rootJoint());
177  cout << "Mass of the robot " << aHDR->mass() << endl;
178  cout << "Force " << aHDR->mass() * 9.81 << endl;
179 
180  cout << "****************************" << endl;
181  MAL_VECTOR_FILL(aCurrentVel, 0.0);
182  MAL_VECTOR_DIM(aCurrentAcc, double, NbOfDofs);
183  MAL_VECTOR_FILL(aCurrentAcc, 0.0);
184 
185  // This is mandatory for this implementation of computeForwardKinematics
186  // to compute the derivative of the momentum.
187  string Properties[4] = {"TimeStep", "ComputeAcceleration",
188  "ComputeBackwardDynamics", "ComputeZMP"};
189  string Values[4] = {"0.005", "false", "false", "true"};
190  for (unsigned int i = 0; i < 4; i++)
191  aHDR->setProperty(Properties[i], Values[i]);
192 
193  for (int i = 0; i < 4; i++) {
194  aHDR->currentVelocity(aCurrentVel);
195  aHDR->currentAcceleration(aCurrentAcc);
196  aHDR->computeForwardKinematics();
197  ZMPval = aHDR->zeroMomentumPoint();
198  cout << i << "-th value of ZMP : " << ZMPval << endl;
199  cout << "Should be equal to the CoM: " << aHDR->positionCenterOfMass()
200  << endl;
201  }
202 
203  // The End!
204  delete aHDR;
205 
206  return true;
207 }
DisplayDynamicRobotInformation
void DisplayDynamicRobotInformation(CjrlDynamicRobot *aDynamicRobot)
Definition: test_djj.cpp:29
RecursiveDisplayOfJoints
void RecursiveDisplayOfJoints(const CjrlJoint *aJoint)
Definition: test_djj.cpp:19
Values
std::vector< Value > Values
i
int i
r
FCL_REAL r
main
int main(int argc, char *argv[])
Definition: test_djj.cpp:68
GoDownTree
void GoDownTree(const CjrlJoint *startJoint)
Definition: test_djj.cpp:51
DisplayMatrix
void DisplayMatrix(MAL_MATRIX(&aJ, double))
Definition: test_djj.cpp:38
M_PI
#define M_PI


sot-dynamic-pinocchio
Author(s): Olivier Stasse
autogenerated on Fri Jul 28 2023 02:10:01