-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMotionDribble.cpp
More file actions
executable file
·289 lines (227 loc) · 8.3 KB
/
MotionDribble.cpp
File metadata and controls
executable file
·289 lines (227 loc) · 8.3 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
#include "MotionDribble.h"
#define DribbleLog gLog<< "[motion] " << "Dribble "
MotionDribble::MotionDribble( WorldModel *wm, Situation *situ, MotionGoto *mtGoto, CommandQuene *cmdQuene, Action *act )
{
mWorldModel = wm;
mSituation = situ;
mGoto = mtGoto;
mCmdQuene = cmdQuene;
mAct = act;
mDribbleRadius = 0.22f; // waited to be tested
mDribbleAngle = 30.0f; // waited to be tested
mDribbleAngleEps = 5.0f; // waited to be tested
}
MotionDribble::~MotionDribble()
{
}
void MotionDribble::InitDribble()
{
}
bool MotionDribble::Dribble()
{
const float dribbleDist = 1.5f;
Vector3f ultimateTarget = mWorldModel->mOppGoalCenter;
Vector3f dribbleTar = ultimateTarget;
Vector3f sitDribbleTar = ultimateTarget;
static Vector3f lastSitDribbleTar = ultimateTarget;
static Angle lastPreDribbleAngle = 0.0f;
if( !EvaluCurrDribbleTar() )
{
sitDribbleTar = mSituation->DribbleTo( ultimateTarget );
}
else
{
Angle preAngle;
Angle preDribbleAng = mWorldModel->mSelf.mPos.angTheta2( mWorldModel->mBall.mPos );
if( fabs(preDribbleAng - lastPreDribbleAngle) < 10.0f )
{
preAngle = lastPreDribbleAngle;
}
else
{
preAngle = preDribbleAng;
}
lastPreDribbleAngle = preAngle;
Ray preDribbleRay = Ray::MakeRayFromPositionAndAngle( mWorldModel->mSelf.mPos, preAngle );
Vector3f preDribblePos = preDribbleRay.GetPoint( dribbleDist );
sitDribbleTar = preDribblePos;
}
if( sitDribbleTar.distXY2( lastSitDribbleTar ) <= 1.0f )
{
dribbleTar = lastSitDribbleTar;
}
else
{
dribbleTar = sitDribbleTar;
}
if( !InDribbleArea( dribbleTar ) )
{
DribbleLog << " !InDribbleArea " << endl;
//cout << " !InDribbleArea " << endl;
// 虽然不在控球区域,但已瞄准球,仍高速前进
if( InDribbleAngle( dribbleTar )
&& mGoto->FacingTheBall()
&& !mGoto->IsOurPlayerObstacle(dribbleTar)
//&& !mGoto->IsOppPlayerObstacle(dribbleTar)
)
{
DribbleLog << " !InDribbleArea But Dash" << endl;
DribbleTo( dribbleTar );
//cout << " DribbleTo " << endl;
//mGoto->SmartFastGoto( mWorldModel->mBall.mPos, 0.2f );
//mGoto->FastGoto( dribbleTar );
}
else
{
dribbleTar = sitDribbleTar;
GotoDribbleArea( dribbleTar );
}
}
else
{
//mGoto->FastGotoDribble( dribbleTar );
DribbleTo( dribbleTar );
//mGoto->SmartFastGoto( mWorldModel->mBall.mPos, 0.2f );
}
lastSitDribbleTar = sitDribbleTar;
return true;
}
bool MotionDribble::GotoDribbleArea( Vector3f tarVector3f )
{
return mGoto->GotoHandleBall( tarVector3f );
//mGoto->SmartFastGoto( mWorldModel->mBall.mPos, 0.2f );
}
bool MotionDribble::DribbleTo( Vector3f tarVector3f )
{
//mGoto->FastGotoDribble( tarVector3f );
//mGoto->FastGoto( tarVector3f );
//mGoto->SmartFastGoto( mWorldModel->mBall.mPos, 0.2f );
return mGoto->Goto( tarVector3f );
//mGoto->SmartGoto( tarVector3f );
}
bool MotionDribble::InDribbleRadius()
{
Circle dribbleCircle( mWorldModel->mBall.mPos, mDribbleRadius );
return dribbleCircle.isInsideCircle( mWorldModel->mSelf.mPos );
}
bool MotionDribble::InDribbleAngle( Vector3f tarVector3f )
{
Angle advanceAng = ( tarVector3f - mWorldModel->mSelf.mPos ).angTheta();
Angle angBetweenTarAndSelf = advanceAng - mWorldModel->mBodyAngle;
float distToTar = mWorldModel->mSelf.DistXyTo(tarVector3f);
if( fabs(angBetweenTarAndSelf) > Max( mDribbleAngleEps, (float)atan2(mDribbleRadius,distToTar) * 180.0f / PI )
&& fabs(fabs(angBetweenTarAndSelf) - 180.0f )> Max( mDribbleAngleEps, (float)atan2(mDribbleRadius,distToTar) * 180.0f / PI )
)
{
return false;
}
Line dribbleLine = Line::makeLineFromTwoPoints( mWorldModel->mBall.mPos, tarVector3f );
if( dribbleLine.getDistanceWithPoint( mWorldModel->mBall.mPos ) > mDribbleRadius )
{
return false;
}
Circle circleBallAndTar( tarVector3f, mWorldModel->mBall.DistXyTo(tarVector3f) );
if( circleBallAndTar.isInsideCircle( mWorldModel->mSelf.mPos ) )
{
return false;
}
return true;
}
bool MotionDribble::InDribbleAngleAllowBack( Vector3f tarVector3f )
{
Angle advanceAng = ( tarVector3f - mWorldModel->mSelf.mPos ).angTheta();
Angle angBetweenTarAndSelf = advanceAng - mWorldModel->mBodyAngle;
float distToTar = mWorldModel->mSelf.DistXyTo(tarVector3f);
if( fabs(angBetweenTarAndSelf) > Max( mDribbleAngleEps, (float)atan2(mDribbleRadius,distToTar) * 180.0f / PI )
&& fabs( fabs(angBetweenTarAndSelf) - 180.0f ) > Max( mDribbleAngleEps, (float)atan2(mDribbleRadius,distToTar) * 180.0f / PI )
)
{
return false;
}
Line dribbleLine = Line::makeLineFromTwoPoints( mWorldModel->mBall.mPos, tarVector3f );
if( dribbleLine.getDistanceWithPoint( mWorldModel->mBall.mPos ) > mDribbleRadius )
{
return false;
}
Circle circleBallAndTar( tarVector3f, mWorldModel->mBall.DistXyTo(tarVector3f) );
if( circleBallAndTar.isInsideCircle( mWorldModel->mSelf.mPos ) )
{
return false;
}
return true;
}
bool MotionDribble::InDribbleAngleAllowTrans( Vector3f tarVector3f )
{
Angle advanceAng = ( tarVector3f - mWorldModel->mSelf.mPos ).angTheta();
Angle angBetweenTarAndSelf = advanceAng - mWorldModel->mBodyAngle;
float distToTar = mWorldModel->mSelf.DistXyTo(tarVector3f);
if( fabs(angBetweenTarAndSelf) > Max( mDribbleAngleEps, (float)atan2(mDribbleRadius,distToTar) * 180.0f / PI )
&& fabs( fabs(angBetweenTarAndSelf) - 180.0f ) > Max( mDribbleAngleEps, (float)atan2(mDribbleRadius,distToTar) * 180.0f / PI )
&& fabs( fabs(angBetweenTarAndSelf) - 90.0f ) > Max( mDribbleAngleEps, (float)atan2(mDribbleRadius,distToTar) * 180.0f / PI )
&& fabs( fabs(angBetweenTarAndSelf) + 90.0f ) > Max( mDribbleAngleEps, (float)atan2(mDribbleRadius,distToTar) * 180.0f / PI )
)
{
return false;
}
Line dribbleLine = Line::makeLineFromTwoPoints( mWorldModel->mBall.mPos, tarVector3f );
if( dribbleLine.getDistanceWithPoint( mWorldModel->mBall.mPos ) > mDribbleRadius )
{
return false;
}
Circle circleBallAndTar( tarVector3f, mWorldModel->mBall.DistXyTo(tarVector3f) );
if( circleBallAndTar.isInsideCircle( mWorldModel->mSelf.mPos ) )
{
return false;
}
return true;
}
bool MotionDribble::InDribbleArea( Vector3f tarVector3f )
{
//return InDribbleRadius() && InDribbleAngleAllowTrans( tarVector3f );
//return InDribbleRadius() && InDribbleAngleAllowBack( tarVector3f );
float distToBall = ( mWorldModel->mSelf.DistXyTo( mWorldModel->mBall.mPos) );
float angleToBall = Normalize( mWorldModel->mBodyAngle - (mWorldModel->mBall.mPos - mWorldModel->mSelf.mPos).angTheta() );
float xDistToBall = -distToBall * cos( angleToBall * PI / 180.0f );
float yDistToBall = distToBall * sin( angleToBall * PI / 180.0f );
const float bodyRadius = 0.5f;
const float xDistEps = 0.11f;
DribbleLog << " DribbleArea "<< xDistToBall << " " << yDistToBall << " " << angleToBall << endl;
if( fabs(xDistToBall) > xDistEps )
{
DribbleLog << "fabs(xDistToBall) > xDistEps " << endl;
return false;
}
if( fabs(yDistToBall) > bodyRadius )
{
DribbleLog << "fabs(yDistToBall) > bodyRadius " << endl;
return false;
}
//return InDribbleAngleAllowTrans(tarVector3f) && InDribbleRadius();
return InDribbleRadius() && InDribbleAngle( tarVector3f );
}
bool MotionDribble::EvaluCurrDribbleTar()
{
const float dribbleDist = 1.5f;
Angle preDribbleAng = mWorldModel->mSelf.mPos.angTheta2( mWorldModel->mBall.mPos );
Ray preDribbleRay = Ray::MakeRayFromPositionAndAngle( mWorldModel->mSelf.mPos, preDribbleAng );
Vector3f preDribblePos = preDribbleRay.GetPoint( dribbleDist );
Vector3f currBallPos = mWorldModel->mBall.mPos;
Angle preDriToOppGoalLeft = preDribblePos.angTheta2( mWorldModel->mFieldGoal[GOAL_OPP_LEFT].mPos );
Angle preDriToOppGoalRight = preDribblePos.angTheta2( mWorldModel->mFieldGoal[GOAL_OPP_RIGHT].mPos );
Angle currDriToOppGoalLeft = currBallPos.angTheta2( mWorldModel->mFieldGoal[GOAL_OPP_LEFT].mPos );
Angle currDriToOppGoalRight = currBallPos.angTheta2( mWorldModel->mFieldGoal[GOAL_OPP_RIGHT].mPos );
Angle preDiffAng = preDriToOppGoalLeft - preDriToOppGoalRight;
Angle currDiffAng = currDriToOppGoalLeft - currDriToOppGoalRight;
if( !mSituation->IsTarInField(preDribblePos) )
{
return false;
}
else if( preDiffAng <= currDiffAng )
{
return true;
}
else
{
return false;
}
}