-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActionTrans.cpp
More file actions
executable file
·351 lines (301 loc) · 9.71 KB
/
ActionTrans.cpp
File metadata and controls
executable file
·351 lines (301 loc) · 9.71 KB
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
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
266
267
268
269
270
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
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
344
345
346
347
348
349
350
351
#include "Action.h"
#define TransFrameNum 2
//加速度:0.001f
//最大速度:0.15f
bool Action::CrazyTrans( float transLen )
{
ActLog << "Crazy Trans " << endl;
mJoint->ClearJoint();
int walkT = TransFrameNum;
int frameNum = 0;
int deltaN = walkT / 2;
static float lastTransLen = 0.0f;
bool leftTrans;
if(transLen >= 0.0f )
{
leftTrans= true;
}
else
{
leftTrans = false;
}
const float thighLen = 0.14f;
const float shankLen = 0.11f;
const float footLen = 0.16f;
const float standingHeight = 0.18f ;// v0.59 - 0.18f; // v0.58 - 0.204
float deltaH = 0.0083f; // v0.59 - 0.0072f; // v0.58 - 0.012f
float heightLeft;
float heightRight;
float transLeft = 0.0f;
float transRight = 0.0f;
while( frameNum < walkT )
{
//计算前进时各关节的角度
if( leftTrans )
{
if( mRightWalk ) //右脚前进
{
heightLeft = standingHeight;
heightRight = standingHeight - deltaH;
transLeft = transLen * sin( PI * ( frameNum - deltaN ) / walkT );
transRight = -transLen * sin( PI * ( frameNum - deltaN ) / walkT );
}
else //左脚前进
{
heightLeft = standingHeight - deltaH;
heightRight = standingHeight;
transLeft = -transLen * sin( PI * ( frameNum - deltaN ) / walkT );
transRight = transLen * sin( PI * ( frameNum - deltaN ) / walkT );
}
}
else
{
if( !mRightWalk ) //右脚前进
{
heightLeft = standingHeight;
heightRight = standingHeight - deltaH;
transLeft = transLen * sin( PI * ( frameNum - deltaN ) / walkT );
transRight = -transLen * sin( PI * ( frameNum - deltaN ) / walkT );
}
else //左脚前进
{
heightLeft = standingHeight - deltaH;
heightRight = standingHeight;
transLeft = -transLen * sin( PI * ( frameNum - deltaN ) / walkT );
transRight = transLen * sin( PI * ( frameNum - deltaN ) / walkT );
}
}
ComputeCrazyTrans(thighLen,shankLen,0.0f,0.0f,heightLeft,heightRight,transLeft, transRight,frameNum, mRightWalk, leftTrans );
frameNum ++ ;
}
mRightWalk = !mRightWalk;
lastTransLen = transLen;
return true;
}
void Action::ComputeCrazyTrans(float l1,float l2,float m1,float m2,float h1,float h2, float transLeft, float transRight, int num, bool leftWalk, bool leftTrans )
{
float l_1_2 = l1 * l1;
float l_2_2 = l2 * l2;
float h_1_2 = h1 * h1;
float h_2_2 = h2 * h2;
float m_1_2 = m1 * m1;
float m_2_2 = m2 * m2;
float lLeg_1 = 0.0f;
float lLeg_2 = 0.0f;
float lLeg_3 = 0.0f;
float lLeg_4 = 0.0f;
float lLeg_5 = 0.0f;
float lLeg_6 = 0.0f;
float lArm_1 = -115.0f; //-115.0f;
float lArm_2 = 0.0f; //0.0f;
float lArm_3 = -85.0f; //-85.0f;
float lArm_4 = -85.0f; //-85.0f;
float rLeg_1 = 0.0f;
float rLeg_2 = 0.0f;
float rLeg_3 = 0.0f;
float rLeg_4 = 0.0f;
float rLeg_5 = 0.0f;
float rLeg_6 = 0.0f;
float rArm_1 = -115.0f; //-115.0f;
float rArm_2 = 0.0f; //0.0f;
float rArm_3 = 85.0f; //85.0f;
float rArm_4 = 85.0f; //85.0f;
//0.59版机器人 腿部第二、三关节有交换
lLeg_3 = 180.0f * (asin((l_2_2-l_1_2-h_1_2-m_1_2)/(2*l1*sqrt(h_1_2+m_1_2)))+atan(h1/m1))/PI;
lLeg_5 = 180.0f * (PI-asin((l_2_2-l_1_2+h_1_2+m_1_2)/(2*l2*sqrt(h_1_2+m_1_2)))-atan(h1/m1))/PI;
lLeg_4 = -1.0f * ( lLeg_5 + lLeg_3 );
rLeg_3 = 180.0f * (asin((l_2_2-l_1_2-h_2_2-m_2_2)/(2*l1*sqrt(h_2_2+m_2_2)))+atan(h2/m2))/PI;
rLeg_5 = 180.0f * (PI-asin((l_2_2-l_1_2+h_2_2+m_2_2)/(2*l2*sqrt(h_2_2+m_2_2)))-atan(h2/m2))/PI;
rLeg_4 = -1.0f * ( rLeg_5 + rLeg_3 );
if( leftTrans )
{
lLeg_2 = 180.0f * atan( transLeft / h1 ) + 10.0f;
rLeg_2 = 180.0f * atan( transRight / h2 ) + 10.0f;
}
else
{
lLeg_2 = 180.0f * atan( transLeft / h1 ) - 10.0f;
rLeg_2 = 180.0f * atan( transRight / h2 ) - 10.0f;
}
lLeg_6 = - lLeg_2;
rLeg_6 = - rLeg_2;
if( leftWalk )
{
lArm_1 = -115.0f + 20 * sin( PI * num / mWalkFrameNum );
rArm_1 = -115.0f - 20 * sin( PI * num / mWalkFrameNum );
}
else
{
lArm_1 = -115.0f - 20 * sin( PI * num / mWalkFrameNum );
rArm_1 = -115.0f + 20 * sin( PI * num / mWalkFrameNum );
}
Joint tempJoints;
tempJoints.joint[Head_1] = 0.0f;
tempJoints.joint[Head_2] = 0.0f;
tempJoints.joint[LARM_1] = lArm_1;
tempJoints.joint[RARM_1] = rArm_1;
tempJoints.joint[LARM_2] = lArm_2;
tempJoints.joint[RARM_2] = rArm_2;
tempJoints.joint[LARM_3] = lArm_3;
tempJoints.joint[RARM_3] = rArm_3;
tempJoints.joint[LARM_4] = lArm_4;
tempJoints.joint[RARM_4] = rArm_4;
tempJoints.joint[LLEG_1] = lLeg_1;
tempJoints.joint[RLEG_1] = rLeg_1;
tempJoints.joint[LLEG_2] = lLeg_2;
tempJoints.joint[RLEG_2] = rLeg_2;
tempJoints.joint[LLEG_3] = lLeg_3;
tempJoints.joint[RLEG_3] = rLeg_3;
tempJoints.joint[LLEG_4] = lLeg_4;
tempJoints.joint[RLEG_4] = rLeg_4;
tempJoints.joint[LLEG_5] = lLeg_5;
tempJoints.joint[RLEG_5] = rLeg_5;
tempJoints.joint[LLEG_6] = lLeg_6;
tempJoints.joint[RLEG_6] = rLeg_6;
mJoint->SetJointAngle( CP_Normal, tempJoints );
}
// 稳定值: 0.001f
void Action::SteadyTrans( float transLen )
{
ActLog << "SteadyTrans " << endl;
mJoint->ClearJoint();
int walkT = 8;
int frameNum = 0;
int deltaN;
int deltaT = walkT / 4;
float forLen = 0.0f;
float turnAng = 0.0f;
if ( forLen >= 0.0f )
{
deltaN = walkT / 4;
}
else
{
deltaN = walkT * 3 / 4;
}
const float thighLen = 0.14f;
const float shankLen = 0.11f;
const float footLen = 0.16f;
const float standingHeight = 0.18f ;// v0.59 - 0.18f; // v0.58 - 0.204
float stepLen = fabs(forLen); //0.015f
float tempLen = stepLen * 0.9f; //0.9f
float heightLeft;
float heightRight;
float stepLeft;
float stepRight;
float turnLeft;
float turnRight;
float transLeft;
float transRight;
float deltaH = 0.0072f;// v0.58 - 0.012f // v0.59 - 0.0072f; //0.01f //0.012f //0.015f
while( frameNum < walkT )
{
//计算前进时各关节的角度
if( frameNum >= 0 && frameNum <= 0.5 * walkT - 1)
{
heightLeft = standingHeight;
heightRight = standingHeight - deltaH;
stepLeft = stepLen + tempLen * sin( 2 * PI * ( frameNum - deltaN ) / walkT );
stepRight = stepLen - tempLen * sin( 2 * PI * ( frameNum - deltaN ) / walkT );
if( turnAng > 0.0f )
{
turnLeft = 0.0f;
turnRight = -turnAng + turnAng * sin( 2 * PI * ( frameNum - deltaN ) / walkT );
}
else
{
turnLeft = turnAng - turnAng * sin( 2 * PI * ( frameNum + deltaN ) / walkT );
turnRight = 0.0f;
}
}
else
{
heightLeft = standingHeight - deltaH;
heightRight = standingHeight;
stepLeft = stepLen + tempLen * sin( 2 * PI * ( frameNum - deltaN ) / walkT );
stepRight = stepLen - tempLen * sin( 2 * PI * ( frameNum - deltaN ) / walkT );
if( turnAng > 0.0f )
{
turnLeft = -turnAng + turnAng * sin( 2 * PI * ( frameNum - deltaN ) / walkT );
turnRight = 0.0f;
}
else
{
turnLeft = 0.0f;
turnRight = turnAng - turnAng * sin( 2 * PI * ( frameNum + deltaN ) / walkT );
}
}
transLeft = transLen * sin( 2 * PI * ( frameNum - deltaN ) / walkT );
transRight = -transLen * sin( 2 * PI * ( frameNum - deltaN ) / walkT );
ComputeTransAngle(thighLen,shankLen,stepLeft,stepRight,heightLeft,heightRight,turnLeft,turnRight,transLeft,transRight,frameNum);
frameNum ++ ;
}
}
void Action::ComputeTransAngle(float l1,float l2,float m1,float m2,float h1,float h2,float turnLeft,float turnRight,float transLeft,float transRight,int num)
{
float l_1_2 = l1 * l1;
float l_2_2 = l2 * l2;
float h_1_2 = h1 * h1;
float h_2_2 = h2 * h2;
float m_1_2 = m1 * m1;
float m_2_2 = m2 * m2;
float lLeg_1 = 0.0f;
float lLeg_2 = 0.0f;
float lLeg_3 = 0.0f;
float lLeg_4 = 0.0f;
float lLeg_5 = 0.0f;
float lLeg_6 = 0.0f;
float lArm_1 = -115.0f; //-115.0f;
float lArm_2 = 0.0f; //0.0f;
float lArm_3 = -85.0f; //-85.0f;
float lArm_4 = -85.0f; //-85.0f;
float rLeg_1 = 0.0f;
float rLeg_2 = 0.0f;
float rLeg_3 = 0.0f;
float rLeg_4 = 0.0f;
float rLeg_5 = 0.0f;
float rLeg_6 = 0.0f;
float rArm_1 = -115.0f; //-115.0f;
float rArm_2 = 0.0f; //0.0f;
float rArm_3 = 85.0f; //85.0f;
float rArm_4 = 85.0f; //85.0f;
//0.59版机器人 腿部第二、三关节有交换
lLeg_3 = 180.0f * (asin((l_2_2-l_1_2-h_1_2-m_1_2)/(2*l1*sqrt(h_1_2+m_1_2)))+atan(h1/m1))/PI;
lLeg_5 = 180.0f * (PI-asin((l_2_2-l_1_2+h_1_2+m_1_2)/(2*l2*sqrt(h_1_2+m_1_2)))-atan(h1/m1))/PI;
lLeg_4 = -1.0f * ( lLeg_5 + lLeg_3 );
rLeg_3 = 180.0f * (asin((l_2_2-l_1_2-h_2_2-m_2_2)/(2*l1*sqrt(h_2_2+m_2_2)))+atan(h2/m2))/PI;
rLeg_5 = 180.0f * (PI-asin((l_2_2-l_1_2+h_2_2+m_2_2)/(2*l2*sqrt(h_2_2+m_2_2)))-atan(h2/m2))/PI;
rLeg_4 = -1.0f * ( rLeg_5 + rLeg_3 );
lLeg_1 = turnRight;
rLeg_1 = turnRight;
lLeg_2 = 180.0f * atan( transLeft / h1 );
lLeg_6 = - lLeg_2;
rLeg_2 = 180.0f * atan( transRight / h2 );
rLeg_6 = - rLeg_2;
lArm_1 = -115.0f + 20 * sin( 2 * PI * num / 8 );
rArm_1 = -115.0f - 20 * sin( 2 * PI * num / 8 );
Joint tempJoints;
tempJoints.joint[Head_1] = 0.0f;
tempJoints.joint[Head_2] = 0.0f;
tempJoints.joint[LARM_1] = lArm_1;
tempJoints.joint[RARM_1] = rArm_1;
tempJoints.joint[LARM_2] = lArm_2;
tempJoints.joint[RARM_2] = rArm_2;
tempJoints.joint[LARM_3] = lArm_3;
tempJoints.joint[RARM_3] = rArm_3;
tempJoints.joint[LARM_4] = lArm_4;
tempJoints.joint[RARM_4] = rArm_4;
tempJoints.joint[LLEG_1] = lLeg_1;
tempJoints.joint[RLEG_1] = rLeg_1;
tempJoints.joint[LLEG_2] = lLeg_2;
tempJoints.joint[RLEG_2] = rLeg_2;
tempJoints.joint[LLEG_3] = lLeg_3;
tempJoints.joint[RLEG_3] = rLeg_3;
tempJoints.joint[LLEG_4] = lLeg_4;
tempJoints.joint[RLEG_4] = rLeg_4;
tempJoints.joint[LLEG_5] = lLeg_5;
tempJoints.joint[RLEG_5] = rLeg_5;
tempJoints.joint[LLEG_6] = lLeg_6;
tempJoints.joint[RLEG_6] = rLeg_6;
mJoint->SetJointAngle( CP_Normal, tempJoints );
}