dynamic.cpp 31.9 KB
Newer Older
Thomas Moulard's avatar
Thomas Moulard committed
1
2
3
4
/*
 * Copyright 2010,
 * François Bleibel,
 * Olivier Stasse,
Francois Bleibel's avatar
Francois Bleibel committed
5
 *
Thomas Moulard's avatar
Thomas Moulard committed
6
 * CNRS/AIST
Francois Bleibel's avatar
Francois Bleibel committed
7
 *
Thomas Moulard's avatar
Thomas Moulard committed
8
9
10
11
12
13
14
15
16
17
18
19
20
 * This file is part of sot-dynamic.
 * sot-dynamic 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.
 * sot-dynamic 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 Lesser General Public License for more details.  You should
 * have received a copy of the GNU Lesser General Public License along
 * with sot-dynamic.  If not, see <http://www.gnu.org/licenses/>.
 */

Thomas Moulard's avatar
Thomas Moulard committed
21
#include <jrl/mal/matrixabstractlayer.hh>
Francois Bleibel's avatar
Francois Bleibel committed
22
23
24
25

#include <sot-dynamic/dynamic.h>
#include <sot-core/debug.h>

Thomas Moulard's avatar
Thomas Moulard committed
26
27
#include <abstract-robot-dynamics/humanoid-dynamic-robot.hh>
#include <abstract-robot-dynamics/robot-dynamics-object-constructor.hh>
Francois Bleibel's avatar
Francois Bleibel committed
28
29
30

#include <dynamic-graph/factory.h>

31
32
#include "../src/dynamic-command.h"

Francois Bleibel's avatar
Francois Bleibel committed
33
34
35
36
37
38
39
40
using namespace sot;
using namespace dynamicgraph;

DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(Dynamic,"Dynamic");

using namespace std;

Dynamic::
Thomas Moulard's avatar
Thomas Moulard committed
41
Dynamic( const std::string & name, bool build )
Francois Bleibel's avatar
Francois Bleibel committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
  :Entity(name)
  ,m_HDR(NULL)

  ,vrmlDirectory()
  ,vrmlMainFile()
  ,xmlSpecificityFile()
  ,xmlRankFile()

  ,init(false)

  ,jointPositionSIN(NULL,"sotDynamic("+name+")::input(vector)::position")
  ,freeFlyerPositionSIN(NULL,"sotDynamic("+name+")::input(vector)::ffposition")
  ,jointVelocitySIN(NULL,"sotDynamic("+name+")::input(vector)::velocity")
  ,freeFlyerVelocitySIN(NULL,"sotDynamic("+name+")::input(vector)::ffvelocity")
  ,jointAccelerationSIN(NULL,"sotDynamic("+name+")::input(vector)::acceleration")
  ,freeFlyerAccelerationSIN(NULL,"sotDynamic("+name+")::input(vector)::ffacceleration")

  ,firstSINTERN( boost::bind(&Dynamic::initNewtonEuler,this,_1,_2),
Thomas Moulard's avatar
Thomas Moulard committed
60
		 sotNOSIGNAL,"sotDynamic("+name+")::intern(dummy)::init" )
Francois Bleibel's avatar
Francois Bleibel committed
61
62
63
64
  ,newtonEulerSINTERN( boost::bind(&Dynamic::computeNewtonEuler,this,_1,_2),
		       firstSINTERN<<jointPositionSIN<<freeFlyerPositionSIN
		       <<jointVelocitySIN<<freeFlyerVelocitySIN
		       <<jointAccelerationSIN<<freeFlyerAccelerationSIN,
Thomas Moulard's avatar
Thomas Moulard committed
65
		       "sotDynamic("+name+")::intern(dummy)::newtoneuleur" )
Francois Bleibel's avatar
Francois Bleibel committed
66
67
68

  ,zmpSOUT( boost::bind(&Dynamic::computeZmp,this,_1,_2),
	    newtonEulerSINTERN,
Thomas Moulard's avatar
Thomas Moulard committed
69
	    "sotDynamic("+name+")::output(vector)::zmp" )
Francois Bleibel's avatar
Francois Bleibel committed
70
71
  ,JcomSOUT( boost::bind(&Dynamic::computeJcom,this,_1,_2),
	     newtonEulerSINTERN,
Thomas Moulard's avatar
Thomas Moulard committed
72
	     "sotDynamic("+name+")::output(matrix)::Jcom" )
Francois Bleibel's avatar
Francois Bleibel committed
73
74
  ,comSOUT( boost::bind(&Dynamic::computeCom,this,_1,_2),
	    newtonEulerSINTERN,
Thomas Moulard's avatar
Thomas Moulard committed
75
	    "sotDynamic("+name+")::output(vector)::com" )
Francois Bleibel's avatar
Francois Bleibel committed
76
77
  ,inertiaSOUT( boost::bind(&Dynamic::computeInertia,this,_1,_2),
		newtonEulerSINTERN,
Thomas Moulard's avatar
Thomas Moulard committed
78
		"sotDynamic("+name+")::output(matrix)::inertia" )
Francois Bleibel's avatar
Francois Bleibel committed
79
80
  ,footHeightSOUT( boost::bind(&Dynamic::computeFootHeight,this,_1,_2),
		   newtonEulerSINTERN,
Thomas Moulard's avatar
Thomas Moulard committed
81
		   "sotDynamic("+name+")::output(double)::footHeight" )
Francois Bleibel's avatar
Francois Bleibel committed
82
83
84

  ,upperJlSOUT( boost::bind(&Dynamic::getUpperJointLimits,this,_1,_2),
		sotNOSIGNAL,
Thomas Moulard's avatar
Thomas Moulard committed
85
		"sotDynamic("+name+")::output(vector)::upperJl" )
Francois Bleibel's avatar
Francois Bleibel committed
86
87
88

  ,lowerJlSOUT( boost::bind(&Dynamic::getLowerJointLimits,this,_1,_2),
		sotNOSIGNAL,
Thomas Moulard's avatar
Thomas Moulard committed
89
		"sotDynamic("+name+")::output(vector)::lowerJl" )
Francois Bleibel's avatar
Francois Bleibel committed
90
91
92
93
94

  ,inertiaRotorSOUT( "sotDynamic("+name+")::output(matrix)::inertiaRotor" )
  ,gearRatioSOUT( "sotDynamic("+name+")::output(matrix)::gearRatio" )
  ,inertiaRealSOUT( boost::bind(&Dynamic::computeInertiaReal,this,_1,_2),
		    inertiaSOUT << gearRatioSOUT << inertiaRotorSOUT,
Thomas Moulard's avatar
Thomas Moulard committed
95
		    "sotDynamic("+name+")::output(matrix)::inertiaReal" )
