第一步:
在三个不同文件夹中
在roboviz文件夹中用./roboviz.sh(打开模拟器)
在SIMSPARK_0.3.1_RELEASE中用rcsss用Tab补齐可以打开球场
在代码文件夹中用。./start.h可以上场球员
首先看了worldmodel里面的函数和变量
这里就简述下个人认为比较有用的一些函数
getUNum()//获取当前球员的号码
getLastSkill()//获得上一次策略
worldModel->getOpponent(i)//{用循环遍历得到对方球员的位置}
SkillType kickBall(kickTypeToUse,VecPosition,&target);//动作踢球
getFallenTeammate() //判断摔倒队友的编号
getBall()//获取球的位置
collisionAvoidance()//避免碰撞
getGameTime()//获取比赛时间
getPalyMode()//获取比赛状态
SkillType goToTargetRelative(相对球员方向,角度)//指定当前球员行动方向
wordModel->getTeammate(i) //(i为我方球员编号) 获取指定球员坐标
Temp.getDistanceTo(VecPosition(x,y,0)) //判断球员于目标距离
写策略的话要用在这个文件夹里面strategy.cc
然后可以根据场上不同形式可以在selectSkill()来选择写完的策略
这边就简单写了个11号直接冲的代码
SkillType NaoBehavior::demokick(){
if(worldModel->getUNum()==11){
return kickBall(KICK_11M,VecPosition(HALF_FIELD_X,0,0));
}
else return SKILL_STAND;
}
这里的官方的代码加上自己的部分注释
SkillType NaoBehavior::demoKickingCircle() {
// Parameters for circle
VecPosition center = VecPosition(-HALF_FIELD_X/2.0, 0, 0);//确定球门位置
double circleRadius = 5.0;
double rotateRate = 2.5;
// Find closest player to ball
int playerClosestToBall = -1;
double closestDistanceToBall = 10000;
for(int i = WO_TEAMMATE1; i < WO_TEAMMATE1+NUM_AGENTS; ++i) {
VecPosition temp;
int playerNum = i - WO_TEAMMATE1 + 1;
if (worldModel->getUNum() == playerNum) {
// This is us
temp = worldModel->getMyPosition();
} else {
WorldObject* teammate = worldModel->getWorldObject( i );
if (teammate->validPosition) {
temp = teammate->pos;
} else {
continue;
}
}
temp.setZ(0);
double distanceToBall = temp.getDistanceTo(ball);
if (distanceToBall < closestDistanceToBall) {
playerClosestToBall = playerNum;
closestDistanceToBall = distanceToBall;
}//判断离球最近的球员编号
}
if (playerClosestToBall == worldModel->getUNum()) {
// Have closest player kick the ball toward the center
if(agentBodyType==0){//此类型机器人还未加入长踢
return kickBall(KICK_FORWARD,center);
}//让最近的人踢球
return kickBall(KICK_8M, center);
} else {
// Move to circle position around center and face the center
VecPosition localCenter = worldModel->g2l(center);
SIM::AngDeg localCenterAngle = atan2Deg(localCenter.getY(), localCenter.getX());
// Our desired target position on the circle
// Compute target based on uniform number, rotate rate, and time
VecPosition target = center + VecPosition(circleRadius,0,0).rotateAboutZ(360.0/(NUM_AGENTS-1)*(worldModel->getUNum()-(worldModel->getUNum() > playerClosestToBall ? 1 : 0)) + worldModel->getTime()*rotateRate);
// Adjust target to not be too close to teammates or the ball
target = collisionAvoidance(true /*teammate*/, false/*opponent*/, true/*ball*/, 1/*proximity thresh*/, .5/*collision thresh*/, target, true/*keepDistance*/);
if (me.getDistanceTo(target) < .25 && abs(localCenterAngle) <= 10) {
// Close enough to desired position and orientation so just stand
return SKILL_STAND;
} else if (me.getDistanceTo(target) < .5) {
// Close to desired position so start turning to face center
return goToTargetRelative(worldModel->g2l(target), localCenterAngle);
} else {
// Move toward target location
return goToTarget(target);
}
}
}