TestNaveau2015.cpp 22.5 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
43
#include "pinocchio/multibody/parser/urdf.hpp"
#include "pinocchio/multibody/parser/srdf.hpp"
44

45
using namespace std;
46
47
using namespace PatternGeneratorJRL;
using namespace::PatternGeneratorJRL::TestSuite;
48
49

enum Profiles_t {
50
  PROFIL_NAVEAU // 1
51
52
};

53
// Class TestNaveau2015
54
55
56
57
58
class TestNaveau2015: public TestObject
{

private:
  int resetfiles ;
59
  bool m_DebugFGPIFull ;
60
61
62
63
64
65
66
  ComAndFootRealizationByGeometry * ComAndFootRealization_ ;
  SimplePluginManager * SPM_ ;
  vector<double> m_err_zmp_x, m_err_zmp_y;
  MAL_VECTOR_TYPE(double) m_conf;
  MAL_VECTOR_TYPE(double) m_vel ;
  MAL_VECTOR_TYPE(double) m_acc ;
  int iteration;
67
68
69
70
  std::vector<se3::JointIndex> m_leftLeg  ;
  std::vector<se3::JointIndex> m_rightLeg ;
  std::vector<se3::JointIndex> m_leftArm  ;
  std::vector<se3::JointIndex> m_rightArm ;
71
72
73
74
75
76
77

public:
  TestNaveau2015(int argc, char *argv[], string &aString, int TestProfile):
    TestObject(argc,argv,aString)
  {
    m_TestProfile = TestProfile;
    resetfiles=0;
78
    m_DebugFGPIFull=true;
79
    m_DebugFGPI=true;
80
81
82
83
84
    ComAndFootRealization_ = NULL;
    SPM_ = NULL ;
    m_err_zmp_x.clear();
    m_err_zmp_y.clear();
    iteration=0;
85
86
87
88
    m_leftLeg .clear();
    m_rightLeg.clear();
    m_leftArm .clear();
    m_rightArm.clear();
89
90
91
92
  }

  ~TestNaveau2015()
  {
93
94
95
96
97
98
99
100
101
102
    if(ComAndFootRealization_!=NULL)
    {
      delete ComAndFootRealization_ ;
      ComAndFootRealization_ = NULL;
    }
    if(SPM_!=NULL)
    {
      delete SPM_ ;
      SPM_ = NULL;
    }
103
104
  }

105
  typedef void (TestObject:: * localeventHandler_t)(PatternGeneratorInterface &);
106
107
108
109
110
111
112

  struct localEvent
  {
    unsigned time;
    localeventHandler_t Handler ;
  };

113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
  bool doTest(std::ostream &os)
  {
    TestObject::doTest(os);
    ComputeAndDisplayZMPStatistic();
  }