Francois Bleibel's avatar
Francois Bleibel committed
96
97
  ,MomentaSOUT( boost::bind(&Dynamic::computeMomenta,this,_1,_2),
		newtonEulerSINTERN,
Thomas Moulard's avatar
Thomas Moulard committed
98
		"sotDynamic("+name+")::output(vector)::momenta" )
Francois Bleibel's avatar
Francois Bleibel committed
99
100
  ,AngularMomentumSOUT( boost::bind(&Dynamic::computeAngularMomentum,this,_1,_2),
			newtonEulerSINTERN,
Thomas Moulard's avatar
Thomas Moulard committed
101
			"sotDynamic("+name+")::output(vector)::angularmomentum" )
Francois Bleibel's avatar
Francois Bleibel committed
102
103
104
105
106
107
108
109
110
111
112
{
  sotDEBUGIN(5);

  if( build ) buildModel();

  firstSINTERN.setDependencyType(TimeDependency<int>::BOOL_DEPENDENT);
  //DEBUG: Why =0? should be function. firstSINTERN.setConstant(0);

  signalRegistration( jointPositionSIN<<freeFlyerPositionSIN
		      <<jointVelocitySIN<<freeFlyerVelocitySIN
		      <<jointAccelerationSIN<<freeFlyerAccelerationSIN);
113
114
115
  signalRegistration( zmpSOUT<<comSOUT<<JcomSOUT<<footHeightSOUT);
	signalRegistration(upperJlSOUT<<lowerJlSOUT<<inertiaSOUT
			 <<inertiaRealSOUT << inertiaRotorSOUT << gearRatioSOUT );
Francois Bleibel's avatar
Francois Bleibel committed
116
117
  signalRegistration( MomentaSOUT << AngularMomentumSOUT );

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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
  //
  // Commands
  //
  std::string docstring;
  // setFiles
  docstring =
    "\n"
    "    Define files to parse in order to build the robot.\n"
    "\n"
    "      Takes as input 4 string:\n"
    "        - Directory containing main wrl file,\n"
    "        - name of wrl file,\n"
    "        - xml file containing humanoid specificities,\n"
    "        - xml file defining order of joints in configuration vector.\n"
    "\n";
  addCommand("setFiles",
	     new command::SetFiles(*this, docstring));
  // parse
  docstring =
    "\n"
    "    Parse files to build an instance ot robot.\n"
    "\n"
    "      Takes no argument.\n"
    "      Files are defined by command setFiles \n"
    "\n";
    addCommand("parse",
	       new command::Parse(*this, docstring));

    // CreateOpPoint
    docstring = "    \n"
      "    Create an operational point attached to a robot joint local frame.\n"
      "    \n"
      "      Takes 2 arguments: \n"
      "        - a string: name of the operational point,\n"
      "        - a string: name the joint, among (gaze, left-ankle, right ankle\n"
      "          , left-wrist, right-wrist, waist, chest).\n"
      "\n";
    addCommand("createOpPoint",
	       new command::CreateOpPoint(*this, docstring));

    // SetProperty
    docstring = "    \n"
      "    Set a property.\n"
      "    \n"
      "      Takes 2 arguments:\n"
      "        - a string: name of the property,\n"
      "        - a string: value of the property.\n"
      "    \n";
      addCommand("setProperty",
		 new command::SetProperty(*this, docstring));
Francois Bleibel's avatar
Francois Bleibel committed
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
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
  sotDEBUGOUT(5);
}

void Dynamic::
buildModel( void )
{
  sotDEBUGIN(5);

  djj::ObjectFactory aRobotDynamicsObjectConstructor;

  m_HDR = aRobotDynamicsObjectConstructor.createHumanoidDynamicRobot();

  sotDEBUGOUT(5);
}


Dynamic::
~Dynamic( void )
{
  sotDEBUGIN(5);
  if( 0!=m_HDR )
    {
      delete m_HDR;
      m_HDR = 0;
    }

  for(  std::list< SignalBase<int>* >::iterator iter = genericSignalRefs.begin();
	iter != genericSignalRefs.end();
	++iter )
    {
      SignalBase<int>* sigPtr = *iter;
      delete sigPtr;
    }

  sotDEBUGOUT(5);
  return;
}

/* --- CONFIG --------------------------------------------------------------- */
/* --- CONFIG --------------------------------------------------------------- */
/* --- CONFIG --------------------------------------------------------------- */
/* --- CONFIG --------------------------------------------------------------- */
void Dynamic::
setVrmlDirectory( const std::string& filename )
{
  vrmlDirectory = filename;
}
void Dynamic::
setVrmlMainFile( const std::string& filename )
{
  vrmlMainFile = filename;
}
void Dynamic::
setXmlSpecificityFile( const std::string& filename )
{
  xmlSpecificityFile = filename;
}
void Dynamic::
setXmlRankFile( const std::string& filename )
{
  xmlRankFile = filename;
}
void Dynamic::
parseConfigFiles( void )
{
  sotDEBUGIN(15);
  try
    {
      sotDEBUG(35) << "Parse the vrml."<<endl;
      string RobotFileName = vrmlDirectory+vrmlMainFile;
      djj::parseOpenHRPVRMLFile(*m_HDR,RobotFileName,xmlRankFile,xmlSpecificityFile);
    }
  catch( ... )
    { SOT_THROW ExceptionDynamic( ExceptionDynamic::DYNAMIC_JRL,
				     "Error while parsing." ); }
  //inertia.init( aHDMB );
  init = true;
  sotDEBUGOUT(15);
}

/* --- SIGNAL ACTIVATION ---------------------------------------------------- */
/* --- SIGNAL ACTIVATION ---------------------------------------------------- */
/* --- SIGNAL ACTIVATION ---------------------------------------------------- */
dg::SignalTimeDependent< ml::Matrix,int > & Dynamic::
252
createJacobianSignal( const std::string& signame, CjrlJoint* aJoint )
Francois Bleibel's avatar
Francois Bleibel committed
253
{
Thomas Moulard's avatar
Thomas Moulard committed
254
  dg::SignalTimeDependent< ml::Matrix,int > * sig
Francois Bleibel's avatar
Francois Bleibel committed
255
256
257
258
259
260
261
262
263
264
265
    = new dg::SignalTimeDependent< ml::Matrix,int >
    ( boost::bind(&Dynamic::computeGenericJacobian,this,aJoint,_1,_2),
      newtonEulerSINTERN,
      "sotDynamic("+name+")::output(matrix)::"+signame );

  genericSignalRefs.push_back( sig );
  signalRegistration( *sig );
  return *sig;
}

