00001
00002
00003
00004
00005
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
00034 }
00035
00036
00037
00038
00039 if(landmarksPercept.numberOfGoals == 2 && landmarksPercept.goals[0].distance > landmarksPercept.goals[1].distance)
00040 {
00041 tempGoal = landmarksPercept.goals[1];
00042 }
00043
00044
00045
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
00062
00063 if(refGoalvalid)
00064 {
00065 speed = 8 * fabs(referenceGoal.distance - tempGoal.distance)/(landmarksPercept.frameNumber - refGoalFramenr);
00066
00067 }
00068
00069
00070
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
00085
00086
00087
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
00113
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
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
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172