force-compensation.h 6.09 KB
Newer Older
Francois Bleibel's avatar
Francois Bleibel committed
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
30
31
32
33
34
35
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
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
199
200
201
202
203
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 * Copyright Projet JRL-Japan, 2007
 *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 *
 * File:      ForceCompensation.h
 * Project:   SOT
 * Author:    Nicolas Mansard
 *
 * Version control
 * ===============
 *
 *  $Id$
 *
 * Description
 * ============
 *
 *
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/



#ifndef __SOT_SOTFORCECOMPENSATION_H__
#define __SOT_SOTFORCECOMPENSATION_H__

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

/* Matrix */
#include <MatrixAbstractLayer/boost.h>
namespace ml = maal::boost;

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

/* STD */
#include <string>

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

#if defined (WIN32) 
#  if defined (force_compensation_EXPORTS)
#    define SOTFORCECOMPENSATION_EXPORT __declspec(dllexport)
#  else  
#    define SOTFORCECOMPENSATION_EXPORT __declspec(dllimport)
#  endif 
#else
#  define SOTFORCECOMPENSATION_EXPORT
#endif


namespace sot {
namespace dg = dynamicgraph;

/* --------------------------------------------------------------------- */
/* --- CLASS ----------------------------------------------------------- */
/* --------------------------------------------------------------------- */

class SOTFORCECOMPENSATION_EXPORT ForceCompensation
{
 private:
  static MatrixRotation I3;
 protected:
  bool usingPrecompensation;

 public:
  ForceCompensation( void );
  static MatrixForce& computeHandXworld( 
					   const MatrixRotation & worldRhand,
					   const ml::Vector & transSensorCom,
					   MatrixForce& res );

  
  static MatrixForce& computeHandVsensor( const MatrixRotation & sensorRhand,
					     MatrixForce& res );
  static MatrixForce& computeSensorXhand( const MatrixRotation & sensorRhand,
					     const ml::Vector & transSensorCom,
					     MatrixForce& res );
/*   static ml::Matrix& computeInertiaSensor( const ml::Matrix& inertiaJoint, */
/* 					   const MatrixForce& sensorXhand, */
/* 					   ml::Matrix& res ); */

  static ml::Vector& computeTorsorCompensated( const ml::Vector& torqueInput,
					       const ml::Vector& torquePrecompensation,
					       const ml::Vector& gravity,
					       const MatrixForce& handXworld,
					       const MatrixForce& handVsensor,
					       const ml::Matrix& gainSensor,
					       const ml::Vector& momentum,
					       ml::Vector& res );

  static ml::Vector& crossProduct_V_F( const ml::Vector& velocity,
				       const ml::Vector& force,
				       ml::Vector& res );
  static ml::Vector& computeMomentum( const ml::Vector& velocity,
				      const ml::Vector& acceleration,
				      const MatrixForce& sensorXhand,
				      const ml::Matrix& inertiaJoint,
				      ml::Vector& res );

  static ml::Vector& computeDeadZone( const ml::Vector& torqueInput,
				      const ml::Vector& deadZoneLimit,
				      ml::Vector& res );
  
 public: // CALIBRATION

  std::list<ml::Vector> torsorList;
  std::list<MatrixRotation> rotationList;

  void clearCalibration( void );
  void addCalibrationValue( const ml::Vector& torsor,
			    const MatrixRotation & worldRhand );
  
  ml::Vector calibrateTransSensorCom( const ml::Vector& gravity,
				      const MatrixRotation& handRsensor );
  ml::Vector calibrateGravity( const MatrixRotation& handRsensor,
			       bool precompensationCalibration = false,
			       const MatrixRotation& hand0Rsensor = I3 );

    
  
};

/* --------------------------------------------------------------------- */
/* --- PLUGIN ---------------------------------------------------------- */
/* --------------------------------------------------------------------- */

class SOTFORCECOMPENSATION_EXPORT ForceCompensationPlugin
:public dg::Entity, public ForceCompensation
{
 public:
  static const std::string CLASS_NAME;
  bool calibrationStarted;


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

  ForceCompensationPlugin( const std::string& name );
  virtual ~ForceCompensationPlugin( void );

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

  /* --- INPUTS --- */
  dg::SignalPtr<ml::Vector,int> torsorSIN; 
  dg::SignalPtr<MatrixRotation,int> worldRhandSIN; 

  /* --- CONSTANTS --- */
  dg::SignalPtr<MatrixRotation,int> handRsensorSIN; 
  dg::SignalPtr<ml::Vector,int> translationSensorComSIN; 
  dg::SignalPtr<ml::Vector,int> gravitySIN; 
  dg::SignalPtr<ml::Vector,int> precompensationSIN; 
  dg::SignalPtr<ml::Matrix,int> gainSensorSIN; 
  dg::SignalPtr<ml::Vector,int> deadZoneLimitSIN; 
  dg::SignalPtr<ml::Vector,int> transSensorJointSIN; 
  dg::SignalPtr<ml::Matrix,int> inertiaJointSIN; 

  dg::SignalPtr<ml::Vector,int> velocitySIN; 
  dg::SignalPtr<ml::Vector,int> accelerationSIN; 

  /* --- INTERMEDIATE OUTPUTS --- */
  dg::SignalTimeDependent<MatrixForce,int> handXworldSOUT; 
  dg::SignalTimeDependent<MatrixForce,int> handVsensorSOUT; 
  dg::SignalPtr<ml::Vector,int> torsorDeadZoneSIN; 

  dg::SignalTimeDependent<MatrixForce,int> sensorXhandSOUT;
  //dg::SignalTimeDependent<ml::Matrix,int> inertiaSensorSOUT;
  dg::SignalTimeDependent<ml::Vector,int> momentumSOUT; 
  dg::SignalPtr<ml::Vector,int> momentumSIN; 

  /* --- OUTPUTS --- */
  dg::SignalTimeDependent<ml::Vector,int> torsorCompensatedSOUT; 
  dg::SignalTimeDependent<ml::Vector,int> torsorDeadZoneSOUT;

  typedef int sotDummyType;
  dg::SignalTimeDependent<sotDummyType,int> calibrationTrigerSOUT; 

 public: /* --- COMMANDLINE --- */

  sotDummyType& calibrationTriger( sotDummyType& dummy,int time );


  virtual void commandLine( const std::string& cmdLine,
			    std::istringstream& cmdArgs,
			    std::ostream& os );



};


} // namaspace sot



#endif // #ifndef __SOT_SOTFORCECOMPENSATION_H__