dg::SignalTimeDependent< ml::Matrix,int > & Dynamic::
266
createEndeffJacobianSignal( const std::string& signame, CjrlJoint* aJoint )
Francois Bleibel's avatar
Francois Bleibel committed
267
268
269
{
  sotDEBUGIN(15);

Thomas Moulard's avatar
Thomas Moulard committed
270
  dg::SignalTimeDependent< ml::Matrix,int > * sig
Francois Bleibel's avatar
Francois Bleibel committed
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
    = new dg::SignalTimeDependent< ml::Matrix,int >
    ( boost::bind(&Dynamic::computeGenericEndeffJacobian,this,aJoint,_1,_2),
      newtonEulerSINTERN,
      "sotDynamic("+name+")::output(matrix)::"+signame );

  genericSignalRefs.push_back( sig );
  signalRegistration( *sig );

  sotDEBUGOUT(15);
  return *sig;
}

void Dynamic::
destroyJacobianSignal( const std::string& signame )
{
  bool deletable = false;
  dg::SignalTimeDependent< ml::Matrix,int > * sig = & jacobiansSOUT( signame );
  for(  std::list< SignalBase<int>* >::iterator iter = genericSignalRefs.begin();
	iter != genericSignalRefs.end();
	++iter )
    {
      if( (*iter) == sig ) { genericSignalRefs.erase(iter); deletable = true; break; }
    }

  if(! deletable )
Thomas Moulard's avatar
Thomas Moulard committed
296
    {
Francois Bleibel's avatar
Francois Bleibel committed
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
      SOT_THROW ExceptionDynamic( ExceptionDynamic::CANT_DESTROY_SIGNAL,
				     "Cannot destroy signal",
				     " (while trying to remove generic jac. signal <%s>).",
				     signame.c_str() );
    }

  signalDeregistration( signame );

  delete sig;
}

/* --- POINT --- */
/* --- POINT --- */
/* --- POINT --- */

dg::SignalTimeDependent< MatrixHomogeneous,int >& Dynamic::
313
createPositionSignal( const std::string& signame, CjrlJoint* aJoint)
Francois Bleibel's avatar
Francois Bleibel committed
314
315
316
{
  sotDEBUGIN(15);

Thomas Moulard's avatar
Thomas Moulard committed
317
  dg::SignalTimeDependent< MatrixHomogeneous,int > * sig
Francois Bleibel's avatar
Francois Bleibel committed
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
    = new dg::SignalTimeDependent< MatrixHomogeneous,int >
    ( boost::bind(&Dynamic::computeGenericPosition,this,aJoint,_1,_2),
      newtonEulerSINTERN,
      "sotDynamic("+name+")::output(matrixHomo)::"+signame );

  genericSignalRefs.push_back( sig );
  signalRegistration( *sig );

  sotDEBUGOUT(15);
  return *sig;
}


void Dynamic::
destroyPositionSignal( const std::string& signame )
{
  bool deletable = false;
  dg::SignalTimeDependent< MatrixHomogeneous,int > * sig = & positionsSOUT( signame );
  for(  std::list< SignalBase<int>* >::iterator iter = genericSignalRefs.begin();
	iter != genericSignalRefs.end();
	++iter )
    {
      if( (*iter) == sig ) { genericSignalRefs.erase(iter); deletable = true; break; }
    }

  if(! deletable )
Thomas Moulard's avatar
Thomas Moulard committed
344
    {
Francois Bleibel's avatar
Francois Bleibel committed
345
346
347
348
349
350
351
352
353
354
355
      SOT_THROW ExceptionDynamic( ExceptionDynamic::CANT_DESTROY_SIGNAL,
				     "Cannot destroy signal",
				     " (while trying to remove generic pos. signal <%s>).",
				     signame.c_str() );
    }

  signalDeregistration( signame );

  delete sig;
}

356
357
358
359
360
/* --- VELOCITY --- */
/* --- VELOCITY --- */
/* --- VELOCITY --- */

SignalTimeDependent< ml::Vector,int >& Dynamic::
361
createVelocitySignal( const std::string& signame, CjrlJoint* aJoint )
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
{
  sotDEBUGIN(15);
  SignalTimeDependent< ml::Vector,int > * sig
    = new SignalTimeDependent< ml::Vector,int >
    ( boost::bind(&Dynamic::computeGenericVelocity,this,aJoint,_1,_2),
      newtonEulerSINTERN,
      "sotDynamic("+name+")::output(ml::Vector)::"+signame );
  genericSignalRefs.push_back( sig );
  signalRegistration( *sig );

  sotDEBUGOUT(15);
  return *sig;
}


void Dynamic::
destroyVelocitySignal( const std::string& signame )
{
  bool deletable = false;
  SignalTimeDependent< ml::Vector,int > * sig = & velocitiesSOUT( signame );
  for(  std::list< SignalBase<int>* >::iterator iter = genericSignalRefs.begin();
	iter != genericSignalRefs.end();
	++iter )
    {
      if( (*iter) == sig ) { genericSignalRefs.erase(iter); deletable = true; break; }
    }

  if(! deletable )
    {
      SOT_THROW ExceptionDynamic( ExceptionDynamic::CANT_DESTROY_SIGNAL,
				     "Cannot destroy signal",
				     " (while trying to remove generic pos. signal <%s>).",
				     signame.c_str() );
    }

  signalDeregistration( signame );

  delete sig;
}

Francois Bleibel's avatar
Francois Bleibel committed
402
403
404
405
406
/* --- ACCELERATION --- */
/* --- ACCELERATION --- */
/* --- ACCELERATION --- */

dg::SignalTimeDependent< ml::Vector,int >& Dynamic::
407
createAccelerationSignal( const std::string& signame, CjrlJoint* aJoint )
Francois Bleibel's avatar
Francois Bleibel committed
408
409
{
  sotDEBUGIN(15);
Thomas Moulard's avatar
Thomas Moulard committed
410
  dg::SignalTimeDependent< ml::Vector,int > * sig
Francois Bleibel's avatar
Francois Bleibel committed
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
    = new dg::SignalTimeDependent< ml::Vector,int >
    ( boost::bind(&Dynamic::computeGenericAcceleration,this,aJoint,_1,_2),
      newtonEulerSINTERN,
      "sotDynamic("+name+")::output(matrixHomo)::"+signame );

  genericSignalRefs.push_back( sig );
  signalRegistration( *sig );

  sotDEBUGOUT(15);
  return *sig;
}


