⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 worldmodel.cpp

📁 根据 trilearn_base_sources-3.3 (一般称做UVA底层)修改的robocup球队代码,对某些模块进行了详细的注释(例如BasicPlayer,WorldMode模块),并且进行
💻 CPP
📖 第 1 页 / 共 5 页
字号:
//  g : 需要搜寻的对象集合//  dConf : 可信度阀值(搜寻的就是第一个可信度大于dConf的点)/*  //附:对象集合 的 枚举类型  OBJECT_SET_TEAMMATES,           //我方队友                      OBJECT_SET_OPPONENTS,           //敌方队员                      OBJECT_SET_PLAYERS,             //球员                         OBJECT_SET_TEAMMATES_NO_GOALIE, //不包括守门员的队友             OBJECT_SET_FLAGS,               //标志(旗帜)                  OBJECT_SET_LINES,               //边界线                       OBJECT_SET_ILLEGAL              //无效/错误的                 */ObjectT WorldModel::iterateObjectStart(int& iIndex,ObjectSetT g,double dConf,                       bool bForward){  iIndex = -1;  return iterateObjectNext( iIndex, g, dConf, bForward );}/*!This method gets the next object in the iteration over an object set g.   iterateObjectStart should have been called first. Only ObjectT with a   confidence higher than dConf will be returned. When no more objects are   available OBJECT_ILLEGAL is returned.   \param iIndex same argument as was supplied to iterateObjectStart.   \param g ObjectSetT of which the ObjecT should be returned.   \param dConf minimum confidence needed for ObjectT to be returned.   \return ObjectT that is next in the set g. *///  返回对象集合中下一个可信度超过dConf的物体ObjectT WorldModel::iterateObjectNext(int& iIndex,ObjectSetT g, double dConf,                      bool bForward){  ObjectT o, objGoalie = OBJECT_TEAMMATE_1;  bool bContinue = true;    if( g == OBJECT_SET_TEAMMATES_NO_GOALIE )    objGoalie = getOwnGoalieType();   //我方守门员      if( iIndex < 0 )    iIndex = (bForward==false) ? OBJECT_MAX_OBJECTS : -1 ;  // when dConf is not specified it has the default value of -1.0, in this  // case set it to the confidence threshold defined in PlayerSetting, but  // only do this for dynamic objects, not for flags, lines, etc. since all  // should be returend.  // 只返回动态对象的可信度,静态对象不返回  if( dConf == -1.0 && (g==OBJECT_SET_OPPONENTS || g==OBJECT_SET_PLAYERS ||                        g==OBJECT_SET_TEAMMATES) )    dConf = PS->getPlayerConfThr();  int i = 0;  if( bForward == true )    i = iIndex + 1;  else    i = iIndex - 1;  bContinue = ( bForward == false ) ? ( i >= 0 ) : ( i < OBJECT_MAX_OBJECTS );   //循环遍历?  while( bContinue )  {    o = (ObjectT) i;    if( SoccerTypes::isInSet( o, g, objGoalie ) )    {      if( getConfidence( o ) >= dConf )      {        //当可信度高的时候,索引值改变        iIndex = i;        return o;      }      else if( dConf == 1.0 && getTimeLastSeeMessage() == getTimeLastSeen( o ))      {        //只有在当前周期看到球员的时候,可信度才可能为1.0        iIndex = i; // confidence of 1.0 can only be in same cycle as see        return o;   // message. Therefore first test should succeed normally;      }             // in cases where this method is called after see message,                    // but new sense has already arrived, confidence is lowered    }               // but we want to return object that was seen in last see                    // message; this compensates for those cases.    if( bForward == true )      i++;    else      i--;    bContinue = ( bForward == false ) ? ( i >= 0 ) :( i < OBJECT_MAX_OBJECTS);   }  return OBJECT_ILLEGAL;}/*!This method finsished the iteration. It should be called after   iterateObjectNext has returned OBJECT_ILLEGAL indicating no more objects are   available that satisfy the constraints.   \param iIndex index of iteration *///  ilndex置-1,用于结束iterateObjectStart/iterateObjectNextvoid WorldModel::iterateObjectDone( int &iIndex ){  iIndex = -1;}/*! This method returns the ObjectType of the agent. This    is an ObjectT between OBJECT_TEAMMATE_1 and OBJECT_TEAMMATE_11    \return ObjectT that represent the type of the agent  *///AGENT的对象类型ObjectT WorldModel::getAgentObjectType( ) const{  return agentObject.getType();}//得到Agent的索引值int WorldModel::getAgentIndex( ) const{  return SoccerTypes::getIndex( getAgentObjectType() );}/*! This method sets the ObjectType of the agent. This    is an objectT between OBJECT_TEAMMATE_1 and OBJECT_TEAMMATE_11    \param ObjectT that represent the type of the agent    \return bool indicating whether the update was succesful *///设置Agent的对象类型bool WorldModel::setAgentObjectType( ObjectT o ){  agentObject.setType( o );  return true;}/*! This method returns the body angle relative to the neck of the agent.    \return AngDeg representing the body angle relative to the neck *///返回agent的身体相对于脖子的角度AngDeg WorldModel::getAgentBodyAngleRelToNeck( ) const{  return agentObject.getBodyAngleRelToNeck();}/*! This method returns the global neck angle of the agent in the world.    \return global neck angle agent *///返回脖子的绝对角度AngDeg WorldModel::getAgentGlobalNeckAngle(  ) const{  return agentObject.getGlobalNeckAngle(  );}/*! This method returns the global body angle of the agent in the world.    \return global body angle agent *///返回agent的身体的绝对角度AngDeg WorldModel::getAgentGlobalBodyAngle(  ){  return agentObject.getGlobalBodyAngle(  );}/*! This method returns the stamina information of the agent    \return Stamina stamina of the agent *///获得球员的体力Stamina WorldModel::getAgentStamina( ) const{  return agentObject.getStamina();}/*! This method returns a TiredNessT value that indicates how tired the agent   is.     \return TiredNessT value that indicates how tired the agent is. *///返回agent的疲劳指数/*  TIREDNESS_ILLEGAL,     * 无效                                    *  TIREDNESS_GOOD,        * 一点都不疲劳                             *  TIREDNESS_AVERAGE,     * 体力处于平均位置                          *  TIREDNESS_BAD,         * 球员开始疲劳                             *  TIREDNESS_VERY_BAD,    * 疲劳到难以移动了                          *  TIREDNESS_TERRIBLE     * 疲劳到无法移动了                          **/TiredNessT WorldModel::getAgentTiredNess( ) const{  return getAgentStamina().getTiredNess(                      SS->getRecoverDecThr(), SS->getStaminaMax() );}/*! This method returns the effort information of the agent    \return double effort of the agent *///返回当前 agent 的体力利用率double WorldModel::getAgentEffort( ) const{  return agentObject.getStamina().getEffort();}/*! This method returns the global velocity information of the agent    \return global velocity of the agent *///返回绝对速度(为一个向量)VecPosition WorldModel::getAgentGlobalVelocity( ) const{  return agentObject.getGlobalVelocity();}/*! This method returns the speed of the agent    \return speed of the agent *///返回agent的速度double WorldModel::getAgentSpeed( ) const{  return agentObject.getSpeed();}/*! This method returns the global position of the agent    \return global position of the agent *///绝对位置VecPosition WorldModel::getAgentGlobalPosition( ) const{  return agentObject.getGlobalPosition();}/*! This method sets the view angle of the agent.    \return bool indicating whether update was successful.  *///设置agent的视觉角度/*  附:视觉范围的枚举:  VA_NARROW,    // 窄范围  VA_NORMAL,    // 普通范围  VA_WIDE,      // 广范围  VA_ILLEGAL    // 无效范围  需要注意的是,视觉的范围增广,会导致视觉质量下降*/bool WorldModel::setAgentViewAngle( ViewAngleT va ) {  agentObject.setViewAngle( va );  return true;}/*! This method returns the view angle of the agent.      \return ViewAngleT view angle of the agent (VA_NARROW, VA_NORMAL,    VA_WIDE)*///接收agent的视觉角度ViewAngleT WorldModel::getAgentViewAngle( ) const{  return agentObject.getViewAngle();}/*! This method sets the view quality of the agent.    \return bool indicating whether update was successful.  *///设置视觉质量/*  视觉质量的枚举:  VQ_HIGH,       // 视觉质量高      VQ_LOW,        // 视觉质量低      VQ_ILLEGAL     // 无效的质量    */bool WorldModel::setAgentViewQuality( ViewQualityT vq ) {  agentObject.setViewQuality( vq );  return true;}/*! This method returns the view quality of the agent    \return ViewQualityT of the agent (VA_LOW, VA_HIGH). *///返回视觉质量ViewQualityT WorldModel::getAgentViewQuality( ) const{  return agentObject.getViewQuality();}/*! This method returns the view frequency of see messages for the agent    relative to the time of the sense_body interval. So 0.5 means a see    message arrives twice in every simulation cycle.    \return double representing the view frequency *///返回Agent的视觉频率//这个频率是相对于身体感觉间隔时间的,就是说0.5表示一个仿真周期内我们获得两次视觉信息double WorldModel::getAgentViewFrequency( ViewAngleT va, ViewQualityT vq ){  double dViewQualityFactor ;  double dViewWidthFactor   ;  //非法视觉角度和质量  if( va == VA_ILLEGAL )    va = getAgentViewAngle();  if( vq == VQ_ILLEGAL )    vq = getAgentViewQuality();  switch( va )  {     //视觉角度的类型    case VA_NARROW:  dViewWidthFactor   = 0.5; break;    case VA_NORMAL:  dViewWidthFactor   = 1.0; break;    case VA_WIDE:    dViewWidthFactor   = 2.0; break;    case VA_ILLEGAL:    default:         dViewWidthFactor   = 0.0; break;  }  switch( vq )  {    //视觉质量的类型    case VQ_LOW:     dViewQualityFactor = 0.5; break;    case VQ_HIGH:    dViewQualityFactor = 1.0; break;    case VQ_ILLEGAL:    default:         dViewQualityFactor = 0.0; break;  }  //获得最终的返回值  //一般来说普通视觉角度高视觉质量可以每个周期获得一次视觉信息  return dViewQualityFactor*dViewWidthFactor;}/*! This method returns whether the arm of the agent can be moved. *///胳膊是否能移动bool WorldModel::getAgentArmMovable( ){  return agentObject.getArmMovable();}/*! This method returns the current position the arm of the agent is     pointing towards. *///接受当前agent胳膊的位置VecPosition WorldModel::getAgentArmPosition( ){  return agentObject.getGlobalArmPosition();}/*! This method returns how many cycles it will last before the arm    of the agent stops pointing. *///返回Agent的指向动作所持续的周期数int WorldModel::getAgentArmExpires( ){  return agentObject.getArmExpires();}/*! This method returns the global position of the ball. The method    getConfidence with as argument OBJECT_BALL should be called to check the    confidence of this global position.    \return global position bal. *///返回球的位置VecPosition  WorldModel::getBallPos(){  return getGlobalPosition( OBJECT_BALL );}/*! This method returns the current estimate of the speed of the ball.    \return speed of the ball (magnitude of the global velocity vector). *///返回当前球速double WorldModel::getBallSpeed(){  return Ball.getGlobalVelocity().getMagnitude();}/*! This method returns the global direction of the ball velocity.    \return global direction of the ball velocity *///返回当前球速的方向AngDeg WorldModel::getBallDirection()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -