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 at MIT 2001-2002 and Oxford 00010 // University 2003-2005. email: pnewman@robots.ox.ac.uk. 00011 // 00012 // This file is part of a MOOS Utility Component. 00013 // 00014 // This program is free software; you can redistribute it and/or 00015 // modify it under the terms of the GNU General Public License as 00016 // published by the Free Software Foundation; either version 2 of the 00017 // License, or (at your option) any later version. 00018 // 00019 // This program is distributed in the hope that it will be useful, 00020 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00022 // General Public License for more details. 00023 // 00024 // You should have received a copy of the GNU General Public License 00025 // along with this program; if not, write to the Free Software 00026 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00027 // 02111-1307, USA. 00028 // 00030 00031 // AcousticSignal.cpp: implementation of the CAcousticSignal class. 00032 // 00034 #ifdef _WIN32 00035 #pragma warning(disable : 4786) 00036 #endif 00037 #include <math.h> 00038 00039 #define DEFAULT_SIGNAL_RANGE 4000.0 00040 #define DEFAULT_SV 1498.0 00041 00042 #include "SimGlobalHelper.h" 00043 00044 #include "AcousticSignal.h" 00045 00046 00047 using namespace std; 00048 00050 // Construction/Destruction 00052 00053 CAcousticSignal::CAcousticSignal() 00054 { 00055 m_SrcPos.ReSize(3,1); 00056 m_SrcPos = 0; 00057 m_dfSV = DEFAULT_SV; 00058 m_dfStartTime = 0; 00059 00060 m_dfMaximumRange = DEFAULT_SIGNAL_RANGE; 00061 } 00062 00063 CAcousticSignal::CAcousticSignal(double dfX,double dfY,double dfZ,double dfStartTime) 00064 { 00065 m_SrcPos.ReSize(3,1); 00066 m_SrcPos<<dfX<<dfY<<dfZ; 00067 m_dfSV = DEFAULT_SV; 00068 m_dfStartTime =dfStartTime; 00069 m_dfMaximumRange = DEFAULT_SIGNAL_RANGE; 00070 00071 } 00072 00073 00074 CAcousticSignal::~CAcousticSignal() 00075 { 00076 00077 } 00078 00079 00080 double CAcousticSignal::GetExpectedIntersectionTime(Matrix & Location) 00081 { 00082 Matrix dP = (m_SrcPos-Location.SubMatrix(1,3,1,1)); 00083 // MOOSTraceMatrix(m_SrcPos,"Src"); 00084 // MOOSTraceMatrix(Location,"Location"); 00085 00086 00087 return m_dfStartTime+sqrt(dP.SumSquare())/m_dfSV; 00088 } 00089 00090 double CAcousticSignal::Age(double dfTimeNow) 00091 { 00092 return dfTimeNow-m_dfStartTime; 00093 } 00094 00095 bool CAcousticSignal::HasDecayed(double dfTimeNow) 00096 { 00097 return (dfTimeNow-m_dfStartTime)*m_dfSV>m_dfMaximumRange; 00098 } 00099 00100 bool CAcousticSignal::SetChannel(AcousticChannel eChannel) 00101 { 00102 m_eChannel = eChannel; 00103 00104 return true; 00105 } 00106 00107 AcousticChannel CAcousticSignal::GetChannel() 00108 { 00109 return m_eChannel; 00110 } 00111 00112 double CAcousticSignal::GetStartTime() 00113 { 00114 return m_dfStartTime; 00115 } 00116 00117 00119 AcousticChannel CAcousticSignal::ChannelFromString(string &sStr) 00120 { 00121 string sTmp = sStr; 00122 MOOSToUpper(sTmp); 00123 MOOSChomp(sTmp,"CH"); 00124 if(sTmp.empty()) 00125 { 00126 //must be something like IIF etc 00127 string sTmp = sStr; 00128 MOOSToUpper(sTmp); 00129 if(sTmp.find("IIF")!=string::npos) 00130 { 00131 return ACOUSTIC_CHAN_IIF; 00132 } 00133 else if(sTmp.find("CIF")!=string::npos) 00134 { 00135 return ACOUSTIC_CHAN_CIF; 00136 } 00137 else if(sTmp.find("IRF")!=string::npos) 00138 { 00139 return ACOUSTIC_CHAN_IRF; 00140 } 00141 else if(sTmp.find("CRF")!=string::npos) 00142 { 00143 return ACOUSTIC_CHAN_CRF; 00144 } 00145 else 00146 { 00147 MOOSTrace("Unknown channel!\n"); 00148 return ACOUSTIC_CHAN_ERROR; 00149 } 00150 00151 00152 } 00153 else 00154 { 00155 int nChan = atoi(sTmp.c_str()); 00156 return (AcousticChannel)nChan; 00157 00158 } 00159 00160 return ACOUSTIC_CHAN_ERROR; 00161 } 00162 00163 bool CAcousticSignal::SetSrcName(const string &sSrcName) 00164 { 00165 m_sSrcName = sSrcName; 00166 00167 return true; 00168 } 00169 00170 string CAcousticSignal::GetSrcName() 00171 { 00172 return m_sSrcName; 00173 }