void Dynamic::
destroyAccelerationSignal( const std::string& signame )
{
  bool deletable = false;
  dg::SignalTimeDependent< ml::Vector,int > * sig = & accelerationsSOUT( signame );
  for(  std::list< SignalBase<int>* >::iterator iter = genericSignalRefs.begin();
	iter != genericSignalRefs.end();
	++iter )
    {
      if( (*iter) == sig ) { genericSignalRefs.erase(iter); deletable = true; break; }
    }

  if(! deletable )
Thomas Moulard's avatar
Thomas Moulard committed
437
    {
Francois Bleibel's avatar
Francois Bleibel committed
438
439
440
441
442
443
444
445
446
447
448
449
450
451
      SOT_THROW ExceptionDynamic( ExceptionDynamic::CANT_DESTROY_SIGNAL,
				     "Cannot destroy signal",
				     " (while trying to remove generic acc signal <%s>).",
				     signame.c_str() );
    }

  signalDeregistration( signame );

  delete sig;
}
/* --- COMPUTE -------------------------------------------------------------- */
/* --- COMPUTE -------------------------------------------------------------- */
/* --- COMPUTE -------------------------------------------------------------- */

Thomas Moulard's avatar
Thomas Moulard committed
452
#include <jrl/mal/boostspecific.hh>
Francois Bleibel's avatar
Francois Bleibel committed
453
454
455

static void MAAL1_V3d_to_MAAL2( const vector3d& source,
				ml::Vector & res )
Thomas Moulard's avatar
Thomas Moulard committed
456
{
Francois Bleibel's avatar
Francois Bleibel committed
457
  sotDEBUG(5) << source <<endl;
Thomas Moulard's avatar
Thomas Moulard committed
458
459
460
  res(0) = source[0];
  res(1) = source[1];
  res(2) = source[2];
Francois Bleibel's avatar
Francois Bleibel committed
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
}

ml::Matrix& Dynamic::
computeGenericJacobian( CjrlJoint * aJoint,ml::Matrix& res,int time )
{
  sotDEBUGIN(25);
  newtonEulerSINTERN(time);

  aJoint->computeJacobianJointWrtConfig();
  res.initFromMotherLib(aJoint->jacobianJointWrtConfig());
  sotDEBUGOUT(25);

  return res;
}

ml::Matrix& Dynamic::
computeGenericEndeffJacobian( CjrlJoint * aJoint,ml::Matrix& res,int time )
{
  sotDEBUGIN(25);
  newtonEulerSINTERN(time);

  aJoint->computeJacobianJointWrtConfig();

  ml::Matrix J,V(6,6);
  J.initFromMotherLib(aJoint->jacobianJointWrtConfig());

  /* --- TODO --- */
  MatrixHomogeneous M;
  computeGenericPosition(aJoint,M,time);
  //M=M.inverse();

  for( int i=0;i<3;++i )
    for( int j=0;j<3;++j )
      {
	V(i,j)=M(j,i);
	V(i+3,j+3)=M(j,i);
	V(i+3,j)=0.;
	V(i,j+3)=0.;
      }

  sotDEBUG(25) << "0Jn = "<< J;
  sotDEBUG(25) << "V = "<< V;
  V.multiply(J,res);
  sotDEBUGOUT(25);

  return res;
}

MatrixHomogeneous& Dynamic::
computeGenericPosition( CjrlJoint * aJoint,MatrixHomogeneous& res,int time )
{
  sotDEBUGIN(25);
  newtonEulerSINTERN(time);
  const matrix4d & m4 = aJoint->currentTransformation();

  res.resize(4,4);
  for( int i=0;i<4;++i )
Thomas Moulard's avatar
Thomas Moulard committed
518
    for( int j=0;j<4;++j )
Francois Bleibel's avatar
Francois Bleibel committed
519
520
521
522
523
      res(i,j) = MAL_S4x4_MATRIX_ACCESS_I_J(m4,i,j);

  //  aJoint->computeJacobianJointWrtConfig();
  //res.initFromMotherLib(aJoint->jacobianJointWrtConfig());

524
  // adaptation to the new dynamic -- to be optimized
Francois Bleibel's avatar
Francois Bleibel committed
525
526
527
528
529
530
531
532
    matrix4d initialTr;
    initialTr = aJoint->initialPosition();
    MAL_S4x4_MATRIX_ACCESS_I_J(initialTr,0,3) = 0.0;
    MAL_S4x4_MATRIX_ACCESS_I_J(initialTr,1,3) = 0.0;
    MAL_S4x4_MATRIX_ACCESS_I_J(initialTr,2,3) = 0.0;

    matrix4d invrot;
    for(unsigned int i=0;i<3;i++)
533
534
535
536
537
538
539
540
541
542
      for(unsigned int j=0;j<3;j++)
        {
  	MAL_S4x4_MATRIX_ACCESS_I_J(invrot,i,j)=0.0;
  	for(unsigned int k=0;k<3;k++)
  	  {
  	    MAL_S4x4_MATRIX_ACCESS_I_J(invrot,i,j)+=
  	      MAL_S4x4_MATRIX_ACCESS_I_J(res,i,k) *
  	      MAL_S4x4_MATRIX_ACCESS_I_J(initialTr,j,k);
  	  }
        }
Francois Bleibel's avatar
Francois Bleibel committed
543
    for(unsigned int i=0;i<3;i++)
544
545
546
547
      for(unsigned int j=0;j<3;j++)
        MAL_S4x4_MATRIX_ACCESS_I_J(res,i,j) =
  	MAL_S4x4_MATRIX_ACCESS_I_J(invrot,i,j);
    //end of the adaptation
Francois Bleibel's avatar
Francois Bleibel committed
548

Thomas Moulard's avatar
Thomas Moulard committed
549

Francois Bleibel's avatar
Francois Bleibel committed
550
551
552
553
  sotDEBUGOUT(25);
  return res;
}

554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
ml::Vector& Dynamic::
computeGenericVelocity( CjrlJoint* j,ml::Vector& res,int time )
{
  sotDEBUGIN(25);
  newtonEulerSINTERN(time);
  CjrlRigidVelocity aRV = j->jointVelocity();
  vector3d al= aRV.linearVelocity();
  vector3d ar= aRV.rotationVelocity();

  res.resize(6);
  for( int i=0;i<3;++i )
    {
      res(i)=al(i);
      res(i+3)=ar(i);
    }

  sotDEBUGOUT(25);
  return res;
}

Francois Bleibel's avatar
Francois Bleibel committed
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
ml::Vector& Dynamic::
computeGenericAcceleration( CjrlJoint* j,ml::Vector& res,int time )
{
  sotDEBUGIN(25);
  newtonEulerSINTERN(time);
  CjrlRigidAcceleration aRA = j->jointAcceleration();
  vector3d al= aRA.linearAcceleration();
  vector3d ar= aRA.rotationAcceleration(); // TODO: Dont copy, reference.

  res.resize(6);
  for( int i=0;i<3;++i )
    {
      res(i)=al(i);
      res(i+3)=ar(i);
    }

  sotDEBUGOUT(25);
  return res;
}



