Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

# Modules/BehaviorControl/CommonXabsl2Symbols/PassSymbols.cpp

Go to the documentation of this file.

    00001 /**
    00002 * @file PassSymbols.cpp
    00003 *
    00004 * Implementation of class PassSymbols.
    00005 *
    00006 * @author Marc Dassler
    00007 */
    00008
    00009 #include "PassSymbols.h"
    00010 #include "Representations/WLan/BehaviorTeamMessage.h"
    00011
    00012 PassSymbols::PassSymbols(const BehaviorControlInterfaces& interfaces)
    00013 : BehaviorControlInterfaces(interfaces)
    00014 {
    00015 }
    00016
    00017
    00018 void PassSymbols::registerSymbols(Xabsl2Engine& engine)
    00019 {
    00020   // "pass.found"
    00021   engine.registerBooleanInputSymbol("pass.found",this,
    00022     (bool (Xabsl2FunctionProvider::*)())&PassSymbols::getPassExists);
    00023   // "pass.quality"
    00024   engine.registerDecimalInputSymbol("pass.quality",this,
    00025     (double (Xabsl2FunctionProvider::*)())&PassSymbols::getPassQuality);
    00026   // "pass.distance"
    00027   engine.registerDecimalInputSymbol("pass.distance",this,
    00028     (double (Xabsl2FunctionProvider::*)())&PassSymbols::getPassDistance);
    00029
    00030   engine.registerDecimalInputSymbol("pass.angle-to-sender",this,
    00031     (double (Xabsl2FunctionProvider::*)())&PassSymbols::getAngleToPassSender);
    00032   engine.registerDecimalInputSymbol("pass.angle-to-receiver",this,
    00033     (double (Xabsl2FunctionProvider::*)())&PassSymbols::getAngleToPassReceiver);
    00034   engine.registerDecimalInputSymbol("pass.player-number-of-pass-receiver",this,
    00035     (double (Xabsl2FunctionProvider::*)())&PassSymbols::getPlayerNumberOfReceiver);
    00036
    00037 }
    00038
    00039 void PassSymbols::update()
    00040 {
    00041 }
    00042
    00043 // receiving pass
    00044
    00045 double PassSymbols::getAngleToPassSender()
    00046 {
    00047   Player::playerNumber senderNumber = Player::undefinedPlayerNumber;
    00048   for (int i=0;i<teamMessageCollection.numberOfTeamMessages;i++)
    00049   {
    00050     if (teamMessageCollection[i].behaviorTeamMessage.message
    00051       == BehaviorTeamMessage::preparingAPass)
    00052     {
    00053       senderNumber = teamMessageCollection[i].playerNumberOfSender;
    00054       preparingAPassMessagePlayerNumber = senderNumber;
    00055       preparingAPassMessageTimeStamp = SystemCall::getCurrentSystemTime();
    00056       break;
    00057     }
    00058   }
    00059   // caching for network failures
    00060   if (senderNumber == Player::undefinedPlayerNumber
    00061     && (SystemCall::getCurrentSystemTime() - preparingAPassMessageTimeStamp < 2000))
    00062     senderNumber = preparingAPassMessagePlayerNumber;
    00063
    00064   if (senderNumber != Player::undefinedPlayerNumber)
    00065   {
    00066     PlayerPose senderPose;
    00067     if (playerPoseCollection.getOwnPlayerPoseByPlayerNumber(senderNumber,senderPose))
    00068     {
    00069       // returns relative angle to sender
    00070       return toDegrees (Geometry::angleTo(robotPose.getPose(),senderPose.getPose().translation));
    00071     }
    00072     else
    00073     {
    00074       // fallback: turn towards the ball
    00075       Vector2<double> pos = ballModel.getKnownPosition(2000);
    00076       return toDegrees (Geometry::angleTo(robotPose.getPose(),pos));
    00077     }
    00078    }
    00079   return 0.0;
    00080 }
    00081
    00082 // sending pass
    00083 bool PassSymbols::getPassExists()
    00084 {
    00085   return (passCorridorCollection.bestPassCorridorIndex != -1);
    00086 }
    00087
    00088 double PassSymbols::getPassQuality()
    00089 {
    00090   return passCorridorCollection.getBestPassCorridorQuality();
    00091 }
    00092
    00093 double PassSymbols::getPassDistance()
    00094 {
    00095   if (passCorridorCollection.bestPassCorridorIndex != -1)
    00096   {
    00097     return passCorridorCollection.bestPassCorridor->distance;
    00098   }
    00099   return 0.0;
    00100 }
    00101 double PassSymbols::getPlayerNumberOfReceiver()
    00102 {
    00103   /*
    00104   Player player;
    00105   player.setPlayerNumber(passCorridorCollection.bestPassCorridor->playerNumber);
    00106   player.getPlayerNumberName
    00107   */
    00108   if (passCorridorCollection.bestPassCorridorIndex != -1)
    00109     return (double)(passCorridorCollection.bestPassCorridor->playerNumber);
    00110   else
    00111     return (double) -1;
    00112 }
    00113 double PassSymbols::getAngleToPassReceiver()
    00114 {
    00115
    00116   if (passCorridorCollection.bestPassCorridorIndex != -1)
    00117   {
    00118     int i = passCorridorCollection.bestPassCorridor->playerPoseIndex;
    00119     PlayerPose receiverPose = playerPoseCollection.getOwnPlayerPose(i);
    00120     return toDegrees (Geometry::angleTo(robotPose.getPose(),receiverPose.getPose().translation));
    00121   }
    00122   else
    00123     return 0.0;
    00124 }