TestNaveau2015.cpp 35.2 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
 * Copyright 2009, 2010, 2014
 *
 * Maximilien Naveau
 * Olivier  Stasse,
 *
 * JRL, CNRS/AIST
 *
 * This file is part of walkGenJrl.
 * walkGenJrl is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * walkGenJrl is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Lesser Public License for more details.
 * You should have received a copy of the GNU Lesser General Public License
 * along with walkGenJrl.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  Research carried out within the scope of the
 *  Joint Japanese-French Robotics Laboratory (JRL)
 */
/*! \file TestNaveau2015.cpp
  \brief This Example shows you how to use the nmpc_genereator.cpp */
#include <stdlib.h>
#include <iostream>
#include <fstream>
30
31
32
33
#include <iomanip>
#include <string>
#include <map>
#include <cmath>
34

35
#include <jrl/walkgen/config_private.hh>
36
#include <jrl/walkgen/pgtypes.hh>
37
38
39
#include "Debug.hh"
#include "CommonTools.hh"
#include "TestObject.hh"
40
#include "MotionGeneration/ComAndFootRealizationByGeometry.hh"
41
42

using namespace std;
43
44
using namespace PatternGeneratorJRL;
using namespace::PatternGeneratorJRL::TestSuite;
45
46

enum Profiles_t {
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
  PROFIL_NAVEAU,       // 0
  PROFIL_SIMPLE_NAVEAU // 1
};

typedef void (TestObject:: * localeventHandler_t)(PatternGeneratorInterface &);

struct localEvent
{
  unsigned time;
  localeventHandler_t Handler ;
};

struct setOfLocalEvents
{
  std::vector<localEvent> m_vecOfLocalEvents;
  PatternGeneratorInterface *m_PGI;
  
  setOfLocalEvents(PatternGeneratorInterface *aPGI)
  { m_PGI = aPGI;} 
    
  void initVecOfLocalEvents( struct localEvent * events,
			     unsigned int sizeOfEvents)
  {
    for(unsigned int i=0;i<sizeOfEvents;i++)
      {
	m_vecOfLocalEvents.push_back(events[i]);
      }
  }
  
  void evaluateEvents(struct OneStep &oneStep,
		      TestObject &aTestObject)
  {
    // Test when triggering event.
    for(unsigned int i=0;i<m_vecOfLocalEvents.size();i++)
      {
	if ( oneStep.NbOfIt==m_vecOfLocalEvents[i].time)
	  {
	    ODEBUG3("********* GENERATE EVENT EMS ***********");
	    (aTestObject.*(m_vecOfLocalEvents[i].Handler))(*m_PGI);
	  }
      }
  }
89
90
};

91
// Class TestNaveau2015
92
93
94
95
96
class TestNaveau2015: public TestObject
{

private:
  int resetfiles ;
97
  bool m_DebugFGPIFull ;
98
  vector<double> m_err_zmp_x, m_err_zmp_y;
99

100
  int iteration;
Olivier Stasse's avatar
Olivier Stasse committed
101
102
103
104
105
106
  std::vector<pinocchio::JointIndex> m_leftLeg  ;
  std::vector<pinocchio::JointIndex> m_rightLeg ;
  std::vector<pinocchio::JointIndex> m_leftArm  ;
  std::vector<pinocchio::JointIndex> m_rightArm ;
  pinocchio::JointIndex m_leftGripper  ;
  pinocchio::JointIndex m_rightGripper ;
107

108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
  /// Object to generate events according to profile.
  setOfLocalEvents * m_setOfLocalEvents;
  std::vector<double> m_prevCoMp;
  std::vector<double> m_prevdCoMp;
  std::vector<double> m_prevddCoMp;
  std::vector<double> m_prevWaistOrien;  
  
  std::vector<double> m_prevLeftFootPos,
    m_prevLeftFootdPos,
    m_prevLeftFootddPos,
    m_prevLeftFootOrientation,
    m_prevLeftFootdOrientation,
    m_prevLeftFootddOrientation;
  
  std::vector<double> m_prevRightFootPos,
    m_prevRightFootdPos,
    m_prevRightFootddPos,
    m_prevRightFootOrientation,
    m_prevRightFootdOrientation,
    m_prevRightFootddOrientation;

