00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "GT2005SelfLocatorSample.h"
00012
00013 GT2005SelfLocatorSample::GT2005SelfLocatorSample()
00014 {
00015 reset();
00016 }
00017
00018 GT2005SelfLocatorSample::GT2005SelfLocatorSample(const Pose2D& pose) :
00019 PoseSample(pose)
00020 {
00021 reset();
00022 }
00023
00024 void GT2005SelfLocatorSample::reset()
00025 {
00026
00027
00028 for(int i = 0; i < numberOfPerceptTypes; i++)
00029 {
00030 perceptProbabilities[i] = UNINITIALIZED_PROBABILITY;
00031 perceptTimestamps[i] = SystemCall::getCurrentSystemTime();
00032 }
00033 probability = UNINITIALIZED_PROBABILITY;
00034 isUsingOdometry = true;
00035 }
00036
00037
00038
00039
00040
00041 void GT2005SelfLocatorSample::updateProbability(const double* average, const GT2005SelfLocatorParameters& parameters)
00042 {
00043 probability = 1;
00044
00045
00046 for (int i=0; i<numberOfPerceptTypes; i++)
00047 {
00048 double alternateProb = max(average[i] - parameters.probNoQualityOffset, 0.000001);
00049
00050
00051
00052
00053
00054
00055
00056
00057 probability *= perceptProbabilities[i] > 1.0 ? alternateProb : perceptProbabilities[i];
00058 }
00059 }
00060
00061
00062
00063
00064
00065
00066
00067
00068 void GT2005SelfLocatorSample::setPerceptProbability(PerceptType type, double value, const GT2005SelfLocatorParameters& parameters)
00069 {
00070 if (type>=0 && type < numberOfPerceptTypes){
00071 double& q = perceptProbabilities[type];
00072
00073 perceptTimestamps[type] = SystemCall::getCurrentSystemTime();
00074
00075 if(type == goal || type == flag )
00076 {
00077 if(q > 1)
00078 q = value;
00079 else if(value < q)
00080 if(value < q - parameters.probFlagDownLimit)
00081 q -= parameters.probFlagDownLimit;
00082 else
00083 q = value;
00084 else
00085 if(value > q + parameters.probFlagUpLimit)
00086 q += parameters.probFlagUpLimit;
00087 else
00088 q = value;
00089 }
00090 else
00091 {
00092 if (q > 1)
00093 q = value;
00094 else
00095 if (value<q)
00096 if (value < q - parameters.probLineDownLimit)
00097 q -=parameters.probLineDownLimit;
00098 else
00099 q = value;
00100 else
00101 if (value > q + parameters.probLineUpLimit)
00102 q += parameters.probLineUpLimit;
00103 else
00104 q = value;
00105
00106 }
00107 }
00108 }
00109
00110 void GT2005SelfLocatorSample::scaleProbabilities(double factor)
00111 {
00112 for(int i = 0; i < numberOfPerceptTypes; ++i)
00113 if (perceptProbabilities[i] != UNINITIALIZED_PROBABILITY)
00114 perceptProbabilities[i] *= factor;
00115 }
00116
00117 In& operator>>(In& stream,GT2005SelfLocatorSample& sample)
00118 {
00119
00120 STREAM_REGISTER_BEGIN_EXT(sample);
00121 STREAM_BASE_EXT( stream, (Pose2D&) sample);
00122 STREAM_EXT(stream, sample.probability);
00123 STREAM_ARRAY_EXT(stream, sample.perceptProbabilities);
00124 STREAM_ARRAY_EXT(stream, sample.perceptTimestamps);
00125 STREAM_EXT(stream, sample.isUsingOdometry);
00126 STREAM_EXT(stream, sample.camera);
00127 STREAM_REGISTER_FINISH();
00128 return stream;
00129 }
00130
00131 Out& operator<<(Out& stream, const GT2005SelfLocatorSample& sample)
00132 {
00133 STREAM_REGISTER_BEGIN_EXT(sample);
00134 STREAM_BASE_EXT( stream, (Pose2D&) sample);
00135 STREAM_EXT(stream, sample.probability);
00136 STREAM_ARRAY_EXT(stream, sample.perceptProbabilities);
00137 STREAM_ARRAY_EXT(stream, sample.perceptTimestamps);
00138 STREAM_EXT(stream, sample.isUsingOdometry);
00139 STREAM_EXT(stream, sample.camera);
00140 STREAM_REGISTER_FINISH();
00141 return stream;
00142 }