  bool init()
  {
    if(!TestObject::init())
      return false;
    SPM_ = new SimplePluginManager();
    ComAndFootRealization_ = new ComAndFootRealizationByGeometry(
          (PatternGeneratorInterfacePrivate*)SPM_ );
    ComAndFootRealization_->setPinocchioRobot(m_PR);
    ComAndFootRealization_->SetStepStackHandler(new StepStackHandler(SPM_));
    ComAndFootRealization_->SetHeightOfTheCoM(0.814);
    ComAndFootRealization_->setSamplingPeriod(0.005);
    ComAndFootRealization_->Initialization();

    MAL_VECTOR_DIM(waist,double,6);
    for (int i = 0 ; i < 6 ; ++i )
    {
      waist(i) = 0;
    }
    MAL_S3_VECTOR(lStartingCOMState,double);

    lStartingCOMState(0) = m_OneStep.finalCOMPosition.x[0] ;
    lStartingCOMState(1) = m_OneStep.finalCOMPosition.y[0] ;
    lStartingCOMState(2) = m_OneStep.finalCOMPosition.z[0] ;
    ComAndFootRealization_->setSamplingPeriod(0.005);
    ComAndFootRealization_->Initialization();
    ComAndFootRealization_->InitializationCoM(m_HalfSitting,lStartingCOMState,
                                              waist,
                                              m_OneStep.LeftFootPosition, m_OneStep.RightFootPosition);
    m_conf = m_CurrentConfiguration ;
    m_vel  = m_CurrentVelocity ;
    m_acc  = m_CurrentAcceleration ;
    {
      istringstream strm2(":setfeetconstraint XY 0.09 0.04");
      m_PGI->ParseCmd(strm2);
    }
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
    m_leftLeg =
        m_PR->jointsBetween(m_PR->waist(),m_PR->leftFoot()->associatedAnkle);
    m_rightLeg =
        m_PR->jointsBetween(m_PR->waist(),m_PR->rightFoot()->associatedAnkle);
    m_leftArm =
        m_PR->jointsBetween(m_PR->chest(),m_PR->leftWrist());
    m_rightArm =
        m_PR->jointsBetween(m_PR->chest(),m_PR->rightWrist());

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

    se3::JointModelVector & ActuatedJoints = m_PR->getActuatedJoints();
    for(unsigned i=0 ; i <m_leftLeg.size() ; ++i)
      m_leftLeg[i] = se3::idx_q(ActuatedJoints[m_leftLeg[i]])-1;
    for(unsigned i=0 ; i <m_rightLeg.size() ; ++i)
      m_rightLeg[i] = se3::idx_q(ActuatedJoints[m_rightLeg[i]])-1;
    for(unsigned i=0 ; i <m_leftArm.size() ; ++i)
      m_leftArm[i] = se3::idx_q(ActuatedJoints[m_leftArm[i]])-1;
    for(unsigned i=0 ; i <m_rightArm.size() ; ++i)
      m_rightArm[i] = se3::idx_q(ActuatedJoints[m_rightArm[i]])-1;

176
177
178
179
    return true ;
  }

protected:
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197

  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)
    {
      double abs_value = sqrt(vec[i]*vec[i]) ;
      if( abs_value > max_abs)
        max_abs = abs_value ;

      total += abs_value ;
    }
    avg = total/vec.size() ;
    return ;
  }

198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
  void ComputeAndDisplayZMPStatistic()
  {
    cout << "Statistic for Dzmp in x : " << endl ;
    double moy_delta_zmp_x = 0.0 ;
    double max_abs_err_x = 0.0 ;
    ComputeStat(m_err_zmp_x,moy_delta_zmp_x,max_abs_err_x);
    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 ;
    ComputeStat(m_err_zmp_y,moy_delta_zmp_y,max_abs_err_y);
    cout << "average : " << moy_delta_zmp_y << endl ;
    cout << "maxx error : " << max_abs_err_y << endl ;
    return ;
  }

  void analyticalInverseKinematics(MAL_VECTOR_TYPE(double) & conf,
                                   MAL_VECTOR_TYPE(double) & vel,
                                   MAL_VECTOR_TYPE(double) & acc)
  {
    /// \brief calculate, from the CoM of computed by the preview control,
    ///    the corresponding articular position, velocity and acceleration
    /// ------------------------------------------------------------------
    MAL_VECTOR_DIM(aCOMState,double,6);
    MAL_VECTOR_DIM(aCOMSpeed,double,6);
    MAL_VECTOR_DIM(aCOMAcc,double,6);
    MAL_VECTOR_DIM(aLeftFootPosition,double,5);
    MAL_VECTOR_DIM(aRightFootPosition,double,5);

    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;
    ComAndFootRealization_->setSamplingPeriod(0.005);
    ComAndFootRealization_->ComputePostureForGivenCoMAndFeetPosture(
          aCOMState, aCOMSpeed, aCOMAcc, aLeftFootPosition, aRightFootPosition,
          conf, vel, acc, iteration, 1);
    ++iteration;
266
267
268

    conf(m_leftArm.back()+1) = 10.0*M_PI/180.0;
    conf(m_rightArm.back()+1) = 10.0*M_PI/180.0;
269
  }
270

271
  MAL_VECTOR_TYPE(double) parseFromURDFtoOpenHRPIndex()