  std::vector<double> m_prevZMPMB, m_prevZMPRef;
  
131
132
133
134
135
136
public:
  TestNaveau2015(int argc, char *argv[], string &aString, int TestProfile):
    TestObject(argc,argv,aString)
  {
    m_TestProfile = TestProfile;
    resetfiles=0;
137
    m_DebugFGPIFull=true;
138
    m_DebugFGPI=true;
139
140
141
    m_err_zmp_x.clear();
    m_err_zmp_y.clear();
    iteration=0;
142
143
144
145
    m_leftLeg .clear();
    m_rightLeg.clear();
    m_leftArm .clear();
    m_rightArm.clear();
146
147
    m_leftGripper  = 0 ;
    m_rightGripper = 0 ;
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
    m_setOfLocalEvents = 0;

    m_prevCoMp.resize(3);
    m_prevdCoMp.resize(3);
    m_prevddCoMp.resize(3);
    m_prevWaistOrien.resize(3);
    
    m_prevLeftFootPos.resize(3);
    m_prevLeftFootdPos.resize(3);
    m_prevLeftFootddPos.resize(3);
    m_prevLeftFootOrientation.resize(3);
    m_prevLeftFootdOrientation.resize(3);
    m_prevLeftFootddOrientation.resize(3);

    m_prevRightFootPos.resize(3);
    m_prevRightFootdPos.resize(3);
    m_prevRightFootddPos.resize(3);
    m_prevRightFootOrientation.resize(3);
    m_prevRightFootdOrientation.resize(3);
    m_prevRightFootddOrientation.resize(3);

    m_prevZMPMB.resize(3);
    m_prevZMPRef.resize(3);
171
172
173
174
  }



175
  bool doTest(std::ostream &os)
176
  {
177
    bool ret = TestObject::doTest(os);
178
179
    if(m_DebugFGPIFull)
      ComputeAndDisplayZMPStatistic();
180
    return ret ;
181
  }
182

183
184
185
186
  bool init()
  {
    if(!TestObject::init())
      return false;
187
188
189
190
191
192
193
194
195
196
197
198
199
200

    /// Initialize Configuration Velocity and Acceleration
    m_CurrentVelocity.setZero();
    m_CurrentAcceleration.setZero();
    m_setOfLocalEvents = new setOfLocalEvents(m_PGI);

    ODEBUG3("m_vel" << m_CurrentVelocity);
    ODEBUG3("m_acc" << m_CurrentAcceleration);
    if (m_PR->getName()=="hrp2_14_reduced")
      m_ComAndFootRealization->SetHeightOfTheCoM(0.814);
    else if (m_PR->getName()=="talos")
      m_ComAndFootRealization->SetHeightOfTheCoM(0.876681);
    

201
    m_leftLeg =
202
      m_PR->jointsBetween(m_PR->waist(),m_PR->leftFoot()->associatedAnkle);
203
    m_rightLeg =
204
      m_PR->jointsBetween(m_PR->waist(),m_PR->rightFoot()->associatedAnkle);
205
    m_leftArm =
206
      m_PR->jointsBetween(m_PR->chest(),m_PR->leftWrist());
207
    m_rightArm =
208
      m_PR->jointsBetween(m_PR->chest(),m_PR->rightWrist());
209
210
211
212

    m_leftLeg.erase( m_leftLeg.begin() );
    m_rightLeg.erase( m_rightLeg.begin() );

Olivier Stasse's avatar
Olivier Stasse committed
213
    pinocchio::JointModelVector & ActuatedJoints = m_PR->getActuatedJoints();
214
    for(unsigned i=0 ; i <m_leftLeg.size() ; ++i)
Olivier Stasse's avatar
Olivier Stasse committed
215
      m_leftLeg[i] = pinocchio::idx_q(ActuatedJoints[m_leftLeg[i]])-1;
216
    for(unsigned i=0 ; i <m_rightLeg.size() ; ++i)
Olivier Stasse's avatar
Olivier Stasse committed
217
      m_rightLeg[i] = pinocchio::idx_q(ActuatedJoints[m_rightLeg[i]])-1;
218
    for(unsigned i=0 ; i <m_leftArm.size() ; ++i)
Olivier Stasse's avatar
Olivier Stasse committed
219
      m_leftArm[i] = pinocchio::idx_q(ActuatedJoints[m_leftArm[i]])-1;
220
    for(unsigned i=0 ; i <m_rightArm.size() ; ++i)
Olivier Stasse's avatar
Olivier Stasse committed
221
      m_rightArm[i] = pinocchio::idx_q(ActuatedJoints[m_rightArm[i]])-1;
222

223
224
225
226
227
228
229
230
231
232
233
234
    if((m_robotModel.parents.size() >= m_rightArm.back()+1) &&
       m_robotModel.parents[m_rightArm.back()+1] == m_rightArm.back())
      m_rightGripper = m_rightArm.back()+1 ;
    else
      m_rightGripper = 0 ;

    if((m_robotModel.parents.size() >= m_leftArm.back()+1) &&
       m_robotModel.parents[m_leftArm.back()+1] == m_leftArm.back())
      m_leftGripper = m_leftArm.back()+1 ;
    else
      m_leftGripper = 0 ;

235
    return true ;
236
237
  }

238
protected:
239
240
241
242
243
244
245

  void ComputeStat(vector<double> vec,double &avg, double &max_abs)
  {
    double total = 0.0 ;
    avg = 0.0 ;
    max_abs = 0.0 ;
    for (unsigned int i = 0 ; i < vec.size() ; ++i)
246
247
248
249
      {
	double abs_value = sqrt(vec[i]*vec[i]) ;
	if( abs_value > max_abs)
	  max_abs = abs_value ;
250

251
252
	total += abs_value ;
      }
Olivier Stasse's avatar
Olivier Stasse committed
253
    avg = total/(double)(vec.size());
254
255
256
257
258
259
260
261
    return ;
  }

