test_results.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 /* --------------------------------------------------------------------- */
11 /* --- INCLUDE --------------------------------------------------------- */
12 /* --------------------------------------------------------------------- */
13 
14 #include <fstream>
15 #include <iostream>
16 
17 /* JRL dynamic */
18 #include <jrl/mal/boost.hh>
19 namespace ml = maal::boost;
20 
21 /* JRL dynamic */
22 
23 #include <jrl/dynamics/dynamicsfactory.hh>
24 namespace djj = dynamicsJRLJapan;
25 
26 #include <abstract-robot-dynamics/humanoid-dynamic-robot.hh>
27 #include <abstract-robot-dynamics/robot-dynamics-object-constructor.hh>
28 
29 using namespace std;
30 
31 int main(int argc, char *argv[]) {
32  if (argc != 6) {
33  cerr << " This program takes 4 arguments: " << endl;
34  cerr << "./TestHumanoidDynamicRobot PATH_TO_VRML_FILE VRML_FILE_NAME "
35  << endl;
36  cerr << " PATH_TO_SPECIFICITIES_XML PATH PATH_TO_MAP_JOINT_2_RANK "
37  "INITIAL_CONFIGURATION_FILE"
38  << endl;
39  exit(0);
40  }
41 
42  string aSpecificitiesFileName = argv[3];
43  string aPath = argv[1];
44  string aName = argv[2];
45  string aMapFromJointToRank = argv[4];
46 
47  dynamicsJRLJapan::ObjectFactory aRobotDynamicsObjectConstructor;
48  CjrlHumanoidDynamicRobot *aHDR =
49  aRobotDynamicsObjectConstructor.createHumanoidDynamicRobot();
50 
51  string RobotFileName = aPath + aName;
52  dynamicsJRLJapan::parseOpenHRPVRMLFile(
53  *aHDR, RobotFileName, aMapFromJointToRank, aSpecificitiesFileName);
54 
55  CjrlHumanoidDynamicRobot *aHDR2 =
56  aRobotDynamicsObjectConstructor.createHumanoidDynamicRobot();
57  // cout << "aHDMB2 Finished the initialization"<< endl;
58  dynamicsJRLJapan::parseOpenHRPVRMLFile(
59  *aHDR2, RobotFileName, aMapFromJointToRank, aSpecificitiesFileName);
60 
61  std::ifstream ReferenceStateFile;
62  ReferenceStateFile.open("teleop-rstate.log");
63  if (!ReferenceStateFile.is_open()) {
64  cout << "Could not open teleop-rstate.log" << endl;
65  exit(0);
66  }
67 
68  std::ifstream ActualStateFile;
69  ActualStateFile.open("teleop-astate.log");
70  if (!ActualStateFile.is_open()) {
71  cout << "Could not open teleop-state.log" << endl;
72  exit(0);
73  }
74 
75  std::ofstream FileActualRHPos, FileRefRHPos, FileRefLHPos;
76 
77  MAL_VECTOR_DIM(m_ReferenceStateConf, double, 46);
78  MAL_VECTOR_DIM(m_ReferenceStateConfPrev, double, 46);
79  MAL_VECTOR_DIM(m_ReferenceStateSpeed, double, 46);
80  MAL_VECTOR_DIM(m_ReferenceStateSpeedPrev, double, 46);
81  MAL_VECTOR_DIM(m_ReferenceStateAcc, double, 46);
82  MAL_VECTOR_DIM(m_ActualStateConf, double, 46);
83  MAL_VECTOR_DIM(m_ActualStateConfPrev, double, 46);
84  MAL_VECTOR_DIM(m_ActualStateSpeed, double, 46);
85  MAL_VECTOR_DIM(m_ActualStateSpeedPrev, double, 46);
86  MAL_VECTOR_DIM(m_ActualStateAcc, double, 46);
87 
88  MAL_VECTOR_DIM(m_ReferenceStateData, double, 100);
89  MAL_VECTOR_DIM(m_ActualStateData, double, 131);
90 
91  unsigned int NbIterations = 0;
92 
93  const CjrlJoint *ActualLeftFoot, *ActualRightFoot, *ActualRightHand;
94  const CjrlJoint *ReferenceLeftFoot, *ReferenceRightFoot, *ReferenceRightHand,
95  *ReferenceLeftHand;
96 
97  ReferenceRightFoot = aHDR->rightFoot()->associatedAnkle();
98  ReferenceLeftFoot = aHDR->leftFoot()->associatedAnkle();
99  ReferenceRightHand = aHDR->rightWrist();
100  ReferenceLeftHand = aHDR->leftWrist();
101 
102  ActualRightFoot = aHDR2->rightFoot()->associatedAnkle();
103  ActualLeftFoot = aHDR2->leftFoot()->associatedAnkle();
104  ActualRightHand = aHDR2->rightWrist();
105 
106  matrix4d ReferenceSupportFootPosition;
107  matrix4d ReferenceRightHandPosition;
108  matrix4d ReferenceLeftHandPosition;
109 
110  matrix4d ActualSupportFootPosition;
111  matrix4d ActualRightHandPosition;
112 
113  FileActualRHPos.open("ActualRHPos.dat");
114  FileRefRHPos.open("RefRHPos.dat");
115  FileRefLHPos.open("RefLHPos.dat");
116 
117  string aProperty("ComputeZMP");
118  string aValue("true");
119  aHDR->setProperty(aProperty, aValue);
120  aHDR2->setProperty(aProperty, aValue);
121  while (!ActualStateFile.eof()) {
122  for (unsigned int i = 0; i < 100; i++)
123  ReferenceStateFile >> m_ReferenceStateData[i];
124 
125  for (unsigned int i = 0; i < 40; i++)
126  m_ReferenceStateConf[i + 6] = m_ReferenceStateData[i];
127 
128  if (NbIterations > 0) {
129  for (unsigned int i = 0; i < 46; i++)
130  m_ReferenceStateSpeed[i] =
131  (m_ReferenceStateConf[i] - m_ReferenceStateConfPrev[i]) / 0.005;
132  } else {
133  for (unsigned int i = 0; i < 46; i++) m_ReferenceStateSpeed[i] = 0.0;
134  }
135 
136  // cout << "ReferenceStateConf: " << m_ReferenceStateConf << endl;
137  /* Update the current configuration vector */
138  aHDR->currentConfiguration(m_ReferenceStateConf);
139 
140  /* Update the current velocity vector */
141  aHDR->currentVelocity(m_ReferenceStateSpeed);
142 
143  for (unsigned int i = 0; i < 46; i++) {
144  m_ReferenceStateConfPrev[i] = m_ReferenceStateConf[i];
145  }
146 
147  aHDR->computeForwardKinematics();
148 
149  ReferenceRightHandPosition = ReferenceRightHand->currentTransformation();
150  ReferenceLeftHandPosition = ReferenceLeftHand->currentTransformation();
151  ReferenceSupportFootPosition = ReferenceRightFoot->currentTransformation();
152 
153  FileRefRHPos << MAL_S4x4_MATRIX_ACCESS_I_J(ReferenceRightHandPosition, 0, 3)
154  << " ";
155  FileRefRHPos << MAL_S4x4_MATRIX_ACCESS_I_J(ReferenceRightHandPosition, 1, 3)
156  << " ";
157  FileRefRHPos << MAL_S4x4_MATRIX_ACCESS_I_J(ReferenceRightHandPosition, 2, 3)
158  << endl;
159 
160  FileRefLHPos << MAL_S4x4_MATRIX_ACCESS_I_J(ReferenceLeftHandPosition, 0, 3)
161  << " ";
162  FileRefLHPos << MAL_S4x4_MATRIX_ACCESS_I_J(ReferenceLeftHandPosition, 1, 3)
163  << " ";
164  FileRefLHPos << MAL_S4x4_MATRIX_ACCESS_I_J(ReferenceLeftHandPosition, 2, 3)
165  << endl;
166 
167  /*
168  cout << ReferenceRightHandPosition(0,3) << " "
169  << ReferenceRightHandPosition(1,3) << " "
170  << ReferenceRightHandPosition(2,3) << endl;
171 
172  cout << ReferenceSupportFootPosition(0,3) << " "
173  << ReferenceSupportFootPosition(1,3) << " "
174  << ReferenceSupportFootPosition(2,3) << endl;
175  */
176  // Actual state.
177  for (unsigned int i = 0; i < 131; i++) {
178  ActualStateFile >> m_ActualStateData[i];
179  }
180  for (unsigned int i = 0; i < 40; i++)
181  m_ActualStateConf[i + 6] = m_ActualStateData[i];
182 
183  if (NbIterations > 0) {
184  for (unsigned int i = 6; i < 46; i++)
185  m_ActualStateSpeed[i] =
186  (m_ActualStateConf[i] - m_ActualStateConfPrev[i]) / 0.005;
187  } else {
188  for (unsigned int i = 0; i < 46; i++) m_ActualStateSpeed[i] = 0.0;
189  }
190  /* Update the current configuration vector */
191  aHDR2->currentConfiguration(m_ActualStateConf);
192 
193  /* Update the current velocity vector */
194  aHDR2->currentVelocity(m_ActualStateSpeed);
195 
196  for (unsigned int i = 0; i < 46; i++) {
197  m_ActualStateConfPrev[i] = m_ActualStateConf[i];
198  }
199 
200  aHDR2->computeForwardKinematics();
201 
202  ActualRightHandPosition = ActualRightHand->currentTransformation();
203 
204  FileActualRHPos << MAL_S4x4_MATRIX_ACCESS_I_J(ActualRightHandPosition, 0, 3)
205  << " ";
206  FileActualRHPos << MAL_S4x4_MATRIX_ACCESS_I_J(ActualRightHandPosition, 1, 3)
207  << " ";
208  FileActualRHPos << MAL_S4x4_MATRIX_ACCESS_I_J(ActualRightHandPosition, 2, 3)
209  << endl;
210 
211  NbIterations++;
212  }
213  ActualStateFile.close();
214  ReferenceStateFile.close();
215  FileActualRHPos.close();
216  FileRefRHPos.close();
217  FileRefLHPos.close();
218 }
i
int i
main
int main(int argc, char *argv[])
Definition: test_results.cpp:31


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