dynamic.h 8.58 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
 * 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/>.
 */
Francois Bleibel's avatar
Francois Bleibel committed
20
21
22
23
24
25
26
27
28

#ifndef __SOT_DYNAMIC_H__
#define __SOT_DYNAMIC_H__

/* --------------------------------------------------------------------- */
/* --- INCLUDE --------------------------------------------------------- */
/* --------------------------------------------------------------------- */

/* Matrix */
Thomas Moulard's avatar
Thomas Moulard committed
29
30
#include <jrl/mal/boost.hh>
#include "jrl/mal/matrixabstractlayer.hh"
Francois Bleibel's avatar
Francois Bleibel committed
31
32
33
namespace ml = maal::boost;

/* JRL dynamic */
Thomas Moulard's avatar
Thomas Moulard committed
34
35
#include <abstract-robot-dynamics/humanoid-dynamic-robot.hh>
#include <jrl/dynamics/dynamicsfactory.hh>
Francois Bleibel's avatar
Francois Bleibel committed
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
namespace djj = dynamicsJRLJapan;

/* SOT */
#include <sot-core/flags.h>
#include <dynamic-graph/entity.h>
#include <dynamic-graph/pool.h>
#include <dynamic-graph/signal-ptr.h>
#include <dynamic-graph/signal-time-dependent.h>
#include <sot-core/exception-dynamic.h>
#include <sot-core/matrix-homogeneous.h>

/* STD */
#include <string>

/* --------------------------------------------------------------------- */
/* --- API ------------------------------------------------------------- */
/* --------------------------------------------------------------------- */

#if defined (WIN32) 
#  if defined (dynamic_EXPORTS)
#    define SOTDYNAMIC_EXPORT __declspec(dllexport)
#  else  
#    define SOTDYNAMIC_EXPORT __declspec(dllimport)
#  endif 
#else
#  define SOTDYNAMIC_EXPORT
#endif