  void ComputeAndDisplayZMPStatistic()
  {
    cout << "Statistic for Dzmp in x : " << endl ;
    double moy_delta_zmp_x = 0.0 ;
    double max_abs_err_x = 0.0 ;
262
    ComputeStat(m_err_zmp_x,moy_delta_zmp_x,max_abs_err_x);
263
264
265
266
267
268
    cout << "average : " << moy_delta_zmp_x << endl ;
    cout << "maxx error : " << max_abs_err_x << endl ;

    cout << "Statistic for Dzmp in y : " << endl ;
    double moy_delta_zmp_y = 0.0 ;
    double max_abs_err_y = 0.0 ;
269
    ComputeStat(m_err_zmp_y,moy_delta_zmp_y,max_abs_err_y);
270
271
272
273
274
    cout << "average : " << moy_delta_zmp_y << endl ;
    cout << "maxx error : " << max_abs_err_y << endl ;
    return ;
  }

Olivier Stasse's avatar
Olivier Stasse committed
275
276
277
  void analyticalInverseKinematics(Eigen::VectorXd & conf,
                                   Eigen::VectorXd & vel,
                                   Eigen::VectorXd & acc)
278
279
280
281
  {
    /// \brief calculate, from the CoM of computed by the preview control,
    ///    the corresponding articular position, velocity and acceleration
    /// ------------------------------------------------------------------
Olivier Stasse's avatar
Olivier Stasse committed
282
283
284
285
286
    Eigen::VectorXd aCOMState(6);
    Eigen::VectorXd aCOMSpeed(6);
    Eigen::VectorXd aCOMAcc(6);
    Eigen::VectorXd aLeftFootPosition(5);
    Eigen::VectorXd aRightFootPosition(5);
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319

    aCOMState(0) = m_OneStep.finalCOMPosition.x[0];
    aCOMState(1) = m_OneStep.finalCOMPosition.y[0];
    aCOMState(2) = m_OneStep.finalCOMPosition.z[0];
    aCOMState(3) = m_OneStep.finalCOMPosition.roll[0]  * 180/M_PI ;
    aCOMState(4) = m_OneStep.finalCOMPosition.pitch[0] * 180/M_PI ;
    aCOMState(5) = m_OneStep.finalCOMPosition.yaw[0]   * 180/M_PI ;

    aCOMSpeed(0) = m_OneStep.finalCOMPosition.x[1];
    aCOMSpeed(1) = m_OneStep.finalCOMPosition.y[1];
    aCOMSpeed(2) = m_OneStep.finalCOMPosition.z[1];
    aCOMSpeed(3) = m_OneStep.finalCOMPosition.roll[1] /** * 180/M_PI  */ ;
    aCOMSpeed(4) = m_OneStep.finalCOMPosition.pitch[1]/** * 180/M_PI  */ ;
    aCOMSpeed(5) = m_OneStep.finalCOMPosition.yaw[1]/** * 180/M_PI  */ ;

    aCOMAcc(0) = m_OneStep.finalCOMPosition.x[2];
    aCOMAcc(1) = m_OneStep.finalCOMPosition.y[2];
    aCOMAcc(2) = m_OneStep.finalCOMPosition.z[2];
    aCOMAcc(3) = m_OneStep.finalCOMPosition.roll[2]/** * 180/M_PI  */ ;
    aCOMAcc(4) = m_OneStep.finalCOMPosition.pitch[2]/** * 180/M_PI  */ ;
    aCOMAcc(5) = m_OneStep.finalCOMPosition.yaw[2] /** * 180/M_PI  */;

    aLeftFootPosition(0) = m_OneStep.LeftFootPosition.x;
    aLeftFootPosition(1) = m_OneStep.LeftFootPosition.y;
    aLeftFootPosition(2) = m_OneStep.LeftFootPosition.z;
    aLeftFootPosition(3) = m_OneStep.LeftFootPosition.theta;
    aLeftFootPosition(4) = m_OneStep.LeftFootPosition.omega;

    aRightFootPosition(0) = m_OneStep.RightFootPosition.x;
    aRightFootPosition(1) = m_OneStep.RightFootPosition.y;
    aRightFootPosition(2) = m_OneStep.RightFootPosition.z;
    aRightFootPosition(3) = m_OneStep.RightFootPosition.theta;
    aRightFootPosition(4) = m_OneStep.RightFootPosition.omega;
320
321
322
323
    m_ComAndFootRealization->setSamplingPeriod(0.005);
    m_ComAndFootRealization->ComputePostureForGivenCoMAndFeetPosture(
								     aCOMState, aCOMSpeed, aCOMAcc, aLeftFootPosition, aRightFootPosition,
								     conf, vel, acc, iteration, 1);
324

325
    if(m_leftGripper!=0 && m_rightGripper!=0)
326
327
328
329
      {
	conf(m_leftGripper) = 10.0*M_PI/180.0;
	conf(m_rightGripper) = 10.0*M_PI/180.0;
      }
330
  }
331

Olivier Stasse's avatar
Olivier Stasse committed
332
  Eigen::VectorXd parseFromURDFtoOpenHRPIndex()
333
  {
Olivier Stasse's avatar
Olivier Stasse committed
334
335
    Eigen::VectorXd conf = m_conf;
    { for(unsigned int i=0;i<conf.size();conf[i++]=0.0);};
336
337
338

    for(unsigned int i = 0 ; i < 6 ; i++)
      conf(i) = m_conf(i);
339
    std::size_t index=6;
340
341
342
    //RLEG
    for(unsigned int i = 0 ; i < m_rightLeg.size() ; i++)
      conf(index+i) = m_conf(m_rightLeg[i]);
Olivier Stasse's avatar
Olivier Stasse committed
343
    index+=(unsigned)m_rightLeg.size();
344
345
346
    //LLEG
    for(unsigned int i = 0 ; i < m_leftLeg.size() ; i++)
      conf(index+i) = m_conf(m_leftLeg[i]);
Olivier Stasse's avatar
Olivier Stasse committed
347
    index+=(unsigned)m_leftLeg.size();
348
349
350
351
352
353
354
355
356
357
    //CHEST
    for(unsigned int i = 0 ; i < 2 ; i++)
      conf(index+i) = 0.0 ;
    index+= 2 ;
    //HEAD
    for(unsigned int i = 0 ; i < 2 ; i++)
      conf(index+i) = 0.0 ;
    index+= 2 ;
    //RARM
    for(unsigned int i = 0 ; i < m_rightArm.size() ; i++)
358
      conf(index+i) = m_HalfSitting(m_rightArm[i]-6);
Olivier Stasse's avatar
Olivier Stasse committed
359
    index+=(unsigned)m_rightArm.size();
360
361
    conf(index) = 10*M_PI/180;
    ++index;
362
363
    //LARM
    for(unsigned int i = 0 ; i < m_leftArm.size() ; i++)
364
365
366
      conf(index+i) = m_HalfSitting(m_leftArm[i]-6);
    index+=m_leftArm.size();
    conf(index) = 10*M_PI/180;
367
368
369
370

    return conf ;
  }

371
  void createOpenHRPFiles()
372
  {
373
374
    /// \brief Create file .hip .pos .zmp
    /// ---------------------------------
Olivier Stasse's avatar
Olivier Stasse committed
375
    Eigen::VectorXd conf = parseFromURDFtoOpenHRPIndex();
376
    ofstream aof ;
377
378
379
380
    string aPosFileName = /*"/tmp/" +*/ m_TestName + ".pos" ;
    string aZMPFileName = /*"/tmp/" +*/ m_TestName + ".zmp" ;
    string aWaistFileName = /*"/tmp/" +*/ m_TestName + ".waist" ;
    string aHipFileName = /*"/tmp/" +*/ m_TestName + ".hip" ;
381
    if ( iteration == 0 )
382
383
384
385
386
387
388
389
390
391
      {
	aof.open(aPosFileName.c_str(),ofstream::out);
	aof.close();
	aof.open(aZMPFileName.c_str(),ofstream::out);
	aof.close();
	aof.open(aWaistFileName.c_str(),ofstream::out);
	aof.close();
	aof.open(aHipFileName.c_str(),ofstream::out);
	aof.close();
      }
392

393
    aof.open(aPosFileName.c_str(),ofstream::app);
394
395
    aof.precision(8);
    aof.setf(ios::scientific, ios::floatfield);
396
    aof << filterprecision( (double)iteration * 0.005 ) << " "  ;// 1
Olivier Stasse's avatar
Olivier Stasse committed
397
    for(unsigned i=6 ; i<conf.size() ; ++i)
398
      aof << filterprecision( conf(i) ) << " "  ;                    // 2-30
399
    for(unsigned i=0 ; i<9 ; ++i)
400
401
      aof << filterprecision( 0.0 ) << " "  ;                        // 31-40
    aof << 0.0  << endl ;                                            // 41
402
403
    aof.close();

404
    aof.open(aWaistFileName.c_str(),ofstream::app);
405
406
    aof.precision(8);
    aof.setf(ios::scientific, ios::floatfield);
407
    aof << filterprecision( (double)iteration * 0.005 ) << " "  ;     // 1
408
409
410
411
412
413
    aof << filterprecision( m_OneStep.finalCOMPosition.roll[0]) << " "  ; // 2
    aof << filterprecision( m_OneStep.finalCOMPosition.pitch[0]) << " "  ;// 3
    aof << filterprecision( m_OneStep.finalCOMPosition.yaw[0]) ;          // 4
    aof << endl ;
    aof.close();

414
415

    aof.open(aHipFileName.c_str(),ofstream::app);
416
417
    aof.precision(8);
    aof.setf(ios::scientific, ios::floatfield);
418
    aof << filterprecision( (double)iteration * 0.005 ) << " "  ;     // 1
419
    aof << filterprecision( m_OneStep.finalCOMPosition.roll[0]) << " "  ; // 2
420
421
422
423
424
    aof << filterprecision( m_OneStep.finalCOMPosition.pitch[0]) << " "  ;// 3
    aof << filterprecision( m_OneStep.finalCOMPosition.yaw[0]) ;          // 4
    aof << endl ;
    aof.close();

425

426
427
428
429
430
431
    FootAbsolutePosition aSupportState;
    if (m_OneStep.LeftFootPosition.stepType < 0 )
      aSupportState = m_OneStep.LeftFootPosition ;
    else
      aSupportState = m_OneStep.RightFootPosition ;

432
    aof.open(aZMPFileName.c_str(),ofstream::app);
433
434
    aof.precision(8);
    aof.setf(ios::scientific, ios::floatfield);
435
    aof << filterprecision( (double)iteration * 0.005 ) << " "  ;   // 1
436
437
438
    aof << filterprecision( m_OneStep.ZMPTarget(0) - conf(0)) << " "  ; // 2
    aof << filterprecision( m_OneStep.ZMPTarget(1) - conf(1) ) << " "  ;// 3
    aof << filterprecision( aSupportState.z  - conf(2))  ;              // 4
439
440
    aof << endl ;
    aof.close();
441
442
443
444
445
  }

