Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

Objects.C

Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2000-2002, Jelle Kok, University of Amsterdam
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without 
00006 modification, are permitted provided that the following conditions are met:
00007 
00008 1. Redistributions of source code must retain the above copyright notice, this 
00009 list of conditions and the following disclaimer. 
00010 
00011 2. Redistributions in binary form must reproduce the above copyright notice, 
00012 this list of conditions and the following disclaimer in the documentation 
00013 and/or other materials provided with the distribution. 
00014 
00015 3. Neither the name of the University of Amsterdam nor the names of its 
00016 contributors may be used to endorse or promote products derived from this 
00017 software without specific prior written permission. 
00018 
00019 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
00020 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
00021 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
00022 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 
00023 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
00024 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
00025 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
00026 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
00027 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
00028 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 */
00045 #include"Objects.h"
00046 
00047 #include<stdlib.h>       // needed for free
00048 #include<iostream.h>     // needed for cout
00049 #ifdef Solaris
00050   #include <strings.h>   // needed for strdup
00051 #else
00052   #include <string.h>    // needed for strdup
00053 #endif
00054 
00055 /******************************************************************************/
00056 /********************** CLASS OBJECT ******************************************/
00057 /******************************************************************************/
00058 
00061 Object::Object( )
00062 {
00063   objectType                   = OBJECT_ILLEGAL;
00064 }
00065 
00069 AngDeg Object::getRelativeAngle( )
00070 {
00071   return VecPosition::normalizeAngle(posRelative.getDirection());
00072 }
00073 
00077 double Object::getRelativeDistance( )
00078 {
00079   return posRelative.getMagnitude();
00080 }
00081 
00087 double Object::getConfidence( Time time )
00088 {
00089   if( timeLastSeen.getTime() == -1 )       
00090     return 0.0;
00091   double dConf = 
00092       max( 0.0, 1.0-(double)(time.getTimeDifference(timeLastSeen))/100.0);
00093   if( dConf > 1.0 )
00094     return 0.0;
00095   return dConf;
00096 }
00097 
00098 
00102 bool Object::setType( ObjectT o )
00103 {
00104   objectType = o;
00105   return true;
00106 }
00107 
00110 ObjectT  Object::getType() const
00111 {
00112   return objectType;
00113 }
00114 
00122 bool Object::setRelativePosition( double dDist, AngDeg ang, Time time )
00123 {
00124   posRelative.setVecPosition( dDist, ang, POLAR );
00125   setTimeRelativePosition( time );
00126   return true;
00127 }
00128 
00134 bool Object::setRelativePosition( VecPosition v, Time time )
00135 {
00136   posRelative = v;
00137   setTimeRelativePosition( time );
00138   return true;
00139 }
00140 
00146 VecPosition Object::getRelativePosition() const
00147 {
00148   return posRelative;
00149 }
00150 
00154 bool Object::setTimeRelativePosition( Time time )
00155 {
00156   timeRelativePosition = time;
00157   return true;
00158 }
00159 
00163 Time Object::getTimeRelativePosition() const
00164 {
00165   return timeRelativePosition;
00166 }
00167 
00173 bool Object::setGlobalPosition( VecPosition p, Time time )
00174 {
00175   posGlobal = p;
00176   setTimeGlobalPosition( time );
00177   return true;
00178 }
00179 
00185 VecPosition Object::getGlobalPosition() const
00186 {
00187   return posGlobal;
00188 }
00189 
00193 bool Object::setTimeGlobalPosition( Time time )
00194 {
00195   timeGlobalPosition = time;
00196   return true;
00197 }
00198 
00202 Time Object::getTimeGlobalPosition() const
00203 {
00204   return timeGlobalPosition;
00205 }
00206 
00214 bool Object::setGlobalPositionLastSee( VecPosition p, Time time )
00215 {
00216   posGlobalLastSee = p;
00217   setTimeGlobalPosDerivedFromSee( time );
00218   return true;
00219 }
00220 
00225 VecPosition Object::getGlobalPositionLastSee() const
00226 {
00227   return posGlobalLastSee;
00228 }
00229 
00234 bool Object::setTimeGlobalPosDerivedFromSee( Time time )
00235 {
00236   timeGlobalPosDerivedFromSee = time;
00237   return true;
00238 }
00239 
00243 Time Object::getTimeGlobalPosDerivedFromSee() const
00244 {
00245   return timeGlobalPosDerivedFromSee;
00246 }
00247 
00252 bool Object::setTimeLastSeen( Time time)
00253 {
00254   timeLastSeen = time;
00255   return true;
00256 }
00257 
00261 Time Object::getTimeLastSeen() const
00262 {
00263   return timeLastSeen;
00264 }
00265 
00266 
00267 /******************************************************************************/
00268 /********************** CLASS FIXEDOBJECT ************************************/
00269 /******************************************************************************/
00270 
00274 void FixedObject::show( ostream & os )
00275 {
00276   char buf[MAX_TEAM_NAME_LENGTH];
00277 
00278   // DEFAULT_TEAM_NAME is used since it is not a player, so name does not matter
00279   SoccerTypes::getObjectStr( buf, objectType, DEFAULT_TEAM_NAME );
00280   os <<  buf
00281      << " rel("  << posRelative << " r:" << posRelative.getMagnitude()
00282      << " phi:"  << posRelative.getDirection()
00283      << " t:"    << timeRelativePosition << ")"
00284      << " seen:" << timeLastSeen << endl;
00285 }
00286 
00295 VecPosition FixedObject::getGlobalPosition( SideT s, double dGoalWidth )const
00296 {
00297   return SoccerTypes::getGlobalPositionFlag( getType(), s, dGoalWidth );
00298 }
00299 
00306 AngDeg FixedObject::getGlobalAngle( SideT s )
00307 {
00308   return SoccerTypes::getGlobalAngleLine( getType(), s );
00309 }
00310 
00311 /******************************************************************************/
00312 /********************** CLASS DYNAMICOBJECT ***********************************/
00313 /******************************************************************************/
00314 
00317 DynamicObject::DynamicObject( ):Object( )
00318 {
00319   dRelativeDistanceChange   = UnknownDoubleValue;
00320   dRelativeAngleChange      = UnknownDoubleValue;
00321 }
00322 
00328 bool DynamicObject::setGlobalVelocity( VecPosition v, Time time)
00329 {
00330   if( v.getMagnitude() < EPSILON )
00331     vecGlobalVelocity.setVecPosition( 0.0, 0.0 );
00332   else
00333      vecGlobalVelocity = v;
00334   setTimeGlobalVelocity( time );
00335   return true;
00336 }
00337 
00341 VecPosition DynamicObject::getGlobalVelocity( ) const
00342 {
00343   return vecGlobalVelocity;
00344 }
00345 
00349 double DynamicObject::getSpeed( ) const
00350 {
00351   return vecGlobalVelocity.getMagnitude();
00352 }
00353 
00358 bool DynamicObject::setTimeGlobalVelocity( Time time )
00359 {
00360   timeGlobalVelocity = time;
00361   return true;
00362 }
00363 
00367 Time DynamicObject::getTimeGlobalVelocity() const
00368 {
00369   return timeGlobalVelocity;
00370 }
00371 
00377 bool DynamicObject::setRelativeDistanceChange( double d, Time time )
00378 {
00379   dRelativeDistanceChange = d;
00380   setTimeChangeInformation( time );
00381   return true;
00382 }
00383 
00390 double DynamicObject::getRelativeDistanceChange() const
00391 {
00392   return dRelativeDistanceChange;
00393 }
00394 
00400 bool DynamicObject::setRelativeAngleChange( double d, Time time )
00401 {
00402   dRelativeAngleChange = d;
00403   setTimeChangeInformation( time );
00404   return true;
00405 }
00406 
00411 double DynamicObject::getRelativeAngleChange() const
00412 {
00413   return dRelativeAngleChange;
00414 }
00415 
00419 bool DynamicObject::setTimeChangeInformation( Time time )
00420 {
00421   timeChangeInformation = time ;
00422   return true;
00423 }
00424 
00428 Time DynamicObject::getTimeChangeInformation()  const
00429 {
00430   return timeChangeInformation;
00431 }
00432 
00433 
00434 /******************************************************************************/
00435 /********************** CLASS PLAYEROBJECT ************************************/
00436 /******************************************************************************/
00437 
00440 PlayerObject::PlayerObject( ):DynamicObject( )
00441 {
00442   angGlobalBodyAngle   = UnknownAngleValue;
00443   angGlobalNeckAngle   = UnknownAngleValue;
00444   isKnownPlayer        = false;
00445   isGoalie             = false;
00446 
00447   angRelativeBodyAngle = UnknownAngleValue;
00448   angRelativeNeckAngle = UnknownAngleValue;
00449 }
00450 
00456 bool PlayerObject::setRelativeBodyAngle( AngDeg ang, Time time )
00457 {
00458   angRelativeBodyAngle = ang;
00459   setTimeRelativeAngles( time );
00460   return true;
00461 }
00462 
00466 AngDeg PlayerObject::getRelativeBodyAngle( )  const
00467 {
00468   return angRelativeBodyAngle;
00469 }
00470 
00476 bool PlayerObject::setGlobalBodyAngle( AngDeg ang, Time time)
00477 {
00478   angGlobalBodyAngle = ang;
00479   setTimeGlobalAngles( time );
00480   return true;
00481 }
00482 
00486 AngDeg PlayerObject::getGlobalBodyAngle( )  const
00487 {
00488   return angGlobalBodyAngle;
00489 }
00490 
00496 bool PlayerObject::setRelativeNeckAngle( AngDeg ang, Time time )
00497 {
00498   angRelativeNeckAngle = ang;
00499   setTimeRelativeAngles( time );
00500   return true;
00501 }
00502 
00506 AngDeg PlayerObject::getRelativeNeckAngle( )  const
00507 {
00508   return angRelativeNeckAngle;
00509 }
00510 
00516 bool PlayerObject::setGlobalNeckAngle( AngDeg ang, Time time )
00517 {
00518   angGlobalNeckAngle = ang;
00519   setTimeGlobalAngles( time );
00520   return true;
00521 }
00522 
00526 AngDeg PlayerObject::getGlobalNeckAngle( )  const
00527 {
00528   return angGlobalNeckAngle;
00529 }
00530 
00534 bool PlayerObject::setTimeRelativeAngles( Time time )
00535 {
00536   timeRelativeAngles = time;
00537   return true;
00538 }
00539 
00543 Time PlayerObject::getTimeRelativeAngles( ) const
00544 {
00545   return timeRelativeAngles ;
00546 }
00547 
00551 bool PlayerObject::setTimeGlobalAngles( Time time )
00552 {
00553   timeGlobalAngles = time;
00554   return true;
00555 }
00556 
00560 Time PlayerObject::getTimeGlobalAngles( ) const
00561 {
00562   return timeGlobalAngles ;
00563 }
00564 
00573 bool PlayerObject::setPossibleRange( ObjectT objMin, ObjectT objMax )
00574 {
00575   objRangeMin = objMin;
00576   objRangeMax = objMax;
00577   return true;
00578 }
00579 
00584 bool PlayerObject::isInRange( ObjectT obj )
00585 {
00586   int  iIndObj = SoccerTypes::getIndex( obj );
00587   int  iIndMin = SoccerTypes::getIndex( objRangeMin );
00588   int  iIndMax = SoccerTypes::getIndex( objRangeMax );
00589     
00590   if( SoccerTypes::isOpponent( obj ) )
00591     iIndObj += 11;
00592   if( SoccerTypes::isOpponent( objRangeMin ) )
00593     iIndMin += 11;
00594   if( SoccerTypes::isOpponent( objRangeMax ) )
00595     iIndMax += 11;      
00596   
00597   return iIndMin <= iIndObj && iIndObj <= iIndMax ;
00598 }
00599 
00603 ObjectT PlayerObject::getMinRange( )
00604 {
00605   return objRangeMin;
00606 }
00607 
00611 ObjectT PlayerObject::getMaxRange( )
00612 {
00613   return objRangeMax;
00614 }
00615 
00622 bool PlayerObject::setIsKnownPlayer( bool b )
00623 {
00624   isKnownPlayer = b;
00625   return true;
00626 }
00627 
00633 bool PlayerObject::getIsKnownPlayer() const
00634 {
00635   return isKnownPlayer;
00636 }
00637 
00641 bool PlayerObject::setIsGoalie( bool b )
00642 {
00643   isGoalie = b;
00644   return true;
00645 }
00646 
00649 bool PlayerObject::getIsGoalie() const
00650 {
00651   return isGoalie;
00652 }
00653 
00654 
00658 void PlayerObject::show( ostream & os )
00659 {
00660   show( DEFAULT_TEAM_NAME, os );
00661 }
00662 
00667 void PlayerObject::show( const char* strTeamName , ostream & os )
00668 {
00669   char buf[MAX_TEAM_NAME_LENGTH];
00670   SoccerTypes::getObjectStr( buf, objectType, strTeamName );
00671   os << buf 
00672             << " conf: "              << getConfidence( timeGlobalPosition )
00673             << " pos: "               << posGlobal
00674             << ","                    << timeGlobalPosition
00675             << " vel: "               << vecGlobalVelocity
00676             << ","                    << timeGlobalVelocity
00677             << " ang (b:"             << getGlobalBodyAngle()
00678             << ",n:"                  << angGlobalNeckAngle
00679             << "),"                   << timeGlobalAngles
00680             << "known: "              << isKnownPlayer
00681             << " lastseen:"            << timeLastSeen << endl;
00682 }
00683 
00684 /******************************************************************************/
00685 /********************** CLASS BALLOBJECT **************************************/
00686 /******************************************************************************/
00687 
00690 BallObject::BallObject():DynamicObject()
00691 {
00692 
00693 }
00694 
00697 void BallObject::show( ostream& os)
00698 {
00699   char buf[MAX_TEAM_NAME_LENGTH];
00700   SoccerTypes::getObjectStr( buf, objectType, DEFAULT_TEAM_NAME );
00701   os <<  buf
00702        << "r: "                 << posRelative.getMagnitude()
00703        << " phi: "              << posRelative.getDirection()
00704        << " vel: "              << vecGlobalVelocity
00705        << " "                   << timeGlobalVelocity
00706        << " rel: "              << posRelative       
00707        << ", "                  << timeRelativePosition
00708        << " global: "           << posGlobal
00709        << ", "                  << timeGlobalPosition
00710        << ", changes: "         << dRelativeDistanceChange
00711        << ", "                  << dRelativeAngleChange
00712        << " last seen:"         << timeLastSeen
00713        << " globalposderived: " << timeGlobalPosDerivedFromSee
00714        << endl;
00715 }
00716 
00717 /******************************************************************************/
00718 /********************** CLASS AGENTOBJECT *************************************/
00719 /******************************************************************************/
00720 
00725 AgentObject::AgentObject( double dStaminaMax ):PlayerObject( )
00726 {
00727   viewAngle              = VA_ILLEGAL;
00728   viewQuality            = VQ_ILLEGAL;
00729 
00730   stamina.setStamina ( dStaminaMax );
00731   stamina.setEffort  ( 1.0 );
00732   stamina.setRecovery( 1.0 );
00733   velSpeedRelToNeck.setVecPosition( 0.0, 0.0 );
00734 
00735   angGlobalNeckAngle   = UnknownAngleValue;
00736   angBodyAngleRelToNeck  = UnknownAngleValue;
00737 }
00738 
00742 void AgentObject::show( ostream& os )
00743 {
00744   show( DEFAULT_TEAM_NAME, os );
00745 }
00746 
00751 void AgentObject::show( const char * strTeamName, ostream & os )
00752 {
00753   char buf[MAX_TEAM_NAME_LENGTH];
00754   SoccerTypes::getObjectStr( buf, objectType, strTeamName );
00755   os   <<  buf
00756        << " (global("    << posGlobal
00757        << ", "           << timeGlobalPosition
00758        << ") (vel("      << vecGlobalVelocity
00759        << ", "           << timeGlobalVelocity
00760        << ") (angles(n:" << angGlobalNeckAngle
00761        << ", b:"         << angBodyAngleRelToNeck << ") ";
00762   stamina.show( os );
00763 }
00764 
00768 ViewAngleT AgentObject::getViewAngle() const
00769 {
00770   return viewAngle;
00771 }
00772 
00778 VecPosition AgentObject::getPositionDifference() const
00779 {
00780   return posPositionDifference;
00781 }
00782 
00788 bool  AgentObject::setPositionDifference( VecPosition p )
00789 {
00790   posPositionDifference = p;
00791   return true;
00792 }
00793 
00797 bool AgentObject::setViewAngle( ViewAngleT v )
00798 {
00799   viewAngle = v;
00800   return true;
00801 }
00802 
00806 ViewQualityT AgentObject::getViewQuality() const
00807 {
00808   return viewQuality;
00809 }
00810 
00814 bool AgentObject::setViewQuality( ViewQualityT v )
00815 {
00816   viewQuality = v;
00817   return true;
00818 }
00819 
00822 Stamina AgentObject::getStamina( ) const
00823 {
00824   return stamina;
00825 }
00826 
00830 bool AgentObject::setStamina( Stamina sta )
00831 {
00832   stamina = sta;
00833   return true ;
00834 }
00835 
00840 VecPosition AgentObject::getSpeedRelToNeck( ) const
00841 {
00842   return velSpeedRelToNeck;
00843 }
00844 
00849 bool AgentObject::setSpeedRelToNeck( VecPosition v )
00850 {
00851   velSpeedRelToNeck = v;
00852   return true;
00853 }
00854 
00858 bool AgentObject::setGlobalNeckAngle( AngDeg ang )
00859 {
00860   angGlobalNeckAngle = ang;
00861   angGlobalBodyAngle = VecPosition::normalizeAngle(getBodyAngleRelToNeck()+ang);
00862   return true ;
00863 }
00864 
00870 AngDeg AgentObject::getBodyAngleRelToNeck( ) const
00871 {
00872   return angBodyAngleRelToNeck;
00873 }
00874 
00878 bool AgentObject::setBodyAngleRelToNeck( AngDeg ang )
00879 {
00880   angBodyAngleRelToNeck = ang;
00881 //  angGlobalBodyAngle = VecPosition::normalizeAngle(getGlobalNeckAngle()+ang);
00882   return true;
00883 }
00884 
00885 /******************************************************************************/
00886 /********************** CLASS STAMINA *****************************************/
00887 /******************************************************************************/
00888 
00894 Stamina::Stamina( double dSta, double dEff, double dRec )
00895 {
00896   setStamina ( dSta );
00897   setEffort  ( dEff );
00898   setRecovery( dRec );
00899 }
00900 
00904 void Stamina::show( ostream & os)
00905 {
00906   os  << "(sta:"   << m_dStamina
00907       << ", eff:"  << m_dEffort
00908       << ", rec: " << m_dRecovery << ")" << endl;
00909 }
00910 
00913 TiredNessT  Stamina::getTiredNess( double dRecDecThr, double dStaminaMax )
00914 {
00915   double dStaDiffWithThr = getStamina() - dRecDecThr * dStaminaMax;
00916   
00917   if( dStaDiffWithThr < 400 )
00918     return TIREDNESS_VERY_BAD;
00919   else if( dStaDiffWithThr < 1000 )
00920     return TIREDNESS_BAD;
00921   else if( dStaDiffWithThr < 2000 )
00922     return TIREDNESS_AVERAGE;
00923 
00924   return TIREDNESS_GOOD;
00925 }
00926 
00929 double Stamina::getStamina() const
00930 {
00931   return m_dStamina;
00932 }
00933 
00938 bool Stamina::setStamina( double d )
00939 {
00940   if( d < 0.0 )
00941   {
00942     m_dStamina = 0.0;
00943     return false;
00944   }
00945   else
00946     m_dStamina = d;
00947   return true;
00948 }
00949 
00956 double Stamina::getEffort() const
00957 {
00958   return m_dEffort;
00959 }
00960 
00966 bool Stamina::setEffort( double d )
00967 {
00968   if( d < 0.0 )
00969   {
00970     m_dEffort = 0.0;
00971     return false;
00972   }
00973    else if( d > 1.0 )
00974   {
00975     m_dEffort = 1.0;
00976     return false;
00977   }
00978   else
00979     m_dEffort = d;
00980   return true;
00981 }
00982 
00989 double Stamina::getRecovery() const
00990 {
00991   return m_dRecovery;
00992 }
00993 
00999 bool Stamina::setRecovery( double d )
01000 {
01001   if( d < 0.0 )
01002   {
01003     m_dRecovery = 0.0;
01004     return false;
01005   }
01006    else if( d > 1.0 )
01007   {
01008     m_dRecovery = 1.0;
01009     return false;
01010   }
01011   else
01012     m_dRecovery = d;
01013   return true;
01014 }
01015 
01016 /******************************************************************************/
01017 /********************** TESTING PURPOSES **************************************/
01018 /******************************************************************************/
01019 
01020 /*
01021 int main( void )
01022 {
01023   PlayerObject p();
01024   BallObject b();
01025   FixedObject s();
01026 
01027   cout << p.getDeltaRelativeAngle() << endl <<
01028       b.getDeltaRelativeDistance() << endl <<
01029   p.getTimeRelativeDistance() << endl;
01030   return 0;
01031 
01032 }
01033 */

Generated on Tue Jul 2 10:18:52 2002 for UvA Trilearn 2002 by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001