ml::Vector& Dynamic::
computeZmp( ml::Vector& ZMPval,int time )
{
  if (ZMPval.size()!=3)
    ZMPval.resize(3);

  newtonEulerSINTERN(time);
  MAAL1_V3d_to_MAAL2(m_HDR->zeroMomentumPoint(),ZMPval);
  sotDEBUGOUT(25);
  return ZMPval;
}


ml::Vector& Dynamic::
computeMomenta(ml::Vector & Momenta, int time)
{
  vector3d LinearMomentum, AngularMomentum;

  if (Momenta.size()!=6)
    Momenta.resize(6);

  sotDEBUGIN(25);
  newtonEulerSINTERN(time);
  LinearMomentum = m_HDR->linearMomentumRobot();
  AngularMomentum = m_HDR->angularMomentumRobot();

  for(unsigned int i=0;i<3;i++)
    {
      Momenta(i)   = LinearMomentum(i);
      Momenta(i+3) = AngularMomentum(i);
    }

  sotDEBUGOUT(25) << "Momenta :" << Momenta ;
  return Momenta;
}

ml::Vector& Dynamic::
computeAngularMomentum(ml::Vector & Momenta, int time)
{
  vector3d  AngularMomentum;

  if (Momenta.size()!=3)
    Momenta.resize(3);

  sotDEBUGIN(25);
  newtonEulerSINTERN(time);
  AngularMomentum = m_HDR->angularMomentumRobot();

  for(unsigned int i=0;i<3;i++)
    {
      Momenta(i) = AngularMomentum(i);
    }

  sotDEBUGOUT(25) << "AngularMomenta :" << Momenta ;
  return Momenta;

}

ml::Matrix& Dynamic::
computeJcom( ml::Matrix& Jcom,int time )
{
  sotDEBUGIN(25);
  newtonEulerSINTERN(time);
Thomas Moulard's avatar
Thomas Moulard committed
659
660

  matrixNxP jacobian;
661
  jacobian.resize(3, m_HDR->numberDof());
Thomas Moulard's avatar
Thomas Moulard committed
662
663
664
  m_HDR->getJacobianCenterOfMass(*m_HDR->rootJoint(), jacobian);

  Jcom.initFromMotherLib(jacobian);
Francois Bleibel's avatar
Francois Bleibel committed
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
  sotDEBUGOUT(25);
  return Jcom;
}

ml::Vector& Dynamic::
computeCom( ml::Vector& com,int time )
{
  sotDEBUGIN(25);
  newtonEulerSINTERN(time);
  com.resize(3);
  MAAL1_V3d_to_MAAL2(m_HDR->positionCenterOfMass(),com);
  sotDEBUGOUT(25);
  return com;
}

ml::Matrix& Dynamic::
computeInertia( ml::Matrix& A,int time )
{
  sotDEBUGIN(25);
  newtonEulerSINTERN(time);

  m_HDR->computeInertiaMatrix();
  A.initFromMotherLib(m_HDR->inertiaMatrix());

  if( 1==debugInertia )
    {
      for( unsigned int i=0;i<18;++i )
	for( unsigned int j=0;j<36;++j )
Thomas Moulard's avatar
Thomas Moulard committed
693
	  if( i==j ) A(i,i)=1;
Francois Bleibel's avatar
Francois Bleibel committed
694
695
696
	  else {  A(i,j)=A(j,i)=0; }
      for( unsigned int i=20;i<22;++i )
	for( unsigned int j=0;j<36;++j )
Thomas Moulard's avatar
Thomas Moulard committed
697
	  if( i==j ) A(i,i)=1;
Francois Bleibel's avatar
Francois Bleibel committed
698
699
700
	  else {  A(i,j)=A(j,i)=0; }
      for( unsigned int i=28;i<36;++i )
	for( unsigned int j=0;j<36;++j )
Thomas Moulard's avatar
Thomas Moulard committed
701
	  if( i==j ) A(i,i)=1;
Francois Bleibel's avatar
Francois Bleibel committed
702
703
704
705
706
707
	  else {  A(i,j)=A(j,i)=0; }
    }
  else if( 2==debugInertia )
    {
      for( unsigned int i=0;i<18;++i )
	for( unsigned int j=0;j<36;++j )
Thomas Moulard's avatar
Thomas Moulard committed
708
	  if( i==j ) A(i,i)=1;
Francois Bleibel's avatar
Francois Bleibel committed
709
710
711
	  else {  A(i,j)=A(j,i)=0; }
      for( unsigned int i=20;i<22;++i )
	for( unsigned int j=0;j<36;++j )
Thomas Moulard's avatar
Thomas Moulard committed
712
	  if( i==j ) A(i,i)=1;
Francois Bleibel's avatar
Francois Bleibel committed
713
714
715
	  else {  A(i,j)=A(j,i)=0; }
      for( unsigned int i=28;i<29;++i )
	for( unsigned int j=0;j<36;++j )
Thomas Moulard's avatar
Thomas Moulard committed
716
	  if( i==j ) A(i,i)=1;
Francois Bleibel's avatar
Francois Bleibel committed
717
718
719
	  else {  A(i,j)=A(j,i)=0; }
      for( unsigned int i=35;i<36;++i )
	for( unsigned int j=0;j<36;++j )
Thomas Moulard's avatar
Thomas Moulard committed
720
	  if( i==j ) A(i,i)=1;
Francois Bleibel's avatar
Francois Bleibel committed
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
	  else {  A(i,j)=A(j,i)=0; }
    }

  sotDEBUGOUT(25);
  return A;
}

ml::Matrix& Dynamic::
computeInertiaReal( ml::Matrix& res,int time )
{
  sotDEBUGIN(25);

  const ml::Matrix & A = inertiaSOUT(time);
  const ml::Vector & gearRatio = gearRatioSOUT(time);
  const ml::Vector & inertiaRotor = inertiaRotorSOUT(time);

  res = A;
  for( unsigned int i=0;i<gearRatio.size();++i )
Thomas Moulard's avatar
Thomas Moulard committed
739
    res(i,i) += (gearRatio(i)*gearRatio(i)*inertiaRotor(i));
Francois Bleibel's avatar
Francois Bleibel committed
740
741
742
743
744
745
746
747
748
749

  sotDEBUGOUT(25);
  return res;
}