  void prepareDebugFiles()
  {
    TestObject::prepareDebugFiles() ;
446
    if (m_DebugFGPIFull)
447
      {
448
449
450
451
452
453
	ofstream aof;
	string aFileName;

	aFileName = m_TestName;	  
        aFileName += "TestFGPIFull_description.dat";

454
        aof.open(aFileName.c_str(),ofstream::out);
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518

        string Titles[51] =
	  { "Time",                          // 1
	    "Com X",                         // 2
	    "Com Y" ,                        // 3
	    "Com Z" ,                        // 4
	    "Com Yaw",                       // 5
	    "Com dX" ,                       // 6
	    "Com dY" ,                       // 7
	    "Com dZ" ,                       // 8
	    "Com dYaw",	                     // 9
	    "Com ddX" ,                      // 10
	    "Com ddY" ,                      // 11
	    "Com ddZ" ,                      // 12
	    "Com ddYaw",                     // 13 
	    "ZMP X (world ref.)" ,           // 14
	    "ZMP Y (world ref.)" ,           // 15
	    "ZMP Z (world ref.)" ,	     // 16
	    "Left Foot X" ,                  // 17
	    "Left Foot Y" ,                  // 18
	    "Left Foot Z" ,                  // 19
	    "Left Foot dX" ,                 // 20
	    "Left Foot dY" ,                 // 21
	    "Left Foot dZ" ,                 // 22
	    "Left Foot ddX" ,                // 23
	    "Left Foot ddY" ,                // 24
	    "Left Foot ddZ" ,                // 25
	    "Left Foot Theta" ,              // 26
	    "Left Foot dTheta" ,             // 27
	    "Left Foot ddTheta" ,	     // 28
	    "Left Foot Omega" ,              // 29
	    "Left Foot Omega2" ,             // 30
	    "Right Foot X" ,                 // 31      
	    "Right Foot Y" ,                 // 32
	    "Right Foot Z" ,                 // 33
	    "Right Foot dX" ,                // 34
	    "Right Foot dY" ,                // 35
	    "Right Foot dZ" ,                // 36
	    "Right Foot ddX" ,               // 37 
	    "Right Foot ddY" ,               // 38
	    "Right Foot ddZ" ,               // 39
	    "Right Foot Theta" ,             // 40
	    "Right Foot dTheta" ,            // 41
	    "Right Foot ddTheta" ,	     // 42
	    "Right Foot Omega" ,             // 43
	    "Right Foot Omega2" ,            // 44
	    "ZMP MB X " ,                    // 45
	    "ZMP MB Y " ,                    // 46
	    "ZMP MB Z " ,	             // 47
	    "q " ,                           // 48 
	    "dq" ,                           // 48 + nq
	    "ddq "};                         // 48 + nq + nv
        for(unsigned int i=0;i<51;i++)
          aof << i+1 << ". " <<Titles[i] <<std::endl;
	
        aof.close();

	aFileName = m_TestName;
	aFileName += "TestFGPIFull.dat";
	if (m_OneStep.NbOfIt==1)
	  {
	    aof.open(aFileName.c_str(),ofstream::out);
	  }

519
520
521
      }
  }

522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
  void prepareFile(ofstream &aof,string &prefix)
  {
    string aFileName;
    aFileName = prefix;
    aFileName += ".dat";
    if (m_OneStep.NbOfIt==1)
      {
	aof.open(aFileName.c_str(),ofstream::out);
      }
    resetfiles = 1;
    aof.open(aFileName.c_str(),ofstream::app);
    aof.precision(8);
    aof.setf(ios::scientific, ios::floatfield);

  }

