MOOS 0.2375
|
00001 00002 // 00003 // MOOS - Mission Oriented Operating Suite 00004 // 00005 // A suit of Applications and Libraries for Mobile Robotics Research 00006 // Copyright (C) 2001-2005 Massachusetts Institute of Technology and 00007 // Oxford University. 00008 // 00009 // This software was written by Paul Newman and others 00010 // at MIT 2001-2002 and Oxford University 2003-2005. 00011 // email: pnewman@robots.ox.ac.uk. 00012 // 00013 // This file is part of a MOOS Basic (Common) Application. 00014 // 00015 // This program is free software; you can redistribute it and/or 00016 // modify it under the terms of the GNU General Public License as 00017 // published by the Free Software Foundation; either version 2 of the 00018 // License, or (at your option) any later version. 00019 // 00020 // This program is distributed in the hope that it will be useful, 00021 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00023 // General Public License for more details. 00024 // 00025 // You should have received a copy of the GNU General Public License 00026 // along with this program; if not, write to the Free Software 00027 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00028 // 02111-1307, USA. 00029 // 00031 // MOOSNavObsStore.cpp: implementation of the CMOOSNavObsStore class. 00032 // 00034 00035 #include "MOOSNavObsStore.h" 00036 00038 // Construction/Destruction 00040 00041 CMOOSNavObsStore::CMOOSNavObsStore() 00042 { 00043 //lets store 20 seconds of data by default.. 00044 m_dfSpan = 20; 00045 m_dfNewestObsTime = 0; 00046 } 00047 00048 CMOOSNavObsStore::~CMOOSNavObsStore() 00049 { 00050 00051 } 00052 00053 bool CMOOSNavObsStore::Add(OBSLIST &ObsList) 00054 { 00055 if(ObsList.empty()) 00056 { 00057 return true; 00058 } 00059 00060 OBSLIST::iterator p; 00061 00062 for(p = ObsList.begin();p!=ObsList.end();p++) 00063 { 00064 CMOOSObservation & rObs = *p; 00065 00066 // MOOSTrace("adding:"); 00067 // rObs.Trace(); 00068 00069 CMOOSObservation::Type eType = rObs.m_eType; 00070 00071 00072 OBSLIST* pList = GetListByType(eType); 00073 00074 if(pList!=NULL) 00075 { 00076 00077 //store time of most recent addition 00078 if(rObs.m_dfTime>m_dfNewestObsTime) 00079 m_dfNewestObsTime = rObs.m_dfTime; 00080 00081 //insert it in the right spot 00082 OBSLIST::iterator q; 00083 for(q =pList->begin();q!=pList->end();q++) 00084 { 00085 if(rObs.m_dfTime>=(*q).m_dfTime) 00086 { 00087 pList->insert(q,rObs); 00088 break; 00089 } 00090 } 00091 if(q==pList->end()) 00092 { 00093 pList->push_back(rObs); 00094 } 00095 00096 //now remove data that is too old.. 00097 while(!pList->empty() && pList->front().m_dfTime-pList->back().m_dfTime>m_dfSpan) 00098 { 00099 pList->pop_back(); 00100 } 00101 } 00102 else 00103 { 00104 m_ObsListMap[eType] = ObsList; 00105 } 00106 } 00107 00108 return true; 00109 00110 } 00111 00112 OBSLIST * CMOOSNavObsStore::GetListByType(CMOOSObservation::Type eType) 00113 { 00114 //find the relevant list 00115 OBSLISTMAP::iterator p = m_ObsListMap.find(eType); 00116 00117 if(p!=m_ObsListMap.end()) 00118 { 00119 return & p->second; 00120 } 00121 00122 return NULL; 00123 00124 } 00125 00126 //all we do here is mark the original observation as 00127 //used. Note falgs like bGoodDA and bIgnore are not copiued 00128 //back. This means that every fetch from the store comes with 00129 //clean observations. Apart from those that have already been used 00130 //and which are never even passed out! 00131 bool CMOOSNavObsStore::MarkAsUsed(OBSLIST &ToMarkList) 00132 { 00133 OBSLIST::iterator r; 00134 00135 bool bFound = false; 00136 00137 //for all the obs we are given 00138 for(r = ToMarkList.begin();r!=ToMarkList.end();r++) 00139 { 00140 bFound = false; 00141 00142 CMOOSObservation & rObsToFind = *r; 00143 00144 OBSLISTMAP::iterator p; 00145 00146 //for all the lists of obs we are storing 00147 for(p = m_ObsListMap.begin();p!=m_ObsListMap.end() && !bFound;p++) 00148 { 00149 OBSLIST & rList = p->second; 00150 OBSLIST::iterator q; 00151 00152 //for all the obs stored in that list 00153 for(q = rList.begin();q!=rList.end() && !bFound ;q++) 00154 { 00155 CMOOSObservation & rObsStored = *q; 00156 if(rObsStored.GetID() == rObsToFind.GetID()) 00157 { 00158 //found it! 00159 rObsStored.m_bUsed = true; 00160 bFound = true; 00161 } 00162 } 00163 } 00164 } 00165 00166 return true; 00167 } 00168 00169 bool CMOOSNavObsStore::SetSpan(double dfSpan) 00170 { 00171 m_dfSpan = dfSpan; 00172 return true; 00173 } 00174 00175 bool CMOOSNavObsStore::Flush() 00176 { 00177 00178 OBSLISTMAP::iterator p; 00179 00180 //for all the lists of obs we are storing 00181 for(p = m_ObsListMap.begin();p!=m_ObsListMap.end();p++) 00182 { 00183 OBSLIST & rList = p->second; 00184 rList.clear(); 00185 } 00186 00187 return true; 00188 } 00189 00190 bool CMOOSNavObsStore::GetObservationsBetween(OBSLIST &ObsList, double dfT1, double dfT2) 00191 { 00192 ObsList.clear(); 00193 00194 OBSLISTMAP::iterator p; 00195 for(p = m_ObsListMap.begin();p!=m_ObsListMap.end();p++) 00196 { 00197 OBSLIST & rList = p->second; 00198 OBSLIST::iterator q; 00199 00200 bool bDone = false; 00201 for(q = rList.begin();q!=rList.end();q++) 00202 { 00203 //starting at youngest and getting older... 00204 CMOOSObservation & rObs = *q; 00205 00206 if(rObs.IsType(CMOOSObservation::LBL_BEACON_2WR)) 00207 { 00208 int lk = 0; 00209 } 00210 00211 // rObs.Trace(); 00212 // MOOSTrace("Stored Obs t = %f cut off = %f\n",rObs.m_dfTime,dfCutOffTime); 00213 if(rObs.m_dfTime>=dfT1 && rObs.m_dfTime<=dfT2 ) 00214 { 00215 if(!rObs.m_bUsed) 00216 { 00217 00218 if(rObs.IsType(CMOOSObservation::LBL_BEACON_2WR)) 00219 { 00220 int lk = 0; 00221 } 00222 00223 00224 //put on outlist with older data towards back of list 00225 ObsList.push_back(rObs); 00226 } 00227 } 00228 } 00229 } 00230 00231 return true; 00232 } 00233 00234 double CMOOSNavObsStore::GetNewestObsTime() 00235 { 00236 return m_dfNewestObsTime; 00237 }