double& Dynamic::
computeFootHeight( double& foot,int time )
{
  sotDEBUGIN(25);
  newtonEulerSINTERN(time);
Thomas Moulard's avatar
Thomas Moulard committed
750
751
  CjrlFoot* RightFoot = m_HDR->rightFoot();
  vector3d AnkleInLocalRefFrame;
Francois Bleibel's avatar
Francois Bleibel committed
752
753
  RightFoot->getAnklePositionInLocalFrame(AnkleInLocalRefFrame);
  sotDEBUGOUT(25);
Thomas Moulard's avatar
Thomas Moulard committed
754
  return AnkleInLocalRefFrame[2];
Francois Bleibel's avatar
Francois Bleibel committed
755
756
757
758
759
760
761
762
763
764
765
766
}


/* --- SIGNAL --------------------------------------------------------------- */
/* --- SIGNAL --------------------------------------------------------------- */
/* --- SIGNAL --------------------------------------------------------------- */

dg::SignalTimeDependent<ml::Matrix,int>& Dynamic::
jacobiansSOUT( const std::string& name )
{
  SignalBase<int> & sigabs = Entity::getSignal(name);

Thomas Moulard's avatar
Thomas Moulard committed
767
768
  try {
    dg::SignalTimeDependent<ml::Matrix,int>& res
Francois Bleibel's avatar
Francois Bleibel committed
769
770
771
772
773
774
      = dynamic_cast< dg::SignalTimeDependent<ml::Matrix,int>& >( sigabs );
    return res;
  } catch( std::bad_cast e ) {
    SOT_THROW ExceptionSignal( ExceptionSignal::BAD_CAST,
				  "Impossible cast.",
				  " (while getting signal <%s> of type matrix.",
Thomas Moulard's avatar
Thomas Moulard committed
775
				  name.c_str());
Francois Bleibel's avatar
Francois Bleibel committed
776
777
778
779
780
781
782
  }
}
dg::SignalTimeDependent<MatrixHomogeneous,int>& Dynamic::
positionsSOUT( const std::string& name )
{
  SignalBase<int> & sigabs = Entity::getSignal(name);

Thomas Moulard's avatar
Thomas Moulard committed
783
784
  try {
    dg::SignalTimeDependent<MatrixHomogeneous,int>& res
Francois Bleibel's avatar
Francois Bleibel committed
785
786
787
788
789
790
      = dynamic_cast< dg::SignalTimeDependent<MatrixHomogeneous,int>& >( sigabs );
    return res;
  } catch( std::bad_cast e ) {
    SOT_THROW ExceptionSignal( ExceptionSignal::BAD_CAST,
				  "Impossible cast.",
				  " (while getting signal <%s> of type matrixHomo.",
Thomas Moulard's avatar
Thomas Moulard committed
791
				  name.c_str());
Francois Bleibel's avatar
Francois Bleibel committed
792
793
  }
}
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810

dg::SignalTimeDependent<ml::Vector,int>& Dynamic::
velocitiesSOUT( const std::string& name )
{
  SignalBase<int> & sigabs = Entity::getSignal(name);
  try {
    dg::SignalTimeDependent<ml::Vector,int>& res
      = dynamic_cast< dg::SignalTimeDependent<ml::Vector,int>& >( sigabs );
    return res;
 } catch( std::bad_cast e ) {
    SOT_THROW ExceptionSignal( ExceptionSignal::BAD_CAST,
				  "Impossible cast.",
				  " (while getting signal <%s> of type Vector.",
				  name.c_str());
  }
}

Francois Bleibel's avatar
Francois Bleibel committed
811
812
813
814
815
dg::SignalTimeDependent<ml::Vector,int>& Dynamic::
accelerationsSOUT( const std::string& name )
{
  SignalBase<int> & sigabs = Entity::getSignal(name);

Thomas Moulard's avatar
Thomas Moulard committed
816
817
  try {
    dg::SignalTimeDependent<ml::Vector,int>& res
Francois Bleibel's avatar
Francois Bleibel committed
818
819
820
821
822
823
      = dynamic_cast< dg::SignalTimeDependent<ml::Vector,int>& >( sigabs );
    return res;
  } catch( std::bad_cast e ) {
    SOT_THROW ExceptionSignal( ExceptionSignal::BAD_CAST,
				  "Impossible cast.",
				  " (while getting signal <%s> of type Vector.",
Thomas Moulard's avatar
Thomas Moulard committed
824
				  name.c_str());
Francois Bleibel's avatar
Francois Bleibel committed
825
826
827
828
829
830
831
832
833
834
835
836
  }
}


int& Dynamic::
computeNewtonEuler( int& dummy,int time )
{
  sotDEBUGIN(15);
  ml::Vector pos = jointPositionSIN(time); // TODO &pos
  ml::Vector vel = jointVelocitySIN(time);
  ml::Vector acc = jointAccelerationSIN(time);

837
  sotDEBUG(5) << "computeNewtonEuler: " << pos << endl;
Francois Bleibel's avatar
Francois Bleibel committed
838
839
840
841
  firstSINTERN(time);
  if( freeFlyerPositionSIN )
    {
      const ml::Vector& ffpos = freeFlyerPositionSIN(time);
842
843
844
845
846

      for( int i=0;i<6;++i ) pos(i) = ffpos(i) ;
      sotDEBUG(5) << "computeNewtonEuler: (" << name << ") ffpos = " << ffpos << endl;
   }
  sotDEBUG(5) << "computeNewtonEuler: (" << name << ") pos = " << pos << endl;
Francois Bleibel's avatar
Francois Bleibel committed
847
848
849
  if( freeFlyerVelocitySIN )
    {
      const ml::Vector& ffvel = freeFlyerVelocitySIN(time);
Thomas Moulard's avatar
Thomas Moulard committed
850
      for( int i=0;i<6;++i ) vel(i) = ffvel(i);
Francois Bleibel's avatar
Francois Bleibel committed
851
852
853
854
    }
  if( freeFlyerAccelerationSIN )
    {
      const ml::Vector& ffacc = freeFlyerAccelerationSIN(time);
Thomas Moulard's avatar
Thomas Moulard committed
855
      for( int i=0;i<6;++i ) acc(i) = ffacc(i);
Francois Bleibel's avatar
Francois Bleibel committed
856
857
    }
  if(! m_HDR->currentConfiguration(pos.accessToMotherLib()))
Thomas Moulard's avatar
Thomas Moulard committed
858
    {
Francois Bleibel's avatar
Francois Bleibel committed
859
860
861
862
863
864
865
866
      SOT_THROW ExceptionDynamic( ExceptionDynamic::JOINT_SIZE,
				     "Position vector size uncorrect",
				     " (Vector size is %d, should be %d).",
				     pos.size(),m_HDR->currentConfiguration().size() );
    }


  if(! m_HDR->currentVelocity(vel.accessToMotherLib()) )
Thomas Moulard's avatar
Thomas Moulard committed
867
    {
Francois Bleibel's avatar
Francois Bleibel committed
868
869
870
871
872
873
874
      SOT_THROW ExceptionDynamic( ExceptionDynamic::JOINT_SIZE,
				     "Velocity vector size uncorrect",
				     " (Vector size is %d, should be %d).",
				     vel.size(),m_HDR->currentVelocity().size() );
    }

  if(! m_HDR->currentAcceleration(acc.accessToMotherLib()) )
Thomas Moulard's avatar
Thomas Moulard committed
875
    {
Francois Bleibel's avatar
Francois Bleibel committed
876
877
878
879
880
881
882
      SOT_THROW ExceptionDynamic( ExceptionDynamic::JOINT_SIZE,
				     "Acceleration vector size uncorrect",
				     " (Vector size is %d, should be %d).",
				     acc.size(),m_HDR->currentAcceleration().size() );
    }

  m_HDR->computeForwardKinematics();
Thomas Moulard's avatar
Thomas Moulard committed
883

Francois Bleibel's avatar
Francois Bleibel committed
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
  sotDEBUG(1)<< "pos = " <<pos <<endl;
  sotDEBUG(1)<< "vel = " <<vel <<endl;
  sotDEBUG(1)<< "acc = " <<acc <<endl;

  sotDEBUGOUT(15);
  return dummy;
}
int& Dynamic::
initNewtonEuler( int& dummy,int time )
{
  sotDEBUGIN(15);
  firstSINTERN.setReady(false);
  computeNewtonEuler(dummy,time);
  for( int i=0;i<3;++i )
    m_HDR->computeForwardKinematics();

  sotDEBUGOUT(15);
  return dummy;
}