272
273
274
  {
    MAL_VECTOR_TYPE(double) conf = m_conf;
    MAL_VECTOR_FILL(conf,0.0);
275
276
277

    for(unsigned int i = 0 ; i < 6 ; i++)
      conf(i) = m_conf(i);
278
279
280
281
282
283
284
285
    unsigned index=6;
    //RLEG
    for(unsigned int i = 0 ; i < m_rightLeg.size() ; i++)
      conf(index+i) = m_conf(m_rightLeg[i]);
    index+=m_rightLeg.size();
    //LLEG
    for(unsigned int i = 0 ; i < m_leftLeg.size() ; i++)
      conf(index+i) = m_conf(m_leftLeg[i]);
286
    index+=m_leftLeg.size();
287
288
289
290
291
292
293
294
295
296
    //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++)
297
      conf(index+i) = m_HalfSitting(m_rightArm[i]-6);
298
    index+=m_rightArm.size();
299
300
    conf(index) = 10*M_PI/180;
    ++index;
301
302
    //LARM
    for(unsigned int i = 0 ; i < m_leftArm.size() ; i++)
303
304
305
      conf(index+i) = m_HalfSitting(m_leftArm[i]-6);
    index+=m_leftArm.size();
    conf(index) = 10*M_PI/180;
306
307
308
309

    return conf ;
  }

310
  void createOpenHRPFiles()
311
  {
312
313
    /// \brief Create file .hip .pos .zmp
    /// ---------------------------------
314
    MAL_VECTOR_TYPE(double) conf = parseFromURDFtoOpenHRPIndex();
315
    ofstream aof ;
316
317
318
319
320
    string aPosFileName = /*"/tmp/" +*/ m_TestName + ".pos" ;
    string aZMPFileName = /*"/tmp/" +*/ m_TestName + ".zmp" ;
    string aWaistFileName = /*"/tmp/" +*/ m_TestName + ".waist" ;
    string aHipFileName = /*"/tmp/" +*/ m_TestName + ".hip" ;
    if ( iteration == 1 )
321
    {
322
323
324
325
326
327
328
      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);
329
330
      aof.close();
    }
331
332

    aof.open(aPosFileName.c_str(),ofstream::app);
333
334
    aof.precision(8);
    aof.setf(ios::scientific, ios::floatfield);
335
    aof << filterprecision( (double)(iteration-1) * 0.005 ) << " "  ;// 1
336
    for(unsigned i=6 ; i<MAL_VECTOR_SIZE(conf) ; ++i)
337
      aof << filterprecision( conf(i) ) << " "  ;                    // 2-30
338
    for(unsigned i=0 ; i<9 ; ++i)
339
340
      aof << filterprecision( 0.0 ) << " "  ;                        // 31-40
    aof << 0.0  << endl ;                                            // 41
341
342
    aof.close();

343
     aof.open(aWaistFileName.c_str(),ofstream::app);
344
345
    aof.precision(8);
    aof.setf(ios::scientific, ios::floatfield);
346
    aof << filterprecision( (double)(iteration-1) * 0.005 ) << " "  ;     // 1
347
348
349
350
351
352
    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();

353
354

    aof.open(aHipFileName.c_str(),ofstream::app);
355
356
    aof.precision(8);
    aof.setf(ios::scientific, ios::floatfield);
357
358
    aof << filterprecision( (double)(iteration-1) * 0.005 ) << " "  ;     // 1
    aof << filterprecision( m_OneStep.finalCOMPosition.roll[0]) << " "  ; // 2
359
360
361
362
363
    aof << filterprecision( m_OneStep.finalCOMPosition.pitch[0]) << " "  ;// 3
    aof << filterprecision( m_OneStep.finalCOMPosition.yaw[0]) ;          // 4
    aof << endl ;
    aof.close();

364

365
366
367
368
369
370
    FootAbsolutePosition aSupportState;
    if (m_OneStep.LeftFootPosition.stepType < 0 )
      aSupportState = m_OneStep.LeftFootPosition ;
    else
      aSupportState = m_OneStep.RightFootPosition ;

371
    aof.open(aZMPFileName.c_str(),ofstream::app);