  void fillFileWithSubsamplingAndClose
  (ofstream &aof,
   std::vector<double> &prev,
   std::vector<double> &next,
   double nb_subsampling=5.0)
  {
    for(double subsampling=1.0;
	subsampling <= nb_subsampling;
	subsampling+=1.0)
      {
	//	aof << filterprecision(((double)m_OneStep.NbOfIt)*dt
	//		       + subsampling*dt/nb_subsampling ) << " ";   // 1
	for(unsigned int i=0;
	    i<next.size();
	    i++)
	  {
	    double intermediate = prev[i] +
	      (next[i]-prev[i])*subsampling/nb_subsampling ;
	    aof << intermediate << " ";
	  }
	aof << std::endl;
      }
    aof.close();
    prev = next;
  }

  void fillInTests()
  {
    ofstream aof;
    string prefix= m_TestName + "CoM";
    std::vector<double> vec_db;

    /// CoM Position
    prepareFile(aof,prefix);
    vec_db.resize(3);
    vec_db[0] = filterprecision(m_OneStep.finalCOMPosition.x[0] );
    vec_db[1] = filterprecision(m_OneStep.finalCOMPosition.y[0] );
    vec_db[2] = filterprecision(m_OneStep.finalCOMPosition.z[0] );
    fillFileWithSubsamplingAndClose(aof,m_prevCoMp,vec_db);

    /// CoM velocity
    prefix= m_TestName + "dCoM";
    prepareFile(aof,prefix);
    vec_db[0] = filterprecision(m_OneStep.finalCOMPosition.x[1] );    // 6
    vec_db[1] = filterprecision(m_OneStep.finalCOMPosition.y[1] );    // 7
    vec_db[2] = filterprecision(m_OneStep.finalCOMPosition.z[1] );    // 8
    fillFileWithSubsamplingAndClose(aof,m_prevdCoMp,vec_db);

    /// CoM acceleration
    prefix= m_TestName + "ddCoM";
    prepareFile(aof,prefix);
    vec_db[0] = filterprecision(m_OneStep.finalCOMPosition.x[2] );    // 10
    vec_db[1] =  filterprecision(m_OneStep.finalCOMPosition.y[2] );    // 11
    vec_db[2] = filterprecision(m_OneStep.finalCOMPosition.z[2] );    // 12
    fillFileWithSubsamplingAndClose(aof,m_prevddCoMp,vec_db);    
      
    /// Waist Orientation
    prefix= m_TestName + "WaistOrientation";
    prepareFile(aof,prefix);
    vec_db[0] = filterprecision(m_OneStep.finalCOMPosition.yaw[0] );  // 5
    vec_db[1] = filterprecision(m_OneStep.finalCOMPosition.yaw[1] );  // 9
    vec_db[2] = filterprecision(m_OneStep.finalCOMPosition.yaw[2] );  // 13
    fillFileWithSubsamplingAndClose(aof,m_prevWaistOrien,vec_db);    
    
    /// ZMP Ref
    prefix= m_TestName + "ZMPRef";
    prepareFile(aof,prefix);
    vec_db[0] = filterprecision(m_OneStep.ZMPTarget(0) );             // 14
    vec_db[1] =  filterprecision(m_OneStep.ZMPTarget(1) );             // 15
    vec_db[2] =  filterprecision(m_OneStep.ZMPTarget(2) );           // 16
    fillFileWithSubsamplingAndClose(aof,m_prevZMPRef,vec_db);

    prefix= m_TestName + "LeftFootPos";
    prepareFile(aof,prefix);
    vec_db[0] = filterprecision(m_OneStep.LeftFootPosition.x  );      // 17
    vec_db[1] = filterprecision(m_OneStep.LeftFootPosition.y  );      // 18
    vec_db[2] = filterprecision(m_OneStep.LeftFootPosition.z  );      // 19
    fillFileWithSubsamplingAndClose(aof,m_prevLeftFootPos,vec_db);    
    
    prefix= m_TestName + "LeftFootdPos";
    prepareFile(aof,prefix);
    vec_db[0] = filterprecision(m_OneStep.LeftFootPosition.dx  );     // 20
    vec_db[1] =  filterprecision(m_OneStep.LeftFootPosition.dy  );     // 21
    vec_db[2] =filterprecision(m_OneStep.LeftFootPosition.dz  );   // 22
    fillFileWithSubsamplingAndClose(aof,m_prevLeftFootdPos,vec_db);
    
    prefix= m_TestName + "LeftFootddPos";
    prepareFile(aof,prefix);
    vec_db[0] = filterprecision(m_OneStep.LeftFootPosition.ddx  );    // 23
    vec_db[1] =  filterprecision(m_OneStep.LeftFootPosition.ddy  );    // 24
    vec_db[2] =filterprecision(m_OneStep.LeftFootPosition.ddz  );    // 25
    fillFileWithSubsamplingAndClose(aof,m_prevLeftFootddPos,vec_db);
    
    prefix= m_TestName + "LeftFootOrientation";
    prepareFile(aof,prefix);
    vec_db[0] = filterprecision(m_OneStep.LeftFootPosition.theta );   // 26
    vec_db[1] = filterprecision(m_OneStep.LeftFootPosition.omega  );  // 29
    vec_db[2] =filterprecision(m_OneStep.LeftFootPosition.omega2  ); // 30
    fillFileWithSubsamplingAndClose(aof,m_prevLeftFootOrientation,vec_db);

    prefix= m_TestName + "LeftFootdOrientation";
    prepareFile(aof,prefix);
    vec_db[0] = filterprecision(m_OneStep.LeftFootPosition.dtheta );
    vec_db[1] = 0.0; vec_db[2] =  0.0;  // 27
    fillFileWithSubsamplingAndClose(aof,m_prevLeftFootdOrientation,vec_db);

    prefix= m_TestName + "LeftFootddOrientation";
    prepareFile(aof,prefix);
    vec_db[0] = filterprecision(m_OneStep.LeftFootPosition.ddtheta );
    vec_db[1] = 0.0; vec_db[2] =  0.0;  // 27
    fillFileWithSubsamplingAndClose(aof,m_prevLeftFootddOrientation,vec_db);    
    
    prefix= m_TestName + "RightFootPos";
    prepareFile(aof,prefix);
    vec_db[0] = filterprecision(m_OneStep.RightFootPosition.x  );
    vec_db[1] = filterprecision(m_OneStep.RightFootPosition.y  );
    vec_db[2] = filterprecision(m_OneStep.RightFootPosition.z  );
    fillFileWithSubsamplingAndClose(aof,m_prevRightFootPos,vec_db);    
    
    prefix= m_TestName + "RightFootdPos";
    prepareFile(aof,prefix);
    vec_db[0] = filterprecision(m_OneStep.RightFootPosition.dx  );
    vec_db[1] = filterprecision(m_OneStep.RightFootPosition.dy  );
    vec_db[2] = filterprecision(m_OneStep.RightFootPosition.dz  );
    fillFileWithSubsamplingAndClose(aof,m_prevRightFootdPos,vec_db);        
    
    prefix= m_TestName + "RightFootddPos";
    prepareFile(aof,prefix);
    vec_db[0] = filterprecision(m_OneStep.RightFootPosition.ddx  );    
    vec_db[1] = filterprecision(m_OneStep.RightFootPosition.ddy  );    
    vec_db[2] = filterprecision(m_OneStep.RightFootPosition.ddz  );    
    fillFileWithSubsamplingAndClose(aof,m_prevRightFootddPos,vec_db);
    
    prefix= m_TestName + "RightFootOrientation";
    prepareFile(aof,prefix);
    vec_db[0] = filterprecision(m_OneStep.RightFootPosition.theta );   
    vec_db[1] = filterprecision(m_OneStep.RightFootPosition.omega  );  
    vec_db[2] = filterprecision(m_OneStep.RightFootPosition.omega2  ); 
    fillFileWithSubsamplingAndClose(aof,m_prevRightFootOrientation,vec_db);

    prefix= m_TestName + "RightFootdOrientation";
    prepareFile(aof,prefix);
    vec_db[0] = filterprecision(m_OneStep.RightFootPosition.dtheta );
    vec_db[1] = 0.0; vec_db[2] = 0.0; 
    fillFileWithSubsamplingAndClose(aof,m_prevRightFootdOrientation,vec_db);

    prefix= m_TestName + "RightFootddOrientation";
    prepareFile(aof,prefix);
    vec_db[0] = filterprecision(m_OneStep.RightFootPosition.ddtheta );
    vec_db[1] = 0.0; vec_db[2] = 0.0;
    fillFileWithSubsamplingAndClose(aof,m_prevRightFootddOrientation,vec_db);    

    analyticalInverseKinematics(m_CurrentConfiguration,
				m_CurrentVelocity,
				m_CurrentAcceleration);
    m_DebugPR->computeInverseDynamics(m_CurrentConfiguration,
				      m_CurrentVelocity,
				      m_CurrentAcceleration);
    Eigen::Vector3d zmpmb;
    m_DebugPR->zeroMomentumPoint(zmpmb);

    prefix= m_TestName + "ZMPMB";
    prepareFile(aof,prefix);
    vec_db[0] = filterprecision(zmpmb[0]);
    vec_db[1] = filterprecision(zmpmb[1]);
    vec_db[2] = filterprecision(zmpmb[2]);
    fillFileWithSubsamplingAndClose(aof,m_prevZMPMB,vec_db);    


  }
  
709
710
711
  void fillInDebugFiles()
  {
    TestObject::fillInDebugFiles();
712

713
    fillInTests();
714
    if(m_DebugFGPIFull)
715
      {
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
	analyticalInverseKinematics(m_CurrentConfiguration,
				    m_CurrentVelocity,
				    m_CurrentAcceleration);
	if(iteration==0)
	  {

	    //        cout << endl ;
	    //        cout << m_conf << endl ;
	    //        cout << m_HalfSitting << endl ;
	    //        cout << std::boolalpha << isHalfsitting << endl ;
	    //        assert(isHalfsitting);
	  }

	m_DebugPR->computeInverseDynamics(m_CurrentConfiguration,
					  m_CurrentVelocity,
					  m_CurrentAcceleration);
	Eigen::Vector3d com, dcom, ddcom;
	m_DebugPR->CenterOfMass(com, dcom, ddcom);
	createOpenHRPFiles();
	Eigen::Vector3d zmpmb;
	m_DebugPR->zeroMomentumPoint(zmpmb);
	m_err_zmp_x.push_back(zmpmb[0]-m_OneStep.ZMPTarget(0)) ;
	m_err_zmp_y.push_back(zmpmb[1]-m_OneStep.ZMPTarget(1)) ;

	++iteration;

	ofstream aof;
	string aFileName;
	aFileName = m_TestName;
	aFileName += "TestFGPIFull.dat";
	if (m_OneStep.NbOfIt==1)
	  {
	    aof.open(aFileName.c_str(),ofstream::out);
	  }
	resetfiles = 1;
	aof.open(aFileName.c_str(),ofstream::app);
	aof.precision(8);
	aof.setf(ios::scientific, ios::floatfield);
	aof << filterprecision(((double)m_OneStep.NbOfIt)*0.005 ) << " "   // 1
	    << filterprecision(m_OneStep.finalCOMPosition.x[0] ) << " "    // 2
	    << filterprecision(m_OneStep.finalCOMPosition.y[0] ) << " "    // 3
	    << filterprecision(m_OneStep.finalCOMPosition.z[0] ) << " "    // 4
	    << filterprecision(m_OneStep.finalCOMPosition.yaw[0] ) << " "  // 5
	    << filterprecision(m_OneStep.finalCOMPosition.x[1] ) << " "    // 6
	    << filterprecision(m_OneStep.finalCOMPosition.y[1] ) << " "    // 7
	    << filterprecision(m_OneStep.finalCOMPosition.z[1] ) << " "    // 8
	    << filterprecision(m_OneStep.finalCOMPosition.yaw[1] ) << " "  // 9
	    << filterprecision(m_OneStep.finalCOMPosition.x[2] ) << " "    // 10
	    << filterprecision(m_OneStep.finalCOMPosition.y[2] ) << " "    // 11
	    << filterprecision(m_OneStep.finalCOMPosition.z[2] ) << " "    // 12
	    << filterprecision(m_OneStep.finalCOMPosition.yaw[2] ) << " "  // 13
	    << filterprecision(m_OneStep.ZMPTarget(0) ) << " "             // 14
	    << filterprecision(m_OneStep.ZMPTarget(1) ) << " "             // 15
	    << filterprecision(m_OneStep.ZMPTarget(2) ) << " "             // 16
	    << filterprecision(m_OneStep.LeftFootPosition.x  ) << " "      // 17
	    << filterprecision(m_OneStep.LeftFootPosition.y  ) << " "      // 18
	    << filterprecision(m_OneStep.LeftFootPosition.z  ) << " "      // 19
	    << filterprecision(m_OneStep.LeftFootPosition.dx  ) << " "     // 20
	    << filterprecision(m_OneStep.LeftFootPosition.dy  ) << " "     // 21
	    << filterprecision(m_OneStep.LeftFootPosition.dz  ) << " "     // 22
	    << filterprecision(m_OneStep.LeftFootPosition.ddx  ) << " "    // 23
	    << filterprecision(m_OneStep.LeftFootPosition.ddy  ) << " "    // 24
	    << filterprecision(m_OneStep.LeftFootPosition.ddz  ) << " "    // 25
	    << filterprecision(m_OneStep.LeftFootPosition.theta ) << " "   // 26
	    << filterprecision(m_OneStep.LeftFootPosition.dtheta ) << " "  // 27
	    << filterprecision(m_OneStep.LeftFootPosition.ddtheta ) << " " // 28
	    << filterprecision(m_OneStep.LeftFootPosition.omega  ) << " "  // 29
	    << filterprecision(m_OneStep.LeftFootPosition.omega2  ) << " " // 30
	    << filterprecision(m_OneStep.RightFootPosition.x ) << " "      // 31
	    << filterprecision(m_OneStep.RightFootPosition.y ) << " "      // 32
	    << filterprecision(m_OneStep.RightFootPosition.z ) << " "      // 33
	    << filterprecision(m_OneStep.RightFootPosition.dx ) << " "     // 34
	    << filterprecision(m_OneStep.RightFootPosition.dy ) << " "     // 35
	    << filterprecision(m_OneStep.RightFootPosition.dz ) << " "     // 36
	    << filterprecision(m_OneStep.RightFootPosition.ddx ) << " "    // 37
	    << filterprecision(m_OneStep.RightFootPosition.ddy ) << " "    // 38
	    << filterprecision(m_OneStep.RightFootPosition.ddz ) << " "    // 39
	    << filterprecision(m_OneStep.RightFootPosition.theta ) << " "  // 40
	    << filterprecision(m_OneStep.RightFootPosition.dtheta ) << " " // 41
	    << filterprecision(m_OneStep.RightFootPosition.ddtheta ) << " "// 42
	    << filterprecision(m_OneStep.RightFootPosition.omega  ) << " " // 43
	    << filterprecision(m_OneStep.RightFootPosition.omega2  ) << " "// 44
	    << filterprecision(zmpmb[0]) << " "                            // 45
	    << filterprecision(zmpmb[1]) << " "                            // 46
	    << filterprecision(zmpmb[2]) << " "                           ;// 47
	for(unsigned int k = 0 ; k < m_conf.size() ; k++){ // 48-53 -> 54-83
	  aof << filterprecision( m_conf(k) ) << " "  ;
	}
	for(unsigned int k = 0 ; k < m_vel.size() ; k++){ // 84-89 -> 90-118
	  aof << filterprecision( m_vel(k) ) << " "  ;
	}
	for(unsigned int k = 0 ; k < m_acc.size() ; k++){ // 119-125 -> 125-155
	  aof << filterprecision( m_acc(k) ) << " "  ;
	}
	aof << endl;
	aof.close();
812
      }
813
  }
814

815
816
817
818
  void createFullEventsForHRP2()
  {
    ODEBUG3("createFullEventsForHRP2");
    localEvent events[8] =
819
      {
820
821
822
823
824
825
826
827
828
829
830
831
	{1*200,&TestObject::walkForwardSlow},
	{10*200,&TestObject::walkForward2m_s},
	{20*200,&TestObject::walkSidewards2m_s},
	{30*200,&TestObject::walkX05Y04},
	{40*200,&TestObject::startTurningRight2},
	{50*200,&TestObject::walkOnSpot},
	{66*200,&TestObject::stop},
	{76*200,&TestObject::stopOnLineWalking}
      };

    if (m_setOfLocalEvents!=0)
      m_setOfLocalEvents->initVecOfLocalEvents(events,8);
832
833
  }

834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
  void createSimpleEventsForHRP2()
  {
    localEvent events[2] =
      {
	{1*200,&TestObject::walkOnSpot},	
	{10*200,&TestObject::stop},
      };
    
    if (m_setOfLocalEvents!=0)
      m_setOfLocalEvents->initVecOfLocalEvents(events,2);
  }

  
  
