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

Modules/BehaviorControl/CommonXabsl2Symbols/ChallengeSymbols.cpp

Go to the documentation of this file.
00001 /** 
00002 * @file ChallengeSymbols.cpp
00003 *
00004 * Implementation of class ChallengeSymbols.
00005 *
00006 * @author Thomas Röfer
00007 */
00008 
00009 #include "ChallengeSymbols.h"
00010 #include "Tools/FieldDimensions.h"
00011 
00012 ChallengeSymbols::ChallengeSymbols(const BehaviorControlInterfaces& interfaces)
00013 : BehaviorControlInterfaces(interfaces)
00014 {
00015 #ifdef _WIN32
00016   InConfigFile stream("points.cfg");
00017 #else
00018   InConfigFile stream("/MS/points.cfg");
00019 #endif
00020   if(stream.exists())
00021   {
00022     for(int i = 0; i < 5; ++i)
00023     {
00024       stream >> targetPositions[i].translation.x >> targetPositions[i].translation.y;
00025       if(getPlayer().getTeamColor() == Player::red)
00026         targetPositions[i].translation *= -10;
00027       else
00028         targetPositions[i].translation *= 10;
00029       challenge2OptimalRotation(targetPositions[i]);
00030     }
00031   }
00032   lastIndex = 10;
00033 }
00034 
00035 void ChallengeSymbols::registerSymbols(Xabsl2Engine& engine)
00036 {
00037   // "challenge-slam.target-position.x"
00038   engine.registerDecimalInputFunction("challenge-slam.target-position.x",this,
00039     (double (Xabsl2FunctionProvider::*)())&ChallengeSymbols::challenge2TargetPositionX);
00040   engine.registerDecimalInputFunctionParameter("challenge-slam.target-position.x",
00041                                                "challenge-slam.target-position.x.index",index);
00042 
00043   // "challenge-slam.target-position.y"
00044   engine.registerDecimalInputFunction("challenge-slam.target-position.y",this,
00045     (double (Xabsl2FunctionProvider::*)())&ChallengeSymbols::challenge2TargetPositionY);
00046   engine.registerDecimalInputFunctionParameter("challenge-slam.target-position.y",
00047                                                "challenge-slam.target-position.y.index",index);
00048 
00049   // "challenge-slam.target-position.rotation"
00050   engine.registerDecimalInputFunction("challenge-slam.target-position.rotation",this,
00051     (double (Xabsl2FunctionProvider::*)())&ChallengeSymbols::challenge2TargetPositionRotation);
00052   engine.registerDecimalInputFunctionParameter("challenge-slam.target-position.rotation",
00053                                                "challenge-slam.target-position.rotation.index",index);
00054 }
00055 
00056 void ChallengeSymbols::update()
00057 {
00058 }
00059 
00060 
00061 double ChallengeSymbols::challenge2TargetPositionX()
00062 {
00063   challenge2ShortestPath();
00064   return targetPositions[int(index)].translation.x;
00065 }
00066 
00067 double ChallengeSymbols::challenge2TargetPositionY()
00068 {
00069   challenge2ShortestPath();
00070   return targetPositions[int(index)].translation.y;
00071 }
00072 
00073 double ChallengeSymbols::challenge2TargetPositionRotation()
00074 {
00075   challenge2ShortestPath();
00076   return toDegrees(targetPositions[int(index)].rotation);
00077 }
00078 
00079 void ChallengeSymbols::challenge2OptimalRotation(Pose2D& pose)
00080 {
00081   if(pose.translation.x < -2000 ||
00082      pose.translation.x > 700 && pose.translation.x < 2000)
00083     pose.rotation = 0;
00084   else if(pose.translation.x > 2000 ||
00085           pose.translation.x < -700 && pose.translation.x > -2000)
00086     pose.rotation = pi;
00087   else if(pose.translation.y > 0)
00088     pose.rotation = pi_2;
00089   else
00090     pose.rotation = -pi_2;
00091     
00092 //    OUTPUT(idText,text,pose.translation.x << " " << pose.translation.y << " " << int(pose.rotation * 180 / pi));
00093 
00094   // reach position with center of body
00095   pose += Pose2D(Vector2<double>(50,0));
00096 }
00097 
00098 void ChallengeSymbols::challenge2ShortestPath()
00099 {
00100   // this is a hack to recalculate path on restart
00101   if(index == 0 && lastIndex > 0)
00102   {
00103     Pose2D p[6];
00104     p[0] = robotPose;
00105     memcpy(p + 1, targetPositions, sizeof(targetPositions));
00106     double minLength = 1e9;
00107     challenge2ShortestPermutation(p, 1, minLength);
00108   }
00109   lastIndex = index;
00110 }
00111 
00112 void ChallengeSymbols::challenge2ShortestPermutation(Pose2D* p, int n, double& minLength)
00113 {
00114   if(n < 6) 
00115     for(int i = n; i < 6; ++i)
00116     {
00117       challenge2Swap(p, i, n);
00118       challenge2ShortestPermutation(p, n + 1, minLength);
00119       challenge2Swap(p, i, n);
00120     }
00121   else
00122   {
00123     double length = 0;
00124     for(int i = 0; i < 5; ++i)
00125       length += (p[i].translation - p[i + 1].translation).abs();
00126     if(length < minLength)
00127     {
00128       memcpy(targetPositions, p + 1, sizeof(targetPositions));
00129       minLength = length;
00130     }
00131   }
00132 }
00133 
00134 void ChallengeSymbols::challenge2Swap(Pose2D* p, int i, int j)
00135 {
00136   Pose2D t = p[i];
00137   p[i] = p[j];
00138   p[j] = t;
00139 }
00140 
00141 /*
00142 * Change Log
00143 * 
00144 * $Log: ChallengeSymbols.cpp,v $
00145 * Revision 1.2  2004/06/28 12:27:59  schumann
00146 * part 1 of the almost slam challenge behavior
00147 *
00148 * Revision 1.1.1.1  2004/05/22 17:16:57  cvsadm
00149 * created new repository GT2004_WM
00150 *
00151 * Revision 1.2  2004/03/08 00:58:54  roefer
00152 * Interfaces should be const
00153 *
00154 * Revision 1.1  2003/10/22 22:18:44  loetzsch
00155 * prepared the cloning of the GT2003BehaviorControl
00156 *
00157 */
00158 

Generated on Thu Sep 23 19:57:25 2004 for GT2004 by doxygen 1.3.6