372
373
    aof.precision(8);
    aof.setf(ios::scientific, ios::floatfield);
374
375
376
377
    aof << filterprecision( (double)(iteration-1) * 0.005 ) << " "  ;   // 1
    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
378
379
380
381
    aof << endl ;
    aof.close();

    iteration++;
382
383
384
385
386
  }

  void prepareDebugFiles()
  {
    TestObject::prepareDebugFiles() ;
387
    if (m_DebugFGPIFull)
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
    {
      ofstream aof;
      string aFileName;
      aFileName = m_TestName;
      aFileName += "TestFGPIFull.dat";
      if (m_OneStep.NbOfIt==1)
      {
        aof.open(aFileName.c_str(),ofstream::out);
      }
    }
  }

  void fillInDebugFiles()
  {
    TestObject::fillInDebugFiles();

404
405
    if(m_DebugFGPIFull)
    {
406
407

      analyticalInverseKinematics(m_conf,m_vel,m_acc);
408
409
410
411
412
413
414
415
416
417
418
419
      if(iteration==1)
      {
        bool isHalfsitting = true ;
        for(unsigned i=0 ; i<MAL_VECTOR_SIZE(m_HalfSitting) ; ++i)
        {
          isHalfsitting &= abs(m_conf(6+i)-m_HalfSitting(i))<1e-3 ;
          if(!(abs(m_conf(6+i)-m_HalfSitting(i))<1e-3))
            cout << i << " " ;
        }
        cout << endl ;
        cout << m_conf << endl ;
        cout << m_HalfSitting << endl ;
420
421
        cout << std::boolalpha << isHalfsitting << endl ;
        //assert(isHalfsitting);
422
      }
423
424
425
426
427
428
429
430
431
432

      se3::JointModelVector & ActuatedJoints = m_DebugPR->getActuatedJoints();
      se3::JointIndex leftHand = se3::idx_q(
            ActuatedJoints[m_DebugPR->leftWrist()+1]);
      se3::JointIndex rightHand = se3::idx_q(
            ActuatedJoints[m_DebugPR->rightWrist()+1]);
//      m_conf(leftHand) = 0.174532925 ;     // gripper openning
//      m_conf(rightHand)= 0.174532925 ;     // gripper openning

      m_DebugPR->computeInverseDynamics(m_conf,m_vel,m_acc);
433
      createOpenHRPFiles();
434
435
436
437
      MAL_S3_VECTOR(zmpmb,double);
      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)) ;
438
439
440
441
442
443
444
445
446
447
448
449
450

      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);
451
452
453
454
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
      aof << filterprecision(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
494
495
496
497
          << filterprecision(m_OneStep.RightFootPosition.omega2  ) << " "// 44
          << filterprecision(zmpmb[0]) << " "                            // 45
          << filterprecision(zmpmb[1]) << " "                            // 46
          << filterprecision(zmpmb[2]) << " "                           ;// 47
498
      for(unsigned int k = 0 ; k < m_CurrentConfiguration.size() ; k++){ // 48-53 -> 54-83
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
        aof << filterprecision( m_CurrentConfiguration(k) ) << " "  ;
      }
      aof << endl;
      aof.close();
    }
  }

  void startOnLineWalking(PatternGeneratorInterface &aPGI)
  {
    CommonInitialization(aPGI);

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

    }
    {
      istringstream strm2(":singlesupporttime 0.7");
      aPGI.ParseCmd(strm2);
    }
    {
      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.09 0.04");
      m_PGI->ParseCmd(strm2);
    }
535
536
537
538
539
    {
      istringstream strm2(":stepheight 0.05");
      m_PGI->ParseCmd(strm2);
    }

540
541
542
543
544
    {
      istringstream strm2(":deleteallobstacles");
      m_PGI->ParseCmd(strm2);
    }

545
    {
546
547
      istringstream strm2(":feedBackControl true");
      //istringstream strm2(":feedBackControl false");
548
549
550
      m_PGI->ParseCmd(strm2);
    }