  void startHRP2OnLineWalking(PatternGeneratorInterface &aPGI)
849
850
851
852
853
854
855
856
857
  {
    CommonInitialization(aPGI);

    {
      istringstream strm2(":SetAlgoForZmpTrajectory Naveau");
      aPGI.ParseCmd(strm2);

    }
    {
858
859
      //istringstream strm2(":singlesupporttime 1.4");
      istringstream strm2(":singlesupporttime 0.7");
860
861
862
      aPGI.ParseCmd(strm2);
    }
    {
863
864
      //istringstream strm2(":doublesupporttime 0.2");
      istringstream strm2(":doublesupporttime 0.1");
865
866
867
868
869
870
871
872
873
874
875
      aPGI.ParseCmd(strm2);
    }
    {
      istringstream strm2(":NaveauOnline");
      aPGI.ParseCmd(strm2);
    }
    {
      istringstream strm2(":numberstepsbeforestop 2");
      aPGI.ParseCmd(strm2);
    }
    {
876
      istringstream strm2(":setfeetconstraint XY 0.095 0.055");
877
878
      m_PGI->ParseCmd(strm2);
    }
879
880
881
882
883
    {
      istringstream strm2(":stepheight 0.05");
      m_PGI->ParseCmd(strm2);
    }

884
885
886
887
888
    {
      istringstream strm2(":deleteallobstacles");
      m_PGI->ParseCmd(strm2);
    }

889
    {
890
891
      //istringstream strm2(":feedBackControl true");
      istringstream strm2(":feedBackControl false");
892
893
894
      m_PGI->ParseCmd(strm2);
    }

mnaveau's avatar
mnaveau committed
895
    {
896
897
      //istringstream strm2(":useDynamicFilter true");
      istringstream strm2(":useDynamicFilter false");
mnaveau's avatar
mnaveau committed
898
899
      m_PGI->ParseCmd(strm2);
    }
900

901
  }
902

903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
  void startTalosOnLineWalking(PatternGeneratorInterface &aPGI)
  {
    CommonInitialization(aPGI);

    {
      istringstream strm2(":setDSFeetDistance 0.162");
      m_PGI->ParseCmd(strm2);
    }
    
    {
      istringstream strm2(":SetAlgoForZmpTrajectory Naveau");
      aPGI.ParseCmd(strm2);

    }
    {
      //istringstream strm2(":singlesupporttime 1.4");
      istringstream strm2(":singlesupporttime 0.7");
      aPGI.ParseCmd(strm2);
    }
    {
      //istringstream strm2(":doublesupporttime 0.2");
      istringstream strm2(":doublesupporttime 0.1");
      aPGI.ParseCmd(strm2);
    }
    {
      istringstream strm2(":NaveauOnline");
      aPGI.ParseCmd(strm2);
    }
    {
      istringstream strm2(":numberstepsbeforestop 2");
      aPGI.ParseCmd(strm2);
    }
    {
      istringstream strm2(":setfeetconstraint XY 0.091 0.0489");
      m_PGI->ParseCmd(strm2);
    }
    {
      istringstream strm2(":stepheight 0.05");
      m_PGI->ParseCmd(strm2);
    }

    {
      istringstream strm2(":deleteallobstacles");
      m_PGI->ParseCmd(strm2);
    }

    {
      //istringstream strm2(":feedBackControl true");
      istringstream strm2(":feedBackControl false");
      m_PGI->ParseCmd(strm2);
    }
954

955
956
957
958
959
    {
      //istringstream strm2(":useDynamicFilter true");
      istringstream strm2(":useDynamicFilter false");
      m_PGI->ParseCmd(strm2);
    }
960

961

962
963
964
965
  }