ml::Vector& Dynamic::
getUpperJointLimits( ml::Vector& res,const int& time )
{
907
  sotDEBUGIN(15);
Francois Bleibel's avatar
Francois Bleibel committed
908
909
910
911
912
913
  const unsigned int NBJ = m_HDR->numberDof();
  res.resize( NBJ );
  for( unsigned int i=0;i<NBJ;++i )
    {
      res(i)=m_HDR->upperBoundDof( i );
    }
914
915
  sotDEBUG(15) << "upperLimit (" << NBJ << ")=" << res <<endl;
  sotDEBUGOUT(15);
Francois Bleibel's avatar
Francois Bleibel committed
916
917
918
919
920
921
  return res;
}

ml::Vector& Dynamic::
getLowerJointLimits( ml::Vector& res,const int& time )
{
922
  sotDEBUGIN(15);
Francois Bleibel's avatar
Francois Bleibel committed
923
924
925
926
927
928
  const unsigned int NBJ = m_HDR->numberDof();
  res.resize( NBJ );
  for( unsigned int i=0;i<NBJ;++i )
    {
      res(i)=m_HDR->lowerBoundDof( i );
    }
929
930
  sotDEBUG(15) << "lowerLimit (" << NBJ << ")=" << res <<endl;
  sotDEBUGOUT(15);
Francois Bleibel's avatar
Francois Bleibel committed
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
  return res;
}



