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

# Modules/BehaviorControl/CommonXabsl2Symbols/GtCamSymbols.cpp

Go to the documentation of this file.

    00001 /**
    00002 * @file GtCamSymbols.cpp
    00003 *
    00004 * @author Matthias Meyer
    00005 */
    00006
    00007 #include "GtCamSymbols.h"
    00008
    00009
    00010
    00011 // Macro definitions
    00012 #define GETROBOTXimpl(number,pnumber,color) \
    00013   double GTCamSymbols::getRobot##number##PosX() {\
    00014   return gtCamWorldState.getPlayerPos(pnumber,color).x;\
    00015 }\
    00016 double GTCamSymbols::getRobot##number##PosY() {\
    00017   return gtCamWorldState.getPlayerPos(pnumber,color).y;\
    00018 }\
    00019 Vector2<double> GTCamSymbols::getRobot##number##Pos() {\
    00020   Vector2<double> v;\
    00021   v.x = getRobot##number##PosX();\
    00022   v.y = getRobot##number##PosY();\
    00023   return v;\
    00024 }\
    00025 double GTCamSymbols::getRobot##number##SpeedX() {\
    00026   return gtCamWorldState.getPlayerSpeed(pnumber,color).x;\
    00027 }\
    00028 double GTCamSymbols::getRobot##number##SpeedY() {\
    00029   return gtCamWorldState.getPlayerSpeed(pnumber,color).y;\
    00030 }\
    00031 Vector2<double> GTCamSymbols::getRobot##number##Speed() {\
    00032   Vector2<double> v;\
    00033   v.x = getRobot##number##SpeedX();\
    00034   v.y = getRobot##number##SpeedY();\
    00035   return v;\
    00036 }\
    00037 double GTCamSymbols::getRobot##number##Rotation() {\
    00038   return gtCamWorldState.getPlayerOrientation(pnumber,color);\
    00039 }\
    00040 double GTCamSymbols::getRobot##number##Distance() {\
    00041   Vector2<double> v;\
    00042   v.x = robotPose.translation.x - getRobot##number##PosX();\
    00043   v.y = robotPose.translation.y - getRobot##number##PosY();\
    00044   return v.abs();\
    00045 }\
    00046
    00047 #define REGISTERROBOTXimpl(number)\
    00048   engine.registerDecimalInputSymbol("GTCam.Robot" #number ".x",this,\
    00049     (double (Xabsl2FunctionProvider::*)())&GTCamSymbols::getRobot##number##PosX);\
    00050   engine.registerDecimalInputSymbol("GTCam.Robot" #number ".y",this,\
    00051     (double (Xabsl2FunctionProvider::*)())&GTCamSymbols::getRobot##number##PosY);\
    00052   engine.registerDecimalInputSymbol("GTCam.Robot" #number ".speed.x",this,\
    00053     (double (Xabsl2FunctionProvider::*)())&GTCamSymbols::getRobot##number##SpeedX);\
    00054   engine.registerDecimalInputSymbol("GTCam.Robot" #number ".speed.y",this,\
    00055     (double (Xabsl2FunctionProvider::*)())&GTCamSymbols::getRobot##number##SpeedY);\
    00056   engine.registerDecimalInputSymbol("GTCam.Robot" #number ".rotation",this,\
    00057     (double (Xabsl2FunctionProvider::*)())&GTCamSymbols::getRobot##number##Rotation);\
    00058   engine.registerDecimalInputSymbol("GTCam.DistanceToRobot" #number ".abs",this,\
    00059   (double (Xabsl2FunctionProvider::*)())&GTCamSymbols::getRobot##number##Distance );\
    00060
    00061
    00062
    00063
    00064
    00065 /**
    00066 * Constructor
    00067 */
    00068 GTCamSymbols::GTCamSymbols(const BehaviorControlInterfaces& interfaces) :
    00069 BehaviorControlInterfaces(interfaces)
    00070 {
    00071 }
    00072
    00073
    00074 /**
    00075 * Register XABSL2 Symbols
    00076 */
    00077 void GTCamSymbols::registerSymbols(Xabsl2Engine& engine)
    00078 {
    00079   // Register ball Symbols
    00080   engine.registerDecimalInputSymbol("GTCam.ball.x",this,
    00081     (double (Xabsl2FunctionProvider::*)())&GTCamSymbols::getBallX);
    00082   engine.registerDecimalInputSymbol("GTCam.ball.y",this,
    00083     (double (Xabsl2FunctionProvider::*)())&GTCamSymbols::getBallY);
    00084   engine.registerDecimalInputSymbol("GTCam.ball.speed.x",this,
    00085     (double (Xabsl2FunctionProvider::*)())&GTCamSymbols::getBallSpeedX);
    00086   engine.registerDecimalInputSymbol("GTCam.ball.speed.y",this,
    00087     (double (Xabsl2FunctionProvider::*)())&GTCamSymbols::getBallSpeedY);
    00088
    00089   // Register Robot 1-8 Symbols
    00090   REGISTERROBOTXimpl(1)
    00091   REGISTERROBOTXimpl(2)
    00092   REGISTERROBOTXimpl(3)
    00093   REGISTERROBOTXimpl(4)
    00094   REGISTERROBOTXimpl(5)
    00095   REGISTERROBOTXimpl(6)
    00096   REGISTERROBOTXimpl(7)
    00097   REGISTERROBOTXimpl(8)
    00098
    00099   // Register own Symbols
    00100   engine.registerDecimalInputSymbol("GTCam.Own.rotation",this,
    00101   (double (Xabsl2FunctionProvider::*)())&GTCamSymbols::getOwnRotation);
    00102   engine.registerDecimalInputSymbol("GTCam.Own.x",this,
    00103   (double (Xabsl2FunctionProvider::*)())&GTCamSymbols::getOwnPosX);
    00104   engine.registerDecimalInputSymbol("GTCam.Own.y",this,
    00105   (double (Xabsl2FunctionProvider::*)())&GTCamSymbols::getOwnPosY);
    00106   engine.registerDecimalInputSymbol("GTCam.Own.speed.x",this,
    00107   (double (Xabsl2FunctionProvider::*)())&GTCamSymbols::getOwnSpeedX);
    00108   engine.registerDecimalInputSymbol("GTCam.Own.speed.y",this,
    00109   (double (Xabsl2FunctionProvider::*)())&GTCamSymbols::getOwnSpeedY);
    00110   engine.registerDecimalInputSymbol("GTCam.Own.Distance.abs",this,
    00111   (double (Xabsl2FunctionProvider::*)())&GTCamSymbols::getOwnDistance);
    00112 }
    00113
    00114 /**
    00115 * Do Update - not implemented yet
    00116 */
    00117 void GTCamSymbols::update()
    00118 {
    00119 }
    00120
    00121
    00122 /**
    00123 * Implementations for Player 1 - 8
    00124 */
    00125 GETROBOTXimpl(1,0,Player::red)
    00126 GETROBOTXimpl(2,1,Player::red)
    00127 GETROBOTXimpl(3,2,Player::red)
    00128 GETROBOTXimpl(4,3,Player::red)
    00129 GETROBOTXimpl(5,0,Player::blue)
    00130 GETROBOTXimpl(6,1,Player::blue)
    00131 GETROBOTXimpl(7,2,Player::blue)
    00132 GETROBOTXimpl(8,3,Player::blue)
    00133
    00134 /**
    00135 * Return Ball.x
    00136 */
    00137 double GTCamSymbols::getBallX() {
    00138   return gtCamWorldState.getBallModel().seen.positionField.x;
    00139 }
    00140
    00141 /**
    00142 * Return Ball.y
    00143 */
    00144 double GTCamSymbols::getBallY() {
    00145   return gtCamWorldState.getBallModel().seen.positionField.y;
    00146 }
    00147
    00148 /**
    00149 * Return BallSpeed.x
    00150 */
    00151 double GTCamSymbols::getBallSpeedX() {
    00152   return gtCamWorldState.getBallModel().seen.speedField.x;
    00153 }
    00154
    00155 /**
    00156 * Return BallSpeed.y
    00157 */
    00158 double GTCamSymbols::getBallSpeedY() {
    00159   return gtCamWorldState.getBallModel().seen.speedField.y;
    00160 }
    00161
    00162 /**
    00163 * Return a vector of BallSpeed.x and BallSpeed.y
    00164 */
    00165 Vector2<double> GTCamSymbols::getBall() {
    00166   Vector2<double> v;
    00167   v.x = getBallX();
    00168   v.y = getBallY();
    00169   return v;
    00170 }
    00171
    00172
    00173 /**
    00174 * get Distance between cam and self-location
    00175 */
    00176 double GTCamSymbols::getOwnDistance() {
    00177   Vector2<double> v;
    00178   v.x = robotPose.translation.x - getOwnPosX();
    00179   v.y = robotPose.translation.y - getOwnPosY();
    00180   return v.abs();
    00181 }
    00182
    00183 /**
    00184 * get own rotation from camstate
    00185 */
    00186 double GTCamSymbols::getOwnRotation() {
    00187   return gtCamWorldState.getPlayerOrientation(getPlayer().getPlayerNumber(),getPlayer().getTeamColor());
    00188 }
    00189
    00190 /**
    00191 * get own x coord from camstate
    00192 */
    00193 double GTCamSymbols::getOwnPosX() {
    00194   return gtCamWorldState.getPlayerPos(getPlayer().getPlayerNumber() ,getPlayer().getTeamColor()).x;
    00195 }
    00196
    00197 /**
    00198 * get own y coor from camstate
    00199 */
    00200 double GTCamSymbols::getOwnPosY() {
    00201   return gtCamWorldState.getPlayerPos(getPlayer().getPlayerNumber() ,getPlayer().getTeamColor()).y;
    00202 }
    00203
    00204 /**
    00205 * get own x speed from camstate
    00206 */
    00207 double GTCamSymbols::getOwnSpeedX() {
    00208   return gtCamWorldState.getPlayerSpeed(getPlayer().getPlayerNumber(),getPlayer().getTeamColor()).x;
    00209 }
    00210
    00211 /**
    00212 * get own y speed from camstate
    00213 */
    00214 double GTCamSymbols::getOwnSpeedY() {
    00215   return gtCamWorldState.getPlayerSpeed(getPlayer().getPlayerNumber(),getPlayer().getTeamColor()).y;
    00216 }