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

Modules/SelfLocator/NoOdometrySelfLocator.cpp

Go to the documentation of this file.
00001 /**
00002 * @file Modules/SelfLocator/NoOdometrySelfLocator.cpp
00003 * 
00004 * This file contains a class for self-localization based on SingleLandmarks w/o odometry.
00005 * @author <a href="mailto:spranger@informatik.hu-berlin.de">Michael Spranger</a>
00006 */
00007 
00008 #include "NoOdometrySelfLocator.h"
00009 #include "Tools/FieldDimensions.h"
00010 #include "Platform/SystemCall.h"
00011 
00012 
00013 
00014 NoOdometrySelfLocator::NoOdometrySelfLocator(const SelfLocatorInterfaces& interfaces)
00015 : SelfLocator(interfaces),refGoalvalid(false), debugflags(0), debugframes(10), speed(0)
00016 { 
00017 }
00018 
00019 void NoOdometrySelfLocator::execute()
00020 {
00021   
00022   
00023   robotPose.setFrameNumber(landmarksPercept.frameNumber);
00024   
00025   
00026   if(landmarksPercept.numberOfGoals)
00027   {
00028     Goal tempGoal = landmarksPercept.goals[0];
00029 
00030       
00031     double cameraOffset = 0;
00032     if(debugflags & 0x10){
00033       /*tempGoal     */
00034     }
00035         
00036     /*
00037      * if 2 goals are seen reference the one closest (in anticipation that the distance is mor correct
00038      */
00039     if(landmarksPercept.numberOfGoals == 2 && landmarksPercept.goals[0].distance > landmarksPercept.goals[1].distance)
00040     {
00041        tempGoal = landmarksPercept.goals[1];
00042     }
00043 
00044     /*
00045      * locate self by which goal is seen and distance to it
00046      */
00047     if(
00048       (getPlayer().getTeamColor() == Player::red && tempGoal.color == skyblue) 
00049       || 
00050       (getPlayer().getTeamColor() == Player::blue && tempGoal.color == yellow)
00051       )
00052     {
00053       robotPose.setPose( Pose2D(0,(-1 * (xPosOpponentGroundline - (tempGoal.distance + cameraOffset))), 0));
00054     }
00055     else
00056     {
00057       robotPose.setPose( Pose2D(0,(xPosOpponentGroundline - (tempGoal.distance + cameraOffset)), 0));
00058     }
00059     
00060     /*
00061      * calculate speed
00062      */
00063     if(refGoalvalid)
00064     {
00065       speed = 8 * fabs(referenceGoal.distance - tempGoal.distance)/(landmarksPercept.frameNumber - refGoalFramenr);
00066        
00067     }
00068 
00069     /*
00070      * set reference goal to the currentlyProcessed
00071      */
00072     referenceGoal = landmarksPercept.goals[0];
00073     refGoalFramenr = landmarksPercept.frameNumber;
00074     refGoalvalid = 1;
00075    
00076   }
00077   else
00078   {
00079     refGoalvalid=0;
00080   }
00081 
00082 
00083   /*
00084    * Debugging
00085    * frames & flags
00086    * flags is data [0]
00087    * frames is data[1]
00088    */
00089   if(debugframes && landmarksPercept.frameNumber % (int)debugframes == 0)
00090   {
00091     if(debugflags & 1)
00092     {
00093         OUTPUT(idText, text,"::speed:"<<speed);
00094     }
00095     if(2 & debugflags)
00096     {
00097         OUTPUT(idText, text,"::x:"<<robotPose.translation.x);
00098     }
00099     if(4 & debugflags)
00100     {
00101         OUTPUT(idText, text,"::y:"<<robotPose.translation.y);
00102     }
00103     if(8 & debugflags)
00104     {
00105         OUTPUT(idText, text,"::cOffx:"<<landmarksPercept.cameraOffset.x);
00106         OUTPUT(idText, text,"::cOffy:"<<landmarksPercept.cameraOffset.y);
00107         OUTPUT(idText, text,"::cOffz:"<<landmarksPercept.cameraOffset.z);
00108     }
00109   }
00110   /*
00111 
00112         OUTPUT(idText, text,"::distance:"<<landmarksPercept.goals[0].distance);
00113         OUTPUT(idText, text,"::xPosOpon:"<<xPosOpponentGroundline);
00114   */
00115   if(robotPose.translation.y != 0)
00116   {
00117         OUTPUT(idText, text, "ERROR!!!! y should not change.");
00118   }
00119 }
00120 
00121 bool NoOdometrySelfLocator::handleMessage(InMessage& message)
00122 {
00123   bool handled = false;
00124 
00125   switch(message.getMessageID())
00126   {
00127   // case id... : ... break;
00128 
00129   case idGenericDebugData:  GenericDebugData d;
00130                             message.bin >> d;
00131                             if(d.id == GenericDebugData::noOdometrySelfLocator)
00132                             {
00133                               OUTPUT(idText,text,
00134                                 "message handled by module NoOdometrySelfLocator");
00135                               debugflags = static_cast<int> (d.data[0]);
00136                               if(d.data[1])
00137                               {
00138                                 debugframes = static_cast<int>(d.data[1]);
00139                               }
00140                             }
00141                             handled = true;
00142                             break;
00143    }
00144 return handled;
00145 }
00146 /*
00147 * Change log :
00148 * 
00149 * $Log: NoOdometrySelfLocator.cpp,v $
00150 * Revision 1.2  2004/05/22 22:52:03  juengel
00151 * Renamed ballP_osition to ballModel.
00152 *
00153 * Revision 1.1.1.1  2004/05/22 17:20:48  cvsadm
00154 * created new repository GT2004_WM
00155 *
00156 * Revision 1.5  2004/03/08 02:11:48  roefer
00157 * Interfaces should be const
00158 *
00159 * Revision 1.4  2004/02/03 13:20:48  spranger
00160 * renamed all references to  class BallP_osition to BallModel (possibly changed include files)
00161 *
00162 * Revision 1.3  2003/12/18 11:48:45  spranger
00163 * added support for seeing 2 goals and some mor debugmessage handling
00164 *
00165 * Revision 1.2  2003/12/03 21:03:45  spranger
00166 * added DebugMessageHandling (handleMessage)
00167 *
00168 * Revision 1.1  2003/12/02 19:18:21  spranger
00169 * added NoOdometrySelfLocator
00170 *
00171 *
00172 */

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