  void chooseTestProfile()
  {
966
967
    ODEBUG3("ROBOT:" << m_PR->getName() <<
	    " Profile: " << m_TestProfile);
968
    switch(m_TestProfile)
969
970
      {
      
971
      case PROFIL_NAVEAU:
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
	createFullEventsForHRP2();
	if (m_PR->getName()=="hrp2_14_reduced")
	  startHRP2OnLineWalking(*m_PGI);
	else if (m_PR->getName()=="talos")
	  startTalosOnLineWalking(*m_PGI);
	else
	  throw("No valid robot");
        break;
	
      case PROFIL_SIMPLE_NAVEAU:
	createSimpleEventsForHRP2();
	if (m_PR->getName()=="hrp2_14_reduced")
	  startHRP2OnLineWalking(*m_PGI);
	else if (m_PR->getName()=="talos")
	  startTalosOnLineWalking(*m_PGI);
	else
	  throw("No valid robot");
989
        break;
990
	
991
992
993
      default:
        throw("No correct test profile");
        break;
994
      }
995
996
997
998
  }

  void generateEventOnLineWalking()
  {
999
1000
    if (m_setOfLocalEvents!=0)
      m_setOfLocalEvents->evaluateEvents(m_OneStep,*this);
For faster browsing, not all history is shown. View entire blame