00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00046 #include"Objects.h"
00047
00048 #include<stdlib.h>
00049 #include<iostream>
00050 #ifdef Solaris
00051 #include <strings.h>
00052 #else
00053 #include <string.h>
00054 #endif
00055
00056
00057
00058
00059
00062 Object::Object( )
00063 {
00064 objectType = OBJECT_ILLEGAL;
00065 }
00066
00070 AngDeg Object::getRelativeAngle( )
00071 {
00072 return VecPosition::normalizeAngle(posRelative.getDirection());
00073 }
00074
00078 double Object::getRelativeDistance( )
00079 {
00080 return posRelative.getMagnitude();
00081 }
00082
00088 double Object::getConfidence( Time time )
00089 {
00090 if( timeLastSeen.getTime() == -1 )
00091 return 0.0;
00092 double dConf =
00093 max( 0.0, 1.0-(double)(time.getTimeDifference(timeLastSeen))/100.0);
00094 if( dConf > 1.0 )
00095 return 0.0;
00096 return dConf;
00097 }
00098
00099
00103 bool Object::setType( ObjectT o )
00104 {
00105 objectType = o;
00106 return true;
00107 }
00108
00111 ObjectT Object::getType() const
00112 {
00113 return objectType;
00114 }
00115
00123 bool Object::setRelativePosition( double dDist, AngDeg ang, Time time )
00124 {
00125 posRelative.setVecPosition( dDist, ang, POLAR );
00126 setTimeRelativePosition( time );
00127 return true;
00128 }
00129
00135 bool Object::setRelativePosition( VecPosition v, Time time )
00136 {
00137 posRelative = v;
00138 setTimeRelativePosition( time );
00139 return true;
00140 }
00141
00147 VecPosition Object::getRelativePosition() const
00148 {
00149 return posRelative;
00150 }
00151
00155 bool Object::setTimeRelativePosition( Time time )
00156 {
00157 timeRelativePosition = time;
00158 return true;
00159 }
00160
00164 Time Object::getTimeRelativePosition() const
00165 {
00166 return timeRelativePosition;
00167 }
00168
00174 bool Object::setGlobalPosition( VecPosition p, Time time )
00175 {
00176 posGlobal = p;
00177 setTimeGlobalPosition( time );
00178 return true;
00179 }
00180
00186 VecPosition Object::getGlobalPosition() const
00187 {
00188 return posGlobal;
00189 }
00190
00194 bool Object::setTimeGlobalPosition( Time time )
00195 {
00196 timeGlobalPosition = time;
00197 return true;
00198 }
00199
00203 Time Object::getTimeGlobalPosition() const
00204 {
00205 return timeGlobalPosition;
00206 }
00207
00215 bool Object::setGlobalPositionLastSee( VecPosition p, Time time )
00216 {
00217 posGlobalLastSee = p;
00218 setTimeGlobalPosDerivedFromSee( time );
00219 return true;
00220 }
00221
00226 VecPosition Object::getGlobalPositionLastSee() const
00227 {
00228 return posGlobalLastSee;
00229 }
00230
00235 bool Object::setTimeGlobalPosDerivedFromSee( Time time )
00236 {
00237 timeGlobalPosDerivedFromSee = time;
00238 return true;
00239 }
00240
00244 Time Object::getTimeGlobalPosDerivedFromSee() const
00245 {
00246 return timeGlobalPosDerivedFromSee;
00247 }
00248
00253 bool Object::setTimeLastSeen( Time time)
00254 {
00255 timeLastSeen = time;
00256 return true;
00257 }
00258
00262 Time Object::getTimeLastSeen() const
00263 {
00264 return timeLastSeen;
00265 }
00266
00267
00268
00269
00270
00271
00275 void FixedObject::show( ostream & os )
00276 {
00277 char buf[MAX_TEAM_NAME_LENGTH];
00278
00279
00280 SoccerTypes::getObjectStr( buf, objectType, DEFAULT_TEAM_NAME );
00281 os << buf
00282 << " rel(" << posRelative << " r:" << posRelative.getMagnitude()
00283 << " phi:" << posRelative.getDirection()
00284 << " t:" << timeRelativePosition << ")"
00285 << " seen:" << timeLastSeen << "\n";
00286 }
00287
00296 VecPosition FixedObject::getGlobalPosition( SideT s, double dGoalWidth )const
00297 {
00298 return SoccerTypes::getGlobalPositionFlag( getType(), s, dGoalWidth );
00299 }
00300
00307 AngDeg FixedObject::getGlobalAngle( SideT s )
00308 {
00309 return SoccerTypes::getGlobalAngleLine( getType(), s );
00310 }
00311
00312
00313
00314
00315
00318 DynamicObject::DynamicObject( ):Object( )
00319 {
00320 dRelativeDistanceChange = UnknownDoubleValue;
00321 dRelativeAngleChange = UnknownDoubleValue;
00322 }
00323
00329 bool DynamicObject::setGlobalVelocity( VecPosition v, Time time)
00330 {
00331 if( v.getMagnitude() < EPSILON )
00332 vecGlobalVelocity.setVecPosition( 0.0, 0.0 );
00333 else
00334 vecGlobalVelocity = v;
00335 setTimeGlobalVelocity( time );
00336 return true;
00337 }
00338
00342 VecPosition DynamicObject::getGlobalVelocity( ) const
00343 {
00344 return vecGlobalVelocity;
00345 }
00346
00350 double DynamicObject::getSpeed( ) const
00351 {
00352 return vecGlobalVelocity.getMagnitude();
00353 }
00354
00359 bool DynamicObject::setTimeGlobalVelocity( Time time )
00360 {
00361 timeGlobalVelocity = time;
00362 return true;
00363 }
00364
00368 Time DynamicObject::getTimeGlobalVelocity() const
00369 {
00370 return timeGlobalVelocity;
00371 }
00372
00373
00379 bool DynamicObject::setRelativeDistanceChange( double d, Time time )
00380 {
00381 dRelativeDistanceChange = d;
00382 setTimeChangeInformation( time );
00383 return true;
00384 }
00385
00392 double DynamicObject::getRelativeDistanceChange() const
00393 {
00394 return dRelativeDistanceChange;
00395 }
00396
00402 bool DynamicObject::setRelativeAngleChange( double d, Time time )
00403 {
00404 dRelativeAngleChange = d;
00405 setTimeChangeInformation( time );
00406 return true;
00407 }
00408
00413 double DynamicObject::getRelativeAngleChange() const
00414 {
00415 return dRelativeAngleChange;
00416 }
00417
00421 bool DynamicObject::setTimeChangeInformation( Time time )
00422 {
00423 timeChangeInformation = time ;
00424 return true;
00425 }
00426
00430 Time DynamicObject::getTimeChangeInformation() const
00431 {
00432 return timeChangeInformation;
00433 }
00434
00439 bool DynamicObject::setGlobalVelocityLastSee ( VecPosition vec )
00440 {
00441 vecGlobalVelocityLastSee = vec;
00442 return true;
00443 }
00444
00449 VecPosition DynamicObject::getGlobalVelocityLastSee ( ) const
00450 {
00451 return vecGlobalVelocityLastSee;
00452 }
00453
00454
00455
00456
00457
00458
00461 PlayerObject::PlayerObject( ):DynamicObject( )
00462 {
00463 angGlobalBodyAngle = UnknownAngleValue;
00464 angGlobalNeckAngle = UnknownAngleValue;
00465 isKnownPlayer = false;
00466 isGoalie = false;
00467
00468 angRelativeBodyAngle = UnknownAngleValue;
00469 angRelativeNeckAngle = UnknownAngleValue;
00470
00471 iHeteroPlayerType = 0;
00472 }
00473
00479 bool PlayerObject::setRelativeBodyAngle( AngDeg ang, Time time )
00480 {
00481 angRelativeBodyAngle = ang;
00482 setTimeRelativeAngles( time );
00483 return true;
00484 }
00485
00491 AngDeg PlayerObject::getRelativeBodyAngle( ) const
00492 {
00493 return angRelativeBodyAngle;
00494 }
00495
00501 bool PlayerObject::setGlobalBodyAngle( AngDeg ang, Time time)
00502 {
00503 angGlobalBodyAngle = ang;
00504 setTimeGlobalAngles( time );
00505 return true;
00506 }
00507
00511 AngDeg PlayerObject::getGlobalBodyAngle( ) const
00512 {
00513 return angGlobalBodyAngle;
00514 }
00515
00521 bool PlayerObject::setRelativeNeckAngle( AngDeg ang, Time time )
00522 {
00523 angRelativeNeckAngle = ang;
00524 setTimeRelativeAngles( time );
00525 return true;
00526 }
00527
00531 AngDeg PlayerObject::getRelativeNeckAngle( ) const
00532 {
00533 return angRelativeNeckAngle;
00534 }
00535
00541 bool PlayerObject::setGlobalNeckAngle( AngDeg ang, Time time )
00542 {
00543 angGlobalNeckAngle = ang;
00544 setTimeGlobalAngles( time );
00545 return true;
00546 }
00547
00551 AngDeg PlayerObject::getGlobalNeckAngle( ) const
00552 {
00553 return angGlobalNeckAngle;
00554 }
00555
00559 bool PlayerObject::setTimeRelativeAngles( Time time )
00560 {
00561 timeRelativeAngles = time;
00562 return true;
00563 }
00564
00568 Time PlayerObject::getTimeRelativeAngles( ) const
00569 {
00570 return timeRelativeAngles ;
00571 }
00572
00576 bool PlayerObject::setTimeGlobalAngles( Time time )
00577 {
00578 timeGlobalAngles = time;
00579 return true;
00580 }
00581
00582
00588 bool PlayerObject::setGlobalBodyAngleLastSee( AngDeg ang )
00589 {
00590 angGlobalBodyAngleLastSee = ang;
00591 return true;
00592 }
00593
00594
00601 AngDeg PlayerObject::getGlobalBodyAngleLastSee( ) const
00602 {
00603 return angGlobalBodyAngleLastSee;
00604 }
00605
00606
00610 Time PlayerObject::getTimeGlobalAngles( ) const
00611 {
00612 return timeGlobalAngles ;
00613 }
00614
00623 bool PlayerObject::setPossibleRange( ObjectT objMin, ObjectT objMax )
00624 {
00625 objRangeMin = objMin;
00626 objRangeMax = objMax;
00627 return true;
00628 }
00629
00634 bool PlayerObject::isInRange( ObjectT obj, bool bTeammatesFirst )
00635 {
00636 int iIndObj = SoccerTypes::getIndex( obj );
00637 int iIndMin = SoccerTypes::getIndex( objRangeMin );
00638 int iIndMax = SoccerTypes::getIndex( objRangeMax );
00639
00640
00641 if( SoccerTypes::isOpponent( obj ) )
00642 iIndObj += ( bTeammatesFirst ) ? 11 : -11 ;
00643 if( SoccerTypes::isOpponent( objRangeMin ) )
00644 iIndMin += ( bTeammatesFirst ) ? 11 : -11 ;
00645 if( SoccerTypes::isOpponent( objRangeMax ) )
00646 iIndMax += ( bTeammatesFirst ) ? 11 : -11 ;
00647
00648 return iIndMin <= iIndObj && iIndObj <= iIndMax ;
00649 }
00650
00654 ObjectT PlayerObject::getMinRange( )
00655 {
00656 return objRangeMin;
00657 }
00658
00662 ObjectT PlayerObject::getMaxRange( )
00663 {
00664 return objRangeMax;
00665 }
00666
00673 bool PlayerObject::setIsKnownPlayer( bool b )
00674 {
00675 isKnownPlayer = b;
00676 return true;
00677 }
00678
00684 bool PlayerObject::getIsKnownPlayer() const
00685 {
00686 return isKnownPlayer;
00687 }
00688
00692 bool PlayerObject::setIsGoalie( bool b )
00693 {
00694 isGoalie = b;
00695 return true;
00696 }
00697
00700 bool PlayerObject::getIsGoalie() const
00701 {
00702 return isGoalie;
00703 }
00704
00705
00709 void PlayerObject::show( ostream & os )
00710 {
00711 show( DEFAULT_TEAM_NAME, os );
00712 }
00713
00718 void PlayerObject::show( const char* strTeamName , ostream & os )
00719 {
00720 char buf[MAX_TEAM_NAME_LENGTH];
00721 SoccerTypes::getObjectStr( buf, objectType, strTeamName );
00722 os << buf
00723 << " conf: " << getConfidence( timeGlobalPosition )
00724 << " pos: " << posGlobal
00725 << "," << timeGlobalPosition
00726 << " vel: " << vecGlobalVelocity
00727 << "," << timeGlobalVelocity
00728 << " ang (b:" << getGlobalBodyAngle()
00729 << ",n:" << angGlobalNeckAngle
00730 << ")," << timeGlobalAngles
00731 << "known: " << isKnownPlayer
00732 << " lastseen:" << timeLastSeen << "\n";
00733 }
00734
00738 bool PlayerObject::setHeteroPlayerType( int index )
00739 {
00740 iHeteroPlayerType = index;
00741 return true;
00742 }
00743
00746 int PlayerObject::getHeteroPlayerType( ) const
00747 {
00748 return iHeteroPlayerType;
00749 }
00750
00751
00753 bool PlayerObject::setTimeTackle( Time time )
00754 {
00755 m_timeTackle = time;
00756 return true;
00757 }
00758
00761 Time PlayerObject::getTimeTackle( ) const
00762 {
00763 return m_timeTackle;
00764 }
00765
00766
00770 bool PlayerObject::setGlobalArm( AngDeg ang, Time time )
00771 {
00772 m_angGlobalArm = ang;
00773 return setTimeGlobalArm( time );
00774 }
00775
00778 AngDeg PlayerObject::getGlobalArm( ) const
00779 {
00780 return m_angGlobalArm;
00781 }
00782
00786 bool PlayerObject::setTimeGlobalArm( Time time )
00787 {
00788 m_timeGlobalArm = time;
00789 return true;
00790 }
00791
00795 Time PlayerObject::getTimeGlobalArm( ) const
00796 {
00797 return m_timeGlobalArm;
00798 }
00799
00800
00801
00802
00803
00806 BallObject::BallObject():DynamicObject()
00807 {
00808
00809 }
00810
00815 void BallObject::show( ostream& os)
00816 {
00817 char buf[MAX_TEAM_NAME_LENGTH];
00818 SoccerTypes::getObjectStr( buf, objectType, DEFAULT_TEAM_NAME );
00819 os << buf
00820 << "r: " << posRelative.getMagnitude()
00821 << " phi: " << posRelative.getDirection()
00822 << " vel: " << vecGlobalVelocity
00823 << " " << timeGlobalVelocity
00824 << " rel: " << posRelative
00825 << ", " << timeRelativePosition
00826 << " global: " << posGlobal
00827 << ", " << timeGlobalPosition
00828 << ", changes: " << dRelativeDistanceChange
00829 << ", " << dRelativeAngleChange
00830 << " last seen:" << timeLastSeen
00831 << " globalposderived: " << timeGlobalPosDerivedFromSee
00832 << "\n";
00833 }
00834
00835
00836
00837
00838
00843 AgentObject::AgentObject( double dStaminaMax ):PlayerObject( )
00844 {
00845 viewAngle = VA_NORMAL;
00846 viewQuality = VQ_HIGH;
00847
00848 stamina.setStamina ( dStaminaMax );
00849 stamina.setEffort ( 1.0 );
00850 stamina.setRecovery( 1.0 );
00851 velSpeedRelToNeck.setVecPosition( 0.0, 0.0 );
00852
00853 angGlobalNeckAngle = UnknownAngleValue;
00854 angBodyAngleRelToNeck = UnknownAngleValue;
00855 }
00856
00860 void AgentObject::show( ostream& os )
00861 {
00862 show( DEFAULT_TEAM_NAME, os );
00863 }
00864
00869 void AgentObject::show( const char * strTeamName, ostream & os )
00870 {
00871 char buf[MAX_TEAM_NAME_LENGTH];
00872 SoccerTypes::getObjectStr( buf, objectType, strTeamName );
00873 os << buf
00874 << " (global(" << posGlobal
00875 << ", " << timeGlobalPosition
00876 << ") (vel(" << vecGlobalVelocity
00877 << ", " << timeGlobalVelocity
00878 << ") (angles(n:" << angGlobalNeckAngle
00879 << ", b:" << angBodyAngleRelToNeck << ") ";
00880 stamina.show( os );
00881 }
00882
00886 ViewAngleT AgentObject::getViewAngle() const
00887 {
00888 return viewAngle;
00889 }
00890
00896 VecPosition AgentObject::getPositionDifference() const
00897 {
00898 return posPositionDifference;
00899 }
00900
00906 bool AgentObject::setPositionDifference( VecPosition p )
00907 {
00908 posPositionDifference = p;
00909 return true;
00910 }
00911
00915 bool AgentObject::setViewAngle( ViewAngleT v )
00916 {
00917 viewAngle = v;
00918 return true;
00919 }
00920
00924 ViewQualityT AgentObject::getViewQuality() const
00925 {
00926 return viewQuality;
00927 }
00928
00932 bool AgentObject::setViewQuality( ViewQualityT v )
00933 {
00934 viewQuality = v;
00935 return true;
00936 }
00937
00940 Stamina AgentObject::getStamina( ) const
00941 {
00942 return stamina;
00943 }
00944
00948 bool AgentObject::setStamina( Stamina sta )
00949 {
00950 stamina = sta;
00951 return true ;
00952 }
00953
00958 VecPosition AgentObject::getSpeedRelToNeck( ) const
00959 {
00960 return velSpeedRelToNeck;
00961 }
00962
00967 bool AgentObject::setSpeedRelToNeck( VecPosition v )
00968 {
00969 velSpeedRelToNeck = v;
00970 return true;
00971 }
00972
00976 bool AgentObject::setGlobalNeckAngle( AngDeg ang )
00977 {
00978 angGlobalNeckAngle= ang;
00979 angGlobalBodyAngle= VecPosition::normalizeAngle(getBodyAngleRelToNeck()+ang);
00980 return true ;
00981 }
00982
00988 AngDeg AgentObject::getBodyAngleRelToNeck( ) const
00989 {
00990 return angBodyAngleRelToNeck;
00991 }
00992
00996 bool AgentObject::setBodyAngleRelToNeck( AngDeg ang )
00997 {
00998 angBodyAngleRelToNeck = ang;
00999
01000 return true;
01001 }
01002
01004 bool AgentObject::getArmMovable( ) const
01005 {
01006 return m_bArmMovable;
01007 }
01008
01010 bool AgentObject::setArmMovable( bool b )
01011 {
01012 m_bArmMovable = b;
01013 return true;
01014 }
01015
01019 int AgentObject::getArmExpires( ) const
01020 {
01021 return m_iArmExpires;
01022 }
01023
01027 bool AgentObject::setArmExpires( int i )
01028 {
01029 m_iArmExpires = i;
01030 return true;
01031 }
01032
01036 VecPosition AgentObject::getGlobalArmPosition( ) const
01037 {
01038 return m_posGlobalArm;
01039 }
01040
01042 bool AgentObject::setGlobalArmPosition ( VecPosition v )
01043 {
01044 m_posGlobalArm = v;
01045 return true;
01046 }
01047
01050 int AgentObject::getTackleExpires( ) const
01051 {
01052 return m_iTackleExpires;
01053 }
01054
01057 bool AgentObject::setTackleExpires( int i )
01058 {
01059 m_iTackleExpires = i;
01060 return true;
01061 }
01062
01063
01064
01065
01066
01067
01073 Stamina::Stamina( double dSta, double dEff, double dRec )
01074 {
01075 setStamina ( dSta );
01076 setEffort ( dEff );
01077 setRecovery( dRec );
01078 }
01079
01083 void Stamina::show( ostream & os)
01084 {
01085 os << "(sta:" << m_dStamina
01086 << ", eff:" << m_dEffort
01087 << ", rec: " << m_dRecovery << ")" << "\n";
01088 }
01089
01092 TiredNessT Stamina::getTiredNess( double dRecDecThr, double dStaminaMax )
01093 {
01094 double dStaDiffWithThr = getStamina() - dRecDecThr * dStaminaMax;
01095
01096
01097 if( dStaDiffWithThr < 100 )
01098 return TIREDNESS_TERRIBLE;
01099 else if( dStaDiffWithThr < 750 )
01100 return TIREDNESS_VERY_BAD;
01101 else if( dStaDiffWithThr < 1500 )
01102 return TIREDNESS_BAD;
01103 else if( dStaDiffWithThr < 2250 )
01104 return TIREDNESS_AVERAGE;
01105
01106 return TIREDNESS_GOOD;
01107 }
01108
01111 double Stamina::getStamina() const
01112 {
01113 return m_dStamina;
01114 }
01115
01120 bool Stamina::setStamina( double d )
01121 {
01122 if( d < 0.0 )
01123 {
01124 m_dStamina = 0.0;
01125 return false;
01126 }
01127 else
01128 m_dStamina = d;
01129 return true;
01130 }
01131
01138 double Stamina::getEffort() const
01139 {
01140 return m_dEffort;
01141 }
01142
01148 bool Stamina::setEffort( double d )
01149 {
01150 if( d < 0.0 )
01151 {
01152 m_dEffort = 0.0;
01153 return false;
01154 }
01155 else if( d > 1.0 )
01156 {
01157 m_dEffort = 1.0;
01158 return false;
01159 }
01160 else
01161 m_dEffort = d;
01162 return true;
01163 }
01164
01171 double Stamina::getRecovery() const
01172 {
01173 return m_dRecovery;
01174 }
01175
01181 bool Stamina::setRecovery( double d )
01182 {
01183 if( d < 0.0 )
01184 {
01185 m_dRecovery = 0.0;
01186 return false;
01187 }
01188 else if( d > 1.0 )
01189 {
01190 m_dRecovery = 1.0;
01191 return false;
01192 }
01193 else
01194 m_dRecovery = d;
01195 return true;
01196 }
01197
01198
01199
01200
01201
01202
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213
01214
01215