/* --- PARAMS --------------------------------------------------------------- */
/* --- PARAMS --------------------------------------------------------------- */
/* --- PARAMS --------------------------------------------------------------- */
void Dynamic::
commandLine( const std::string& cmdLine,
	     std::istringstream& cmdArgs,
	     std::ostream& os )
{
  sotDEBUG(25) << "# In { Cmd " << cmdLine <<endl;
  std::string filename;
  if( cmdLine == "debugInertia" )
Thomas Moulard's avatar
Thomas Moulard committed
947
948
949
950
    {
      cmdArgs>>ws; if(cmdArgs.good())
		     {
		       std::string arg; cmdArgs >> arg;
Francois Bleibel's avatar
Francois Bleibel committed
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
		       if( (arg=="true")||(arg=="1") )
			 { debugInertia = 1; }
		       else if( (arg=="2")||(arg=="grip") )
			 { debugInertia = 2; }
		       else debugInertia=0;

		     }
      else { os << "debugInertia = " << debugInertia << std::endl; }
    }
  else if( cmdLine == "setVrmlDir" )
    {  cmdArgs>>filename; setVrmlDirectory( filename );  }
  else if( cmdLine == "setVrml" )
    {  cmdArgs>>filename; setVrmlMainFile( filename );  }
  else if( cmdLine == "setXmlSpec" )
    {  cmdArgs>>filename; setXmlSpecificityFile( filename );  }
  else if( cmdLine == "setXmlRank" )
    {  cmdArgs>>filename; setXmlRankFile( filename );  }
  else if( cmdLine == "setFiles" )
    {
Thomas Moulard's avatar
Thomas Moulard committed
970
971
972
973
      cmdArgs>>filename; setVrmlDirectory( filename );
      cmdArgs>>filename; setVrmlMainFile( filename );
      cmdArgs>>filename; setXmlSpecificityFile( filename );
      cmdArgs>>filename; setXmlRankFile( filename );
Francois Bleibel's avatar
Francois Bleibel committed
974
975
976
    }
  else if( cmdLine == "displayFiles" )
    {
Thomas Moulard's avatar
Thomas Moulard committed
977
      cmdArgs >> ws; bool filespecified = false;
Francois Bleibel's avatar
Francois Bleibel committed
978
979
      if( cmdArgs.good() )
	{
Thomas Moulard's avatar
Thomas Moulard committed
980
	  filespecified = true;
Francois Bleibel's avatar
Francois Bleibel committed
981
982
983
984
985
986
987
988
	  std::string filetype; cmdArgs >> filetype;
	  sotDEBUG(15) << " Request: " << filetype << std::endl;
	  if( "vrmldir" == filetype ) { os << vrmlDirectory << std::endl; }
	  else if( "xmlspecificity" == filetype ) { os << xmlSpecificityFile << std::endl; }
	  else if( "xmlrank" == filetype ) { os << xmlRankFile << std::endl; }
	  else if( "vrmlmain" == filetype ) { os << vrmlMainFile << std::endl; }
	  else filespecified = false;
	}
Thomas Moulard's avatar
Thomas Moulard committed
989
      if( ! filespecified )
Francois Bleibel's avatar
Francois Bleibel committed
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
	{
	  os << "  - VRML Directory:\t\t\t" << vrmlDirectory <<endl
	     << "  - XML Specificity File:\t\t" << xmlSpecificityFile <<endl
	     << "  - XML Rank File:\t\t\t" << xmlRankFile <<endl
	     << "  - VRML Main File:\t\t\t" << vrmlMainFile <<endl;
	}
    }
  else if( cmdLine == "parse" )
    {
      if(! init )parseConfigFiles(); else cout << "  !! Already parsed." <<endl;
    }
  else if( cmdLine == "createJacobian" )
    {
      std::string Jname; cmdArgs >> Jname;
      unsigned int rank; cmdArgs >> rank;
1005
      //createJacobianSignal(Jname,rank);
Francois Bleibel's avatar
Francois Bleibel committed
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
    }
  else if( cmdLine == "destroyJacobian" )
    {
      std::string Jname; cmdArgs >> Jname;
      destroyJacobianSignal(Jname);
    }
  else if( cmdLine == "createPosition" )
    {
      std::string Jname; cmdArgs >> Jname;
      unsigned int rank; cmdArgs >> rank;
1016
      //createPositionSignal(Jname,rank);
Francois Bleibel's avatar
Francois Bleibel committed
1017
1018
1019
1020
1021
1022
    }
  else if( cmdLine == "destroyPosition" )
    {
      std::string Jname; cmdArgs >> Jname;
      destroyPositionSignal(Jname);
    }
1023
1024
1025
1026
  else if( cmdLine == "createVelocity" )
    {
      std::string Jname; cmdArgs >> Jname;
      unsigned int rank; cmdArgs >> rank;
1027
      //createVelocitySignal(Jname,rank);
1028
1029
1030
1031
1032
1033
    }
  else if( cmdLine == "destroyVelocity" )
    {
      std::string Jname; cmdArgs >> Jname;
      destroyVelocitySignal(Jname);
    }
Francois Bleibel's avatar
Francois Bleibel committed
1034
1035
1036
1037
  else if( cmdLine == "createAcceleration" )
    {
      std::string Jname; cmdArgs >> Jname;
      unsigned int rank; cmdArgs >> rank;
1038
      //createAccelerationSignal(Jname,rank);
Francois Bleibel's avatar
Francois Bleibel committed
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
    }
  else if( cmdLine == "destroyAcceleration" )
    {
      std::string Jname; cmdArgs >> Jname;
      destroyAccelerationSignal(Jname);
    }
  else if( cmdLine == "createEndeffJacobian" )
    {
      std::string Jname; cmdArgs >> Jname;
      unsigned int rank; cmdArgs >> rank;
1049
      //createEndeffJacobianSignal(Jname,rank);
Francois Bleibel's avatar
Francois Bleibel committed
1050
1051
1052
1053
1054
    }
  else if( cmdLine == "createOpPoint" )
    {
      std::string Jname; cmdArgs >> Jname;
      unsigned int rank; cmdArgs >> rank;
1055
1056
      //createEndeffJacobianSignal(string("J")+Jname,rank);
      //createPositionSignal(Jname,rank);
Francois Bleibel's avatar
Francois Bleibel committed
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
      sotDEBUG(15)<<endl;
    }
  else if( cmdLine == "destroyOpPoint" )
    {
      std::string Jname; cmdArgs >> Jname;
      destroyJacobianSignal(string("J")+Jname);
      destroyPositionSignal(Jname);
    }
  else if( cmdLine == "ndof" ) { os << m_HDR->numberDof() <<endl; return; }
  else if( cmdLine == "setComputeCom" )
    {
      unsigned int b; cmdArgs >> b;
1069
      comActivation((b!=0));
Francois Bleibel's avatar
Francois Bleibel committed
1070
1071
1072
1073
    }
  else if( cmdLine == "setComputeZmp" )
    {
      unsigned int b; cmdArgs >> b;
1074
      zmpActivation((b!=0));
Francois Bleibel's avatar
Francois Bleibel committed
1075
1076
1077
    }
  else if( cmdLine == "setProperty" )
    {
Thomas Moulard's avatar
Thomas Moulard committed
1078
      string prop,val; cmdArgs >> prop;
Francois Bleibel's avatar
Francois Bleibel committed
1079
1080
1081
1082
1083
      if( cmdArgs.good() ) cmdArgs >> val; else val="true";
      m_HDR->setProperty( prop,val );
    }
  else if( cmdLine == "getProperty" )
    {
Thomas Moulard's avatar
Thomas Moulard committed
1084
      string prop,val; cmdArgs >> prop;
Francois Bleibel's avatar
Francois Bleibel committed
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
      m_HDR->getProperty( prop,val );
      os<<val<<endl;
    }
  else if( cmdLine == "displayProperties" )
    {
      std::istringstream iss("ComputeVelocity ComputeCoM ComputeAccelerationCoM ComputeMomentum ComputeZMP ComputeBackwardDynamics");
      string prop,val; const unsigned int STR_SIZE=30;
      while( iss.good() )
	{
	  iss>>prop;
	  m_HDR->getProperty( prop,val );
	  os<<prop;
	  for( unsigned int i=prop.length();i<STR_SIZE;++i ) os<<" ";
	  os<<" -> "<<val <<endl;
Thomas Moulard's avatar
Thomas Moulard committed
1099
	}
Francois Bleibel's avatar
Francois Bleibel committed
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
    }
  else if( cmdLine == "help" )
    {
      os << "Dynamics:"<<endl
	 << "  - setVrmlDir - setVrml - setXmlSpec - setXmlRanks <file>" <<endl
	 << "\t\t\t\t:set the config files" <<endl
	 << "  - setFiles <%1> ... <%4>\t:set files in the order cited above" <<endl
	 << "  - displayFiles\t\t\t:display the 5 config files" <<endl
	 << "  - parse\t\t\t:parse the files set unsing the set{Xml|Vrml} commands." <<endl
	 << "  - createJacobian <name> <point>:create a signal named <name> " << endl
	 << "  - createEndeffJacobian <name> <point>:create a signal named <name> "
	 << "forwarding the jacoian computed at <point>." <<endl
	 << "  - destroyJacobian <name>\t:delete the jacobian signal <name>" << endl
	 << "  - {create|destroy}Position\t:handle position signals." <<endl
	 << "  - {create|destroy}OpPoint\t:handle Operation Point (ie pos+jac) signals." <<endl
	 << "  - {create|destroy}Acceleration\t:handle acceleration signals." <<endl
	 << "  - {get|set}Property <name> [<val>]: set/get the property." <<endl
	 << "  - displayProperties: print the prop-val couples list." <<endl
	 << "  - ndof\t\t\t: display the number of DOF of the robot."<< endl;
Thomas Moulard's avatar
Thomas Moulard committed
1119

Francois Bleibel's avatar
Francois Bleibel committed
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
      Entity::commandLine(cmdLine,cmdArgs,os);
    }
  else { Entity::commandLine( cmdLine,cmdArgs,os); }

  sotDEBUGOUT(15);

}