00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "ArExport.h"
00028 #include "ariaOSDef.h"
00029 #include "ArInterpolation.h"
00030
00031 ArInterpolation::ArInterpolation(size_t numberOfReadings)
00032 {
00033 mySize = numberOfReadings;
00034
00035 }
00036
00037 ArInterpolation::~ArInterpolation()
00038 {
00039
00040 }
00041
00042 bool ArInterpolation::addReading(ArTime timeOfReading,
00043 ArPose position)
00044 {
00045 if (myTimes.size() >= mySize)
00046 {
00047 myTimes.pop_back();
00048 myPoses.pop_back();
00049 }
00050 myTimes.push_front(timeOfReading);
00051 myPoses.push_front(position);
00052 return true;
00053 }
00054
00063 int ArInterpolation::getPose(ArTime timeStamp,
00064 ArPose *position)
00065 {
00066 std::list<ArTime>::iterator tit;
00067 std::list<ArPose>::iterator pit;
00068
00069 ArPose thisPose;
00070 ArTime thisTime;
00071 ArPose lastPose;
00072 ArTime lastTime;
00073
00074 ArTime nowTime;
00075 long total;
00076 long toStamp;
00077 double percentage;
00078 ArPose retPose;
00079
00080
00081 for (tit = myTimes.begin(), pit = myPoses.begin();
00082 tit != myTimes.end() && pit != myPoses.end();
00083 ++tit, ++pit)
00084 {
00085 lastTime = thisTime;
00086 lastPose = thisPose;
00087
00088 thisTime = (*tit);
00089 thisPose = (*pit);
00090
00091
00092
00093 if (!timeStamp.isAfter(thisTime))
00094 {
00095
00096 break;
00097 }
00098
00099 }
00100
00101 if (tit == myTimes.end() || pit == myPoses.end())
00102 {
00103
00104 return -2;
00105 }
00106
00107
00108 if ((tit == myTimes.begin() || pit == myPoses.begin()) &&
00109 !timeStamp.isAt((*tit)))
00110 {
00111
00112
00113 thisTime = (*tit);
00114 thisPose = (*pit);
00115 tit++;
00116 pit++;
00117 if (tit == myTimes.end() || pit == myPoses.end())
00118 {
00119
00120 return -3;
00121 }
00122 lastTime = (*tit);
00123 lastPose = (*pit);
00124 nowTime.setToNow();
00125 total = thisTime.mSecSince(lastTime);
00126 if (total == 0)
00127 total = 100;
00128 toStamp = nowTime.mSecSince(thisTime);
00129 percentage = (double)toStamp/(double)total;
00130
00131 if (percentage > 3)
00132 return -1;
00133
00134 retPose.setX(thisPose.getX() +
00135 (thisPose.getX() - lastPose.getX()) * percentage);
00136 retPose.setY(thisPose.getY() +
00137 (thisPose.getY() - lastPose.getY()) * percentage);
00138 retPose.setTh(ArMath::addAngle(thisPose.getTh(),
00139 ArMath::subAngle(thisPose.getTh(),
00140 lastPose.getTh())
00141 * percentage));
00142 *position = retPose;
00143 return 0;
00144 }
00145
00146
00147
00148
00149
00150 total = thisTime.mSecSince(lastTime);
00151 toStamp = thisTime.mSecSince(timeStamp);
00152 percentage = (double)toStamp/(double)total;
00153
00154 retPose.setX(thisPose.getX() +
00155 (lastPose.getX() - thisPose.getX()) * percentage);
00156 retPose.setY(thisPose.getY() +
00157 (lastPose.getY() - thisPose.getY()) * percentage);
00158 retPose.setTh(ArMath::addAngle(thisPose.getTh(),
00159 ArMath::subAngle(lastPose.getTh(),
00160 thisPose.getTh())
00161 * percentage));
00162
00163
00164
00165
00166
00167
00168
00169
00170 *position = retPose;
00171 return 1;
00172
00173 }
00174
00175 size_t ArInterpolation::getNumberOfReadings(void) const
00176 {
00177 return mySize;
00178 }
00179
00180 void ArInterpolation::setNumberOfReadings(size_t numberOfReadings)
00181 {
00182 while (myTimes.size() > numberOfReadings)
00183 {
00184 myTimes.pop_back();
00185 myPoses.pop_back();
00186 }
00187 mySize = numberOfReadings;
00188 }
00189
00190 void ArInterpolation::reset(void)
00191 {
00192 while (myTimes.size() > 0)
00193 myTimes.pop_back();
00194 while (myPoses.size() > 0)
00195 myPoses.pop_back();
00196 }
00197
00198