551
//    {
552
553
554
555
556
557
//      istringstream strm2(":addoneobstacle 9.0 0.5 0.23");
//      m_PGI->ParseCmd(strm2);
//    }


//    {
558
//      istringstream strm2(":addoneobstacle 1.0 0.5 0.23");
559
560
561
//      m_PGI->ParseCmd(strm2);
//    }

562
563
564
565
//    {
//      istringstream strm2(":addoneobstacle 1.5 -0.0 0.23");
//      m_PGI->ParseCmd(strm2);
//    }
566

567

568
569
570
571
//    {
//      istringstream strm2(":updateoneobstacle 1 1.5 -1.5 0.23");
//      m_PGI->ParseCmd(strm2);
//    }
572
573
574
575
576
577
578
579
  }

  void chooseTestProfile()
  {

    switch(m_TestProfile)
    {

580
      case PROFIL_NAVEAU:
581
582
583
584
585
586
587
588
589
590
        startOnLineWalking(*m_PGI);
        break;
      default:
        throw("No correct test profile");
        break;
    }
  }

  void generateEventOnLineWalking()
  {
591
592
593
    #define localNbOfEvents 20
    struct localEvent events [localNbOfEvents] =
    {
594
      //{ 1,&TestObject::walkForward2m_s},
595
      { 5,&TestObject::walkOnSpot},
596
597
598
599
600
601
      //{10*200,&TestObject::walkForward2m_s},
      //{15*200,&TestObject::walkForward3m_s},
      //{20*200,&TestObject::walkForward2m_s},
      //{25*200,&TestObject::walkForward2m_s},
      //{30*200,&TestObject::walkSidewards1m_s},
      //{35*200,&TestObject::walkSidewards2m_s},
602
603
      {20*200,&TestObject::stop},
      {30*200,&TestObject::stopOnLineWalking}
604
605
606
    };
    // Test when triggering event.
    for(unsigned int i=0;i<localNbOfEvents;i++)
607
    {
608
609
610
611
612
      if ( m_OneStep.NbOfIt==events[i].time)
      {
        ODEBUG3("********* GENERATE EVENT EMS ***********");
        (this->*(events[i].Handler))(*m_PGI);
      }
613
    }
614
615
616
617
618
619
620
621
622
623
//    if(m_OneStep.NbOfIt>=0*200)
//    {
//      ostringstream oss ;
//      oss << ":perturbationforce "
//          << 0.0 << " "
//          << 0.0 << " "
//          << " 0.0";
//      istringstream strm (oss.str()) ;
//      m_PGI->ParseCmd(strm);
//    }
624
  }
625

626
627
628
  void generateEvent()
  {
    switch(m_TestProfile){
629
      case PROFIL_NAVEAU:
630
631
632
633
634
635
636
637
638
639
640
        generateEventOnLineWalking();
        break;
      default:
        break;
    }
  }

};

int PerformTests(int argc, char *argv[])
{
641
#define NB_PROFILES 1
642
  std::string TestNames[NB_PROFILES] = {"TestNaveau2015"};
643
  int TestProfiles[NB_PROFILES] = {PROFIL_NAVEAU};
644

645

646
647
  for (unsigned int i=0;i<NB_PROFILES;i++){
    TestNaveau2015 aTN2015(argc,argv,TestNames[i],TestProfiles[i]);
mnaveau's avatar
mnaveau committed
648
649
650
651
652
653
654
    if(!aTN2015.init())
    {
      cout << "pb on init" << endl;
      return -1;
    }
    try
    {
655
656
657
658
659
660
661
662
663
664
665
      if (!aTN2015.doTest(std::cout)){
        cout << "Failed test " << i << endl;
        return -1;
      }
      else
        cout << "Passed test " << i << endl;
    }
    catch (const char * astr){
      cerr << "Failed on following error " << astr << std::endl;
      return -1; }
  }
666

667
668
669
670
671
672
673
  return 0;
}

int main(int argc, char *argv[])
{
  try
  {
674
    return PerformTests(argc,argv);
675
676
677
678
679
680
681
  }
  catch (const std::string& msg)
  {
    std::cerr << msg << std::endl;
  }
  return 1;
}