@@ -37,19 +37,22 @@ DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(GripperControlPlugin,"GripperControl");
37
37
/* --- PLUGIN --------------------------------------------------------------- */
38
38
39
39
40
- #define SOT_FULL_TO_REDUCED ( sotName ) \
41
- sotName##FullSizeSIN(NULL ," GripperControl(" +name+" )::input(vector)::" \
42
- +#sotName+" FullIN" ) \
43
- ,sotName##ReduceSOUT( SOT_INIT_SIGNAL_2( GripperControlPlugin::selector, \
44
- sotName##FullSizeSIN,ml::Vector, \
45
- selectionSIN,Flags ), \
46
- " GripperControl(" +name+" )::input(vector)::" \
47
- +#sotName+" ReducedOUT" )
40
+ #define SOT_FULL_TO_REDUCED ( sotName ) \
41
+ sotName##FullSizeSIN(NULL ," GripperControl(" +name+" )::input(vector)::" \
42
+ +#sotName+" FullIN" ) \
43
+ ,sotName##ReduceSOUT( SOT_INIT_SIGNAL_2( GripperControlPlugin::selector, \
44
+ sotName##FullSizeSIN,ml::Vector, \
45
+ selectionSIN,Flags ), \
46
+ " GripperControl(" +name+" )::input(vector)::" \
47
+ +#sotName+" ReducedOUT" )
48
48
49
49
50
50
51
51
const double GripperControl::OFFSET_DEFAULT = 0.9 ;
52
52
53
+ // TODO: hard coded
54
+ const double DT = 0.005 ;
55
+
53
56
GripperControl::
54
57
GripperControl (void )
55
58
:offset( GripperControl::OFFSET_DEFAULT )
@@ -60,45 +63,34 @@ GripperControlPlugin::
60
63
GripperControlPlugin ( const std::string & name )
61
64
:Entity(name)
62
65
,calibrationStarted(false )
63
-
64
66
,positionSIN(NULL ," GripperControl(" +name+" )::input(vector)::position" )
65
- ,upperLimitSIN(NULL ," GripperControl(" +name+" )::input(vector)::upperLimit" )
66
- ,lowerLimitSIN(NULL ," GripperControl(" +name+" )::input(vector)::lowerLimit" )
67
+ ,positionDesSIN(NULL ," GripperControl(" +name+" )::input(vector)::positionDes" )
67
68
,torqueSIN(NULL ," GripperControl(" +name+" )::input(vector)::torque" )
68
69
,torqueLimitSIN(NULL ," GripperControl(" +name+" )::input(vector)::torqueLimit" )
69
70
,selectionSIN(NULL ," GripperControl(" +name+" )::input(vector)::selec" )
70
-
71
- ,SOT_FULL_TO_REDUCED( position )
72
- ,SOT_FULL_TO_REDUCED( upperLimit )
73
- ,SOT_FULL_TO_REDUCED( lowerLimit )
74
- ,SOT_FULL_TO_REDUCED( torque )
75
- ,SOT_FULL_TO_REDUCED( torqueLimit )
76
-
77
- ,desiredPositionSOUT( SOT_MEMBER_SIGNAL_5( GripperControl::computeDesiredPosition,
78
- positionSIN,ml::Vector,
79
- torqueSIN,ml::Vector,
80
- upperLimitSIN,ml::Vector,
81
- lowerLimitSIN,ml::Vector,
82
- torqueLimitSIN,ml::Vector ),
83
- "GripperControl(" +name+" )::output(vector)::reference" )
84
-
71
+
72
+ ,SOT_FULL_TO_REDUCED( position )
73
+ ,SOT_FULL_TO_REDUCED( torque )
74
+ ,SOT_FULL_TO_REDUCED( torqueLimit )
75
+ ,desiredPositionSOUT( SOT_MEMBER_SIGNAL_4( GripperControl::computeDesiredPosition,
76
+ positionSIN,ml::Vector,
77
+ positionDesSIN,ml::Vector,
78
+ torqueSIN,ml::Vector,
79
+ torqueLimitSIN,ml::Vector ),
80
+ "GripperControl(" +name+" )::output(vector)::reference" )
85
81
{
86
82
sotDEBUGIN (5 );
87
-
83
+
88
84
positionSIN.plug ( &positionReduceSOUT );
89
- upperLimitSIN.plug ( &upperLimitReduceSOUT );
90
- lowerLimitSIN.plug ( &lowerLimitReduceSOUT );
91
85
torqueSIN.plug ( &torqueReduceSOUT );
92
86
torqueLimitSIN.plug ( &torqueLimitReduceSOUT );
93
87
94
- signalRegistration ( positionSIN << upperLimitSIN << lowerLimitSIN
88
+ signalRegistration ( positionSIN << positionDesSIN
95
89
<< torqueSIN << torqueLimitSIN << selectionSIN
96
90
<< desiredPositionSOUT
97
- << positionFullSizeSIN << positionReduceSOUT
98
- << upperLimitFullSizeSIN << upperLimitReduceSOUT
99
- << lowerLimitFullSizeSIN << lowerLimitReduceSOUT
100
- << torqueFullSizeSIN << torqueReduceSOUT
101
- << torqueLimitFullSizeSIN << torqueLimitReduceSOUT );
91
+ << positionFullSizeSIN
92
+ << torqueFullSizeSIN
93
+ << torqueLimitFullSizeSIN);
102
94
sotDEBUGOUT (5 );
103
95
104
96
initCommands ();
@@ -107,17 +99,12 @@ GripperControlPlugin( const std::string & name )
107
99
108
100
GripperControlPlugin::
109
101
~GripperControlPlugin ( void )
110
- {
111
- return ;
112
- }
102
+ {}
113
103
114
104
std::string GripperControlPlugin::
115
105
getDocString () const
116
106
{
117
- std::string docstring =
118
- " \n "
119
- " \n Control of HRP2 gripper."
120
- " \n " ;
107
+ std::string docstring =" Control of gripper." ;
121
108
return docstring;
122
109
}
123
110
@@ -128,89 +115,64 @@ getDocString () const
128
115
void GripperControl::
129
116
computeIncrement ( const ml::Vector& torques,
130
117
const ml::Vector& torqueLimits,
131
- const ml::Vector& currentNormPos )
118
+ const ml::Vector& currentNormVel )
132
119
{
133
- const unsigned int SIZE = torques.size ();
134
- if ( (SIZE==torqueLimits.size ())||(SIZE==currentNormPos.size ()) )
135
- { /* ERROR ... */ }
136
-
137
- if ( factor.size ()!=SIZE ) { factor.resize (SIZE); factor.fill (1 .); }
138
- for ( unsigned int i=0 ;i<SIZE;++i )
139
- {
140
- if ( (torques (i)>torqueLimits (i))&&(currentNormPos (i)>0 ) )
141
- { factor (i)*=offset; }
142
- else if ( (torques (i)<-torqueLimits (i))&&(currentNormPos (i)<0 ) )
143
- { factor (i)*=offset; }
144
- else { factor (i)/=offset; }
145
- if ( factor (i)>1 ) factor (i)=1 ;
146
- if ( factor (i)<0 ) factor (i)=0 ;
147
- }
148
- }
120
+ const unsigned int SIZE = currentNormVel.size ();
149
121
122
+ // initialize factor, if needed.
123
+ if ( factor.size ()!=SIZE ) { factor.resize (SIZE); factor.fill (1 .); }
150
124
151
- void GripperControl::
152
- computeNormalizedPosition ( const ml::Vector& currentPos,
153
- const ml::Vector& upperLim,
154
- const ml::Vector& lowerLim,
155
- ml::Vector& currentNormPos )
156
- {
157
- sotDEBUG (25 ) << " UJL = " << upperLim;
158
- sotDEBUG (25 ) << " LJL = " << lowerLim;
159
-
160
- const unsigned int SIZE = currentPos.size ();
161
- if ( (SIZE==upperLim.size ())||(SIZE==lowerLim.size ()) )
162
- { /* ERROR ... */ }
163
- currentNormPos.resize (SIZE);
164
- for ( unsigned int i=0 ;i<SIZE;++i )
165
- {
166
- currentNormPos (i) = ( -1 +2 *( currentPos (i)-lowerLim (i) )
167
- /( upperLim (i)-lowerLim (i) ));
168
- }
169
- }
125
+ // Torque not provided?
126
+ if (torques.size () == 0 )
127
+ {
128
+ std::cerr << " torque is not provided " << std::endl;
129
+ return ;
130
+ }
170
131
171
- void GripperControl::
172
- computeDenormalizedPosition ( const ml::Vector& currentNormPos,
173
- const ml::Vector& upperLim,
174
- const ml::Vector& lowerLim,
175
- ml::Vector& currentPos )
176
- {
177
- const unsigned int SIZE = currentNormPos.size ();
178
- if ( (SIZE==upperLim.size ())||(SIZE==lowerLim.size ()) )
179
- { /* ERROR ... */ }
180
- currentPos.resize (SIZE);
181
- for ( unsigned int i=0 ;i<SIZE;++i )
182
- {
183
- currentPos (i) = ( (currentNormPos (i)+1 )*( upperLim (i)-lowerLim (i) )/2
184
- +lowerLim (i) );
185
- }
132
+ for ( unsigned int i=0 ;i<SIZE;++i )
133
+ {
134
+ // apply a reduction factor if the torque limits are exceeded
135
+ // and the velocity goes in the same way
136
+ if ( (torques (i)>torqueLimits (i))&&(currentNormVel (i)>0 ) )
137
+ { factor (i)*=offset; }
138
+ else if ( (torques (i)< -torqueLimits (i))&&(currentNormVel (i)<0 ) )
139
+ { factor (i)*=offset; }
140
+ // otherwise, release smoothly the reduction if possible/needed
141
+ else { factor (i)/=offset; }
142
+
143
+ // ensure factor is in )0,1(
144
+ factor (i) = std::min (1 ., std::max (factor (i),0 .));
145
+ }
186
146
}
187
147
188
148
ml::Vector& GripperControl::
189
149
computeDesiredPosition ( const ml::Vector& currentPos,
150
+ const ml::Vector& desiredPos,
190
151
const ml::Vector& torques,
191
- const ml::Vector& upperLim,
192
- const ml::Vector& lowerLim,
193
152
const ml::Vector& torqueLimits,
194
- ml::Vector& desPos )
153
+ ml::Vector& referencePos )
195
154
{
196
155
const unsigned int SIZE = currentPos.size ();
197
- if ( (SIZE==torques.size ()) )
198
- { /* ERROR ... */ }
199
- desPos.resize (SIZE);
200
-
201
- ml::Vector normPos;
202
- computeNormalizedPosition ( currentPos,upperLim,lowerLim,normPos );
203
- sotDEBUG (25 ) << " Norm pos = " << normPos;
204
-
205
- computeIncrement ( torques,torqueLimits,normPos );
206
- sotDEBUG (25 ) << " Factor = " << factor;
207
-
208
- ml::Vector desNormPos (SIZE);
209
- normPos.multiply (factor,desNormPos);
210
-
211
- computeDenormalizedPosition ( desNormPos,upperLim,lowerLim,desPos );
212
-
213
- return desPos;
156
+ // if( (SIZE==torques.size()) )
157
+ // { /* ERROR ... */ }
158
+
159
+ // compute the desired velocity
160
+ ml::Vector velocity = (desiredPos - currentPos)* (1 . / DT);
161
+
162
+ computeIncrement (torques, torqueLimits, velocity);
163
+
164
+ sotDEBUG (25 ) << " velocity " << velocity << std::endl;
165
+ sotDEBUG (25 ) << " factor " << factor << std::endl;
166
+
167
+ // multiply the velocity elmt per elmt
168
+ ml::Vector weightedVel (SIZE);
169
+ velocity.multiply (factor, weightedVel);
170
+ sotDEBUG (25 ) << " weightedVel " << weightedVel << std::endl;
171
+
172
+ // integrate the desired velocity
173
+ referencePos.resize (SIZE);
174
+ referencePos = currentPos + weightedVel * DT;
175
+ return referencePos;
214
176
}
215
177
216
178
@@ -241,7 +203,7 @@ void GripperControlPlugin::initCommands()
241
203
namespace dc = ::dynamicgraph::command;
242
204
addCommand (" offset" ,
243
205
dc::makeCommandVoid1 (*this ,&GripperControlPlugin::setOffset,
244
- " set the offset (should be in )0, 1(." ));
206
+ " set the offset (should be in )0, 1( ) ." ));
245
207
}
246
208
247
209
0 commit comments