namespace sot {
namespace dg = dynamicgraph;

68
69
70
71
72
  namespace command {
    class SetFiles;
    class Parse;
    class CreateOpPoint;
  }
Francois Bleibel's avatar
Francois Bleibel committed
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* --------------------------------------------------------------------- */
/* --- CLASS ----------------------------------------------------------- */
/* --------------------------------------------------------------------- */

/*! @ingroup signals
  \brief This class provides an inverse dynamic model of the robot.
  More precisely it wraps the newton euler algorithm implemented
  by the dynamicsJRLJapan library to make it accessible in the stack of tasks.
  The robot is described by a VRML file.
*/
  
class SOTDYNAMIC_EXPORT Dynamic
:public dg::Entity
{
87
88
89
  friend class sot::command::SetFiles;
  friend class sot::command::Parse;
  friend class sot::command::CreateOpPoint;
Francois Bleibel's avatar
Francois Bleibel committed
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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
 public:
  static const std::string CLASS_NAME;

 protected:
 public:

  /*! \name Fields to access dynamicsJRLJapan Library 
    @{
   */

  /*! \brief Abstract pointer on the structure.
    Ultimately we should be able to use only the abstract
    interface and do not care about the implementation.
  */
  CjrlHumanoidDynamicRobot* m_HDR;


  int debugInertia;

  /*! \brief Fields to access the humanoid model 
   @{ */

  /*! \brief Directory where the VRML humanoid model is stored */
  std::string vrmlDirectory;
  /*! \brief Name of the root's robot model file */
  std::string vrmlMainFile;
  /*! \brief Name of the name specifying which end-effector is
    the head, the feet and so on... */
  std::string xmlSpecificityFile;
  /*! \brief Name of the name specifying which end-effector is
    the head, the feet and so on... */
  std::string xmlRankFile;
  /*! @} */

  /*! @} */
  bool init;
  std::list< dg::SignalBase<int>*  > genericSignalRefs;

 public: /* --- CONSTRUCTION --- */

  Dynamic( const std::string& name, bool build=true );
  virtual ~Dynamic( void );

 public: /* --- MODEL CREATION --- */
 
  virtual void buildModel( void );

  void setVrmlDirectory( const std::string& filename );
  void setVrmlMainFile( const std::string& filename );
  void setXmlSpecificityFile( const std::string& filename );
  void setXmlRankFile( const std::string& filename );
  void parseConfigFiles( void );

 public: /* --- SIGNAL ACTIVATION --- */
  dg::SignalTimeDependent< ml::Matrix,int > &
    createEndeffJacobianSignal( const std::string& signame,
146
				CjrlJoint* inJoint );
Francois Bleibel's avatar
Francois Bleibel committed
147
148
  dg::SignalTimeDependent< ml::Matrix,int > &
    createJacobianSignal( const std::string& signame,
149
			  CjrlJoint* inJoint );
Francois Bleibel's avatar
Francois Bleibel committed
150
151
152
  void destroyJacobianSignal( const std::string& signame );
  dg::SignalTimeDependent< MatrixHomogeneous,int >&
    createPositionSignal( const std::string& signame,
153
			  CjrlJoint* inJoint );
Francois Bleibel's avatar
Francois Bleibel committed
154
  void destroyPositionSignal( const std::string& signame );
155
156
  dg::SignalTimeDependent< ml::Vector,int >&
      createVelocitySignal( const std::string& signame,
157
  			     CjrlJoint* inJoint );
158
    void destroyVelocitySignal( const std::string& signame );
Francois Bleibel's avatar
Francois Bleibel committed
159
160
  dg::SignalTimeDependent< ml::Vector,int >&
    createAccelerationSignal( const std::string& signame,
161
			     CjrlJoint* inJoint );
Francois Bleibel's avatar
Francois Bleibel committed
162
163
164
165
166
167
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
  void destroyAccelerationSignal( const std::string& signame );

  bool zmpActivation( void ) { std::string Property("ComputeZMP");
    std::string Value; m_HDR->getProperty(Property,Value); return (Value=="true");}
  void zmpActivation( const bool& b ) { std::string Property("ComputeZMP");
    std::string Value; if (b) Value="true"; else Value="false"; m_HDR->setProperty(Property,Value); }
  bool comActivation( void ) { std::string Property("ComputeCoM");
    std::string Value; m_HDR->getProperty(Property,Value); return (Value=="true"); }
  void comActivation( const bool& b ) { std::string Property("ComputeCoM");
    std::string Value; if (b) Value="true"; else Value="false"; m_HDR->setProperty(Property,Value); } 

 public: /* --- SIGNAL --- */

  dg::SignalPtr<ml::Vector,int> jointPositionSIN;
  dg::SignalPtr<ml::Vector,int> freeFlyerPositionSIN;
  dg::SignalPtr<ml::Vector,int> jointVelocitySIN;
  dg::SignalPtr<ml::Vector,int> freeFlyerVelocitySIN;
  dg::SignalPtr<ml::Vector,int> jointAccelerationSIN;
  dg::SignalPtr<ml::Vector,int> freeFlyerAccelerationSIN;

  // protected:
 public:
  typedef int Dummy;
  dg::SignalTimeDependent<Dummy,int> firstSINTERN;
  dg::SignalTimeDependent<Dummy,int> newtonEulerSINTERN;

  int& computeNewtonEuler( int& dummy,int time );
  int& initNewtonEuler( int& dummy,int time );

 public:
  dg::SignalTimeDependent<ml::Vector,int> zmpSOUT;
  dg::SignalTimeDependent<ml::Matrix,int> JcomSOUT;
  dg::SignalTimeDependent<ml::Vector,int> comSOUT;
  dg::SignalTimeDependent<ml::Matrix,int> inertiaSOUT;

  dg::SignalTimeDependent<ml::Matrix,int>& jacobiansSOUT( const std::string& name );
  dg::SignalTimeDependent<MatrixHomogeneous,int>& positionsSOUT( const std::string& name );
199
  dg::SignalTimeDependent<ml::Vector,int>& velocitiesSOUT( const std::string& name );
Francois Bleibel's avatar
Francois Bleibel committed
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
  dg::SignalTimeDependent<ml::Vector,int>& accelerationsSOUT( const std::string& name );

  dg::SignalTimeDependent<double,int> footHeightSOUT;
  dg::SignalTimeDependent<ml::Vector,int> upperJlSOUT;
  dg::SignalTimeDependent<ml::Vector,int> lowerJlSOUT;

  dg::Signal<ml::Vector,int> inertiaRotorSOUT;
  dg::Signal<ml::Vector,int> gearRatioSOUT;
  dg::SignalTimeDependent<ml::Matrix,int> inertiaRealSOUT;
  dg::SignalTimeDependent<ml::Vector,int> MomentaSOUT;
  dg::SignalTimeDependent<ml::Vector,int> AngularMomentumSOUT;

 protected:
  ml::Vector& computeZmp( ml::Vector& res,int time );
  ml::Vector& computeMomenta( ml::Vector &res, int time);
  ml::Vector& computeAngularMomentum( ml::Vector &res, int time);
  ml::Matrix& computeJcom( ml::Matrix& res,int time );
  ml::Vector& computeCom( ml::Vector& res,int time );
  ml::Matrix& computeInertia( ml::Matrix& res,int time );
  ml::Matrix& computeInertiaReal( ml::Matrix& res,int time );
  double& computeFootHeight( double& res,int time );
  
  ml::Matrix& computeGenericJacobian( CjrlJoint* j,ml::Matrix& res,int time );
  ml::Matrix& computeGenericEndeffJacobian( CjrlJoint* j,ml::Matrix& res,int time );
  MatrixHomogeneous& computeGenericPosition( CjrlJoint* j,MatrixHomogeneous& res,int time );
225
  ml::Vector& computeGenericVelocity( CjrlJoint* j,ml::Vector& res,int time );
Francois Bleibel's avatar
Francois Bleibel committed
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
  ml::Vector& computeGenericAcceleration( CjrlJoint* j,ml::Vector& res,int time );

  ml::Vector& getUpperJointLimits( ml::Vector& res,const int& time );
  ml::Vector& getLowerJointLimits( ml::Vector& res,const int& time );


 public: /* --- PARAMS --- */
  virtual void commandLine( const std::string& cmdLine,
			    std::istringstream& cmdArgs,
			    std::ostream& os );
    

};


} // namespace sot



#endif // #ifndef __SOT_DYNAMIC_H__