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 the Seagrant AUV lab (R.Damus et.al) 00010 // and Paul Newman at MIT 2001-2002 and Oxford University 2003-2005. 00011 // email: pnewman@robots.ox.ac.uk. rdamus@mit.edu 00012 // 00013 // This file is part of a MOOS Instrument 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 // DVLInstrument.cpp: implementation of the CDVLInstrument class. 00032 // 00034 #include <MOOSLIB/MOOSLib.h> 00035 #include <iostream> 00036 #include <cstring> 00037 00038 using namespace std; 00039 00040 #include "DVLInstrument.h" 00041 00042 00043 #ifndef PI 00044 #define PI 3.141592653589793 00045 #endif 00046 00048 // Construction/Destruction 00050 00051 CDVLInstrument::CDVLInstrument() 00052 { 00053 //some sensible defaults (missionfile can overwrite this) 00054 SetAppFreq(10); 00055 SetCommsFreq(10); 00056 m_dfLastSummary = 0; 00057 m_dfAlignment = -45; 00058 m_bExposeVelocities = false; 00059 m_eType = MOOS_DVL_SENSOR_RDI; 00060 } 00061 00062 CDVLInstrument::~CDVLInstrument() 00063 { 00064 00065 } 00066 00067 00070 bool CDVLInstrument::Iterate() 00071 { 00072 00073 if(GetData()) 00074 { 00075 PublishData(); 00076 } 00077 00078 return true; 00079 } 00080 00081 00082 bool CDVLInstrument::OnStartUp() 00083 { 00084 CMOOSInstrument::OnStartUp(); 00085 00086 00087 //here we make the variables that we are managing 00088 double dfDVLPeriod = 0.2; 00089 //Earth Referenced Distance Traveled 00090 AddMOOSVariable("EARTH_EAST", "SIM_X", "DVL_X", dfDVLPeriod); 00091 AddMOOSVariable("EARTH_NORTH", "SIM_Y", "DVL_Y", dfDVLPeriod); 00092 AddMOOSVariable("EARTH_UP", "SIM_Z", "DVL_Z", dfDVLPeriod); 00093 AddMOOSVariable("EARTH_FRESH", "", "DVL_FRESHNESS",dfDVLPeriod); 00094 00095 //Earth Referenced Velocity Data 00096 AddMOOSVariable("EARTH_VEL_EAST", "", "DVL_EARTH_VEL_X", dfDVLPeriod); 00097 AddMOOSVariable("EARTH_VEL_NORTH", "", "DVL_EARTH_VEL_Y", dfDVLPeriod); 00098 AddMOOSVariable("EARTH_VEL_UP", "", "DVL_EARTH_VEL_Z", dfDVLPeriod); 00099 AddMOOSVariable("EARTH_VEL_STATUS", "", "DVL_EARTH_VEL_STATUS", dfDVLPeriod); 00100 00101 //AUV referenced Velocity Data 00102 AddMOOSVariable("AUV_VEL_EAST", "", "DVL_BODY_VEL_X", dfDVLPeriod); 00103 AddMOOSVariable("AUV_VEL_NORTH", "", "DVL_BODY_VEL_Y", dfDVLPeriod); 00104 AddMOOSVariable("AUV_VEL_UP", "", "DVL_BODY_VEL_Z", dfDVLPeriod); 00105 AddMOOSVariable("AUV_VEL_STATUS", "", "DVL_AUV_VEL_STATUS", dfDVLPeriod); 00106 00107 //AUV referenced Attitude Data 00108 AddMOOSVariable("PITCH", "SIM_PITCH", "DVL_PITCH", dfDVLPeriod); 00109 AddMOOSVariable("ROLL", "SIM_ROLL", "DVL_ROLL", dfDVLPeriod); 00110 AddMOOSVariable("YAW", "SIM_YAW", "DVL_YAW", dfDVLPeriod); 00111 AddMOOSVariable("HEADING", "SIM_HEADING", "DVL_HEADING", dfDVLPeriod); 00112 AddMOOSVariable("SPEED", "SIM_SPEED", "DVL_SPEED", dfDVLPeriod); 00113 AddMOOSVariable("ALTITUDE", "SIM_ALTITUDE", "DVL_ALTITUDE", dfDVLPeriod); 00114 00115 //Register for the variable that will provide for dynamic configuration 00116 //of the DVL 00117 AddMOOSVariable("UPDATE_CMD", "DVL_UPDATE", "DVL_UPDATE_REPLY", dfDVLPeriod); 00118 00119 RegisterMOOSVariables(); 00120 00121 //get DVL alignment 00122 m_dfAlignment = -45; 00123 m_MissionReader.GetConfigurationParam("Alignment",m_dfAlignment); 00124 00125 00126 //search the setup file for the Magnetic Offset 00127 GetMagneticOffset(); 00128 00129 //use the *pfn callback routine in the SerialPort to notify that we are interested 00130 //in using the prompt given back to us by the RDI 00131 //Error Message for Unrecognized Command: ERR 010: UNRECOGNIZED COMMAND 00132 //Error Message for Out of bounds Command: ERR 045: PARAMETER OUT OF BOUNDS 00133 //Common to both error message strings is ERR 00134 00135 SetPrompt(">"); 00136 SetInstrumentErrorMessage("ERR"); 00137 00138 if(IsSimulateMode()) 00139 { 00140 SetAppFreq(10); 00141 SetCommsFreq(8); 00142 } 00143 else 00144 { 00145 00146 //try to open 00147 if(!SetupPort()) 00148 { 00149 return false; 00150 } 00151 00152 //try 10 times to initialise sensor 00153 if(!InitialiseSensorN(10,"DVL")) 00154 { 00155 return false; 00156 } 00157 00158 } 00159 return true; 00160 } 00161 00162 00163 00164 bool CDVLInstrument::OnNewMail(MOOSMSG_LIST &NewMail) 00165 { 00166 CMOOSMsg Msg; 00167 double dfTimeNow = MOOSTime(); 00168 00169 00170 if(m_Comms.PeekMail(NewMail,"DVL_SUMMARY_REQUIRED",Msg)) 00171 { 00172 m_bExposeVelocities = MOOSStrCmp(Msg.m_sVal,"TRUE"); 00173 } 00174 00175 if(m_Comms.PeekMail(NewMail,"DVL_UPDATE",Msg)) 00176 { 00177 MOOSTrace("..............new DVL_UPDATE: %s\n", Msg.m_sVal.c_str()); 00178 ExecuteDVLUpdateCommands(Msg); 00179 } 00180 00181 return UpdateMOOSVariables(NewMail); 00182 } 00183 00184 bool CDVLInstrument::PublishData() 00185 { 00186 if(m_bExposeVelocities && MOOSTime()-m_dfLastSummary>2.0) 00187 { 00188 m_dfLastSummary = MOOSTime(); 00189 00190 CMOOSVariable * pBVX = GetMOOSVar("AUV_VEL_EAST"); 00191 CMOOSVariable * pBVY = GetMOOSVar("AUV_VEL_NORTH"); 00192 00193 string sText = "NO DVL"; 00194 00195 if(pBVX && pBVY) 00196 { 00197 00198 sText = MOOSFormat("DVL Body Vel Y = %7.2f X = %7.2f %s", 00199 pBVY->GetDoubleVal(), 00200 pBVX->GetDoubleVal(), 00201 (pBVX->IsFresh() && pBVY->IsFresh()) ? "OK":"STALE"); 00202 00203 } 00204 00205 MOOSDebugWrite(sText); 00206 00207 } 00208 00209 return PublishFreshMOOSVariables(); 00210 } 00211 00212 00213 00214 bool CDVLInstrument::OnConnectToServer() 00215 { 00216 if(IsSimulateMode()) 00217 { 00218 RegisterMOOSVariables(); 00219 00220 } 00221 00222 m_Comms.Register("DVL_SUMMARY_REQUIRED",0.0); 00223 00224 return true; 00225 } 00226 00227 00229 // here we initialise the sensor, giving it start up values 00230 bool CDVLInstrument::InitialiseSensor() 00231 { 00232 #define MAXTRIES 10 00233 int nTries = 0; 00234 00235 00236 TERMPAIRLIST InitCmds; 00237 00238 //STRING_LIST sInitCmds; 00239 00240 //The DVL replies with a '>' prompt 00241 m_Port.SetTermCharacter(m_sPrompt.c_str()[0]); 00242 00243 //Wake up the sensor 00244 m_Port.Break(); 00245 MOOSPause(1000); 00246 00247 //XXX: Navigator DVL for Caribou does not recognize all the commands 00248 //XXX: that the Workhorse on Xanthos does. Therefore, commented out 00249 //XXX: lines reflect this change - 3/12/02 00250 00251 InitCmds.push_back(SendTermPair("CB411\r", m_sPrompt.c_str())); 00252 InitCmds.push_back(SendTermPair("CF11010\r",m_sPrompt.c_str())); 00253 // InitCmds.push_back(SendTermPair("CD111110000\r",m_sPrompt)); 00254 InitCmds.push_back(SendTermPair("PD6\r",m_sPrompt.c_str())); 00255 InitCmds.push_back(SendTermPair("TC0000\r",m_sPrompt.c_str())); 00256 InitCmds.push_back(SendTermPair("TE00:00:00.00\r",m_sPrompt.c_str())); 00257 InitCmds.push_back(SendTermPair("TP00:01.00\r",m_sPrompt.c_str())); 00258 // InitCmds.push_back(SendTermPair("WP1\r",m_sPrompt.c_str())); 00259 InitCmds.push_back(SendTermPair("BM5\r",m_sPrompt.c_str())); 00260 // InitCmds.push_back(SendTermPair("BX00050\r",m_sPrompt.c_str())); 00261 InitCmds.push_back(SendTermPair("BP1\r",m_sPrompt.c_str())); 00262 InitCmds.push_back(SendTermPair("BK0\r",m_sPrompt.c_str())); 00263 // InitCmds.push_back(SendTermPair("BA030\r",m_sPrompt.c_str())); 00264 InitCmds.push_back(SendTermPair("BS\r",m_sPrompt.c_str())); 00265 InitCmds.push_back(SendTermPair("EX10110\r",m_sPrompt.c_str())); 00266 InitCmds.push_back(SendTermPair("EZ1011101\r",m_sPrompt.c_str())); 00267 InitCmds.push_back(SendTermPair("ED0\r",m_sPrompt.c_str())); 00268 00269 00270 string sEA = MOOSFormat("EA%d\r",-(int)m_dfAlignment*100); 00271 string sEB = MOOSFormat("EB%d\r",(int)m_dfAlignment*100); 00272 00273 InitCmds.push_back(SendTermPair(sEA,m_sPrompt.c_str())); 00274 InitCmds.push_back(SendTermPair(sEB,m_sPrompt.c_str())); 00275 00276 InitCmds.push_back(SendTermPair("CS\r",m_sPrompt.c_str())); 00277 00278 00279 //sInitCmds.push_back("CB411\r\n"); 00280 00281 00282 //STRING_LIST::iterator p; 00283 TERMPAIRLIST::iterator p; 00284 00285 string sWhatReply; 00286 00287 double dfWhen; 00288 00289 for(p = InitCmds.begin(); p != InitCmds.end(); p) 00290 { 00291 SendTermPair & rToDo = *p; 00292 //string sCmd = *p; 00293 00294 //make sure to pause before reading the reply 00295 //@9600bps, DVL may not react fast enough 00296 MOOSPause(500); 00297 00298 while(!m_Port.GetLatest(sWhatReply,dfWhen)) 00299 { 00300 MOOSPause(10); 00301 } 00302 00303 //check reply... 00304 //if(GoodReply(sCmd, sWhatReply)) 00305 if(GoodReply(sWhatReply)) 00306 { 00307 m_Port.Write((char *)rToDo.sSend.c_str(),rToDo.sSend.size()); 00308 //m_Port.Write((char *)rToDo.sSend.c_str(),rToDo.sSend.size()); 00309 //m_Port.Write((char*)sCmd.c_str(),sCmd.size()); 00310 00311 p++; 00312 00313 } 00314 else 00315 { 00316 MOOSTrace("D'oh!\n"); 00317 if(nTries++ > MAXTRIES) 00318 return false; 00319 } 00320 00321 00322 } 00323 00324 //Need to put the device back in a mode where it looks for <CR> 00325 //to delimit a Telegram 00326 m_Port.SetTermCharacter('\r'); 00327 00328 return true; 00329 } 00330 00331 00340 bool CDVLInstrument::GetData() 00341 { 00342 if(!IsSimulateMode()) 00343 { 00344 //here we actually access serial ports etc 00345 string sWhat; 00346 double dfWhen; 00347 00348 if(m_Port.IsStreaming()) 00349 { 00350 if(!m_Port.GetLatest(sWhat,dfWhen)) 00351 { 00352 00353 return false; 00354 } 00355 } 00356 else 00357 { 00358 MOOSTrace("DVL Must be streaming..\n"); 00359 00360 return false; 00361 00362 } 00363 00364 00365 ParseRDIReply(sWhat); 00366 00367 00368 } 00369 else 00370 { 00371 //in simulated mode there is nothing to do..all data 00372 //arrives via comms. 00373 } 00374 00375 return true; 00376 00377 } 00378 00390 bool CDVLInstrument::ParseRDIReply(string &sReply) 00391 { 00392 string sCopy = sReply; 00393 string sWhat = MOOSChomp(sReply,","); 00394 00395 double dfTimeNow = MOOSTime(); 00396 00397 if(sWhat==":SA") 00398 { 00399 //Vehicle Attitude Information 00400 double dfPitch = atof(MOOSChomp(sReply,",").c_str()); 00401 double dfRoll = atof(MOOSChomp(sReply,",").c_str()); 00402 double dfHeading = atof(MOOSChomp(sReply,",").c_str()); 00403 00404 SetMOOSVar("PITCH",PI/180.0*dfPitch,dfTimeNow); 00405 SetMOOSVar("YAW",PI/180.0*dfHeading,dfTimeNow); 00406 SetMOOSVar("ROLL",PI/180.0*dfRoll, dfTimeNow); 00407 SetMOOSVar("HEADING",dfHeading, dfTimeNow); 00408 00409 00410 } 00411 else if (sWhat == ":BI") 00412 { 00413 //Bottom Track, Instrument Referenced Velocity Data 00414 // 00415 //X axis: Beam1 Beam2 xdcr movement relative to bottom 00416 //Y axis: Beam4 Beam3 xdcr movement relative to bottom 00417 //Z axis: Transducre movement away from bottom 00418 //Error is the error velocity 00419 //The status is either 'A' = Good or 'V' = Bad 00420 int nXaxisVel = (int)atof(MOOSChomp(sReply,",").c_str()); 00421 int nYaxisVel = (int)atof(MOOSChomp(sReply,",").c_str()); 00422 int nZaxisVel = (int)atof(MOOSChomp(sReply,",").c_str()); 00423 int nErrorVel = (int)atof(MOOSChomp(sReply,",").c_str()); 00424 string sStatus = MOOSChomp(sReply,","); 00425 00426 if (sStatus == "A") 00427 { 00428 //SetMOOSVar here 00429 //Convert to m/s 00430 } 00431 else if (sStatus == "V") 00432 { 00433 //alert to failure 00434 } 00435 00436 } 00437 else if (sWhat == ":BS") 00438 { 00439 //Bottom Track, Ship Referenced Velocity Data 00440 // 00441 //RDI defines positive as Right Handed with Y extending through the Bow 00442 //and X extending out through Starboard. This makes Z positive upwards, 00443 //extending away from the bottom. 00444 // 00445 //Transverse is the Port-Stbd ship movement 00446 //Longitudinal is the Aft-Fwd ship movement 00447 //Normal is the ship movement away from bottom 00448 //The status is either 'A' = Good or 'V' = Bad 00449 int nTransVel = (int)atof(MOOSChomp(sReply,",").c_str()); 00450 int nLongVel = (int)atof(MOOSChomp(sReply,",").c_str()); 00451 int nNormalVel = (int)atof(MOOSChomp(sReply,",").c_str()); 00452 string sStatus = MOOSChomp(sReply,","); 00453 00454 if (sStatus == "A") 00455 { 00456 //SetMOOSVar here 00457 //Convert to m/s 00458 SetMOOSVar("AUV_VEL_EAST",nTransVel*.001,dfTimeNow); 00459 SetMOOSVar("AUV_VEL_NORTH",nLongVel*.001,dfTimeNow); 00460 SetMOOSVar("AUV_VEL_UP",nNormalVel*.001,dfTimeNow); 00461 SetMOOSVar("AUV_VEL_STATUS",sStatus,dfTimeNow); 00462 } 00463 else if (sStatus == "V") 00464 { 00465 //alert to failure 00466 SetMOOSVar("AUV_VEL_STATUS",sStatus,dfTimeNow); 00467 } 00468 00469 00470 } 00471 else if (sWhat == ":BE") 00472 { 00473 //Bottom Track, Earth Referenced Velocity Data 00474 // 00475 //East is the ADCP movement to East 00476 //North is the ADCP movement to North 00477 //Upward is the ADCP movement to Surface 00478 //The status is either 'A' = Good or 'V' = Bad 00479 int nEastVel = (int)atof(MOOSChomp(sReply,",").c_str()); 00480 int nNorthVel = (int)atof(MOOSChomp(sReply,",").c_str()); 00481 int nUpwardVel = (int)atof(MOOSChomp(sReply,",").c_str()); 00482 string sStatus = MOOSChomp(sReply,","); 00483 00484 if (sStatus == "A") 00485 { 00486 //SetMOOSVar here 00487 //Convert to m/s 00488 SetMOOSVar("EARTH_VEL_NORTH",nNorthVel*.001,dfTimeNow); 00489 SetMOOSVar("EARTH_VEL_EAST",nEastVel*.001,dfTimeNow); 00490 SetMOOSVar("EARTH_VEL_UP",nUpwardVel*.001,dfTimeNow); 00491 SetMOOSVar("EARTH_VEL_STATUS",sStatus,dfTimeNow); 00492 } 00493 else if (sStatus == "V") 00494 { 00495 //alert to failure 00496 SetMOOSVar("EARTH_VEL_STATUS",sStatus,dfTimeNow); 00497 } 00498 00499 } 00500 else if (sWhat == ":BD") 00501 { 00502 //Bottom Track, Earth Referenced Distance Data 00503 // 00504 //East is the distance East in meters 00505 //North is the distance North in meters 00506 //Upward is the distance Upward in meters 00507 //Bottom is the range to bottom in meters 00508 //Time is the Time since last good velocity estimate in seconds 00509 double dfEastDist = atof(MOOSChomp(sReply,",").c_str()); 00510 double dfNorthDist = atof(MOOSChomp(sReply,",").c_str()); 00511 double dfUpDist = atof(MOOSChomp(sReply,",").c_str()); 00512 double dfBottomDist = atof(MOOSChomp(sReply,",").c_str()); 00513 double dfTimeSinceGood = atof(MOOSChomp(sReply,",").c_str()); 00514 00515 if(dfBottomDist!=0 && dfTimeSinceGood<3.0) 00516 { 00517 //no status here so use time and altitude as measure of success 00518 SetMOOSVar("ALTITUDE",dfBottomDist,dfTimeNow); 00519 SetMOOSVar("EARTH_NORTH",dfNorthDist,dfTimeNow); 00520 SetMOOSVar("EARTH_EAST",dfEastDist,dfTimeNow); 00521 SetMOOSVar("EARTH_UP",dfUpDist,dfTimeNow); 00522 SetMOOSVar("EARTH_FRESH",dfTimeSinceGood,dfTimeNow); 00523 } 00524 } 00525 else if(sWhat == ":TS") 00526 { 00527 MOOSChomp(sReply,","); 00528 00529 double dfSalinity = atof(MOOSChomp(sReply,",").c_str()); 00530 double dfTemp = atof(MOOSChomp(sReply,",").c_str()); 00531 double dfDepth = atof(MOOSChomp(sReply,",").c_str()); 00532 double dfSoundSpeed = atof(MOOSChomp(sReply,",").c_str()); 00533 double dfBIT = atof(MOOSChomp(sReply,",").c_str()); 00534 } 00535 else 00536 { 00537 //This was a response we are not expecting 00538 MOOSTrace("Unknown RDI reply %s\n",sWhat.c_str()); 00539 return false; 00540 } 00541 00542 00543 //we are here so we processed the string 00544 if(PublishRaw()) 00545 { 00546 //yep user want to see raw data... 00547 m_Comms.Notify("DVL_RAW",sCopy); 00548 } 00549 00550 return true; 00551 } 00552 00553 00554 00555 00556 00557 bool CDVLInstrument::GoodReply(string sReply) 00558 { 00559 00560 //look for the prompt and an error 00561 //keep track of where each resides 00562 const char * pPrompt = strstr(sReply.c_str(), m_sPrompt.c_str()); 00563 const char * pError = strstr(sReply.c_str(), m_sInstrumentErrorMessage.c_str()); 00564 00565 if((pError != NULL) && (pPrompt != NULL)) 00566 return false; 00567 else if((pError != NULL) && (pPrompt == NULL)) 00568 return false; 00569 else if((pError == NULL) && (pPrompt == NULL)) 00570 return false; 00571 else 00572 return true; 00573 00574 } 00575 00576 00577 bool CDVLInstrument::ExecuteDVLUpdateCommands(CMOOSMsg &Msg) 00578 { 00579 #define FRESH_UPDATE 30.0 00580 string sCmdUpdateStatus; 00581 double dfTimeNow = MOOSTime(); 00582 00583 //only interested in the string message of comma separated 00584 //values for the DVL. 00585 string sNewCmdString = Msg.m_sVal; 00586 MOOSTrace("Update DVL: Cmd - [%s] - Size - %d \n", sNewCmdString.c_str(), sNewCmdString.size()); 00587 00588 //check for skewedness 00589 if(NewCommandsAreSkewed(Msg, dfTimeNow, sNewCmdString)) 00590 return false; 00591 00592 //Stop the DVL from streaming and get it's attention 00593 if(!GetDVLAttention()) 00594 return false; 00595 00596 //send the commands 00597 if(SendDVLUpdatedCommands(sCmdUpdateStatus, sNewCmdString)) 00598 { 00599 //Set the UPDATE_DVL_REPLY variable to indicate success 00600 MOOSTrace("Update DVL: Pinging Restarted\n"); 00601 SetMOOSVar("UPDATE_CMD", sCmdUpdateStatus, dfTimeNow); 00602 00603 //reset the Termination character 00604 m_Port.SetTermCharacter('\r'); 00605 00606 //start the sensor pinging again 00607 StartPinging(); 00608 00609 } 00610 else 00611 { 00612 MOOSTrace("Update DVL: Failure - Pinging Not Restarted\n"); 00613 SetMOOSVar("UPDATE_CMD", sCmdUpdateStatus, dfTimeNow); 00614 } 00615 00616 //show the outcome to the DB 00617 PublishFreshMOOSVariables(); 00618 00619 return true; 00620 } 00621 00625 void CDVLInstrument::StartPinging() 00626 { 00627 00628 SendTermPair keepPinging("CS\r", m_sPrompt); 00629 m_Port.Write((char *)keepPinging.sSend.c_str(),keepPinging.sSend.size()); 00630 00631 return; 00632 } 00633 00638 bool CDVLInstrument::SendDVLUpdatedCommands(string &sCmdUpdateStatus, string sNewCmdString) 00639 { 00640 string sMOOSChompResult = MOOSChomp(sNewCmdString, ","); 00641 double dfWhen; 00642 string sWhatReply; 00643 bool bSuccess = true; 00644 00645 while(!sMOOSChompResult.empty()) 00646 { 00647 //take action here and talk to the DVL 00648 //have to add a <CR> to the command 00649 string sDVLUpdateFormattedCmd = sMOOSChompResult + "\r"; 00650 00651 //we are writing and then reading too quickly for this device 00652 //MOOSPause(500); 00653 00654 m_Port.Write((char *)sDVLUpdateFormattedCmd.c_str(),sDVLUpdateFormattedCmd.size()); 00655 00656 while(!m_Port.GetLatest(sWhatReply,dfWhen)) 00657 { 00658 MOOSPause(10); 00659 } 00660 00661 if(GoodReply(sWhatReply)) 00662 { 00663 MOOSTrace("Update DVL: Succesful Update - %s\n", sDVLUpdateFormattedCmd.c_str()); 00664 00665 //keep track of the success 00666 sCmdUpdateStatus += sMOOSChompResult + ": OK; "; 00667 } 00668 else 00669 { 00670 MOOSTrace("Update DVL: Failure - %s\n", sDVLUpdateFormattedCmd.c_str()); 00671 00672 //keep track of the failure 00673 sCmdUpdateStatus += sMOOSChompResult + ": FAIL; "; 00674 00675 if(bSuccess) 00676 bSuccess = !bSuccess; 00677 } 00678 00679 sMOOSChompResult = MOOSChomp(sNewCmdString, ","); 00680 00681 } 00682 00683 return bSuccess; 00684 } 00685 00693 bool CDVLInstrument::NewCommandsAreSkewed(CMOOSMsg & Msg, double dfTimeNow, string sNewCmdString) 00694 { 00695 double dfSkewTime; 00696 string sCmdUpdateStatus; 00697 00698 if((sNewCmdString.size() == 0) || 00699 Msg.IsSkewed(dfTimeNow, &dfSkewTime)) 00700 { 00701 if((sNewCmdString.size() == 0)) 00702 { 00703 sCmdUpdateStatus = "Update DVL: Cmd SIZE = 0 - Aborted Update\n"; 00704 MOOSTrace("%s", sCmdUpdateStatus.c_str()); 00705 SetMOOSVar("UPDATE_CMD",sCmdUpdateStatus,MOOSTime()); 00706 } 00707 else 00708 { 00709 sCmdUpdateStatus = "Update DVL: Cmd [" + sNewCmdString + "] SKEWED - Aborted Update\n"; 00710 MOOSTrace("%s\n SkewTime: %f\n", sCmdUpdateStatus.c_str(), dfSkewTime); 00711 SetMOOSVar("UPDATE_CMD",sCmdUpdateStatus,MOOSTime()); 00712 } 00713 00714 return true; 00715 00716 } 00717 else if(dfSkewTime > FRESH_UPDATE) 00718 { 00719 sCmdUpdateStatus = "Update DVL: Cmd [" + sNewCmdString + "] STALE - Aborted Update\n"; 00720 MOOSTrace("%s\n SkewTime: %f\n", sCmdUpdateStatus.c_str(), dfSkewTime); 00721 SetMOOSVar("UPDATE_CMD",sCmdUpdateStatus,MOOSTime()); 00722 00723 return true; 00724 } 00725 else 00726 { 00727 MOOSTrace("Update DVL: Time Stamp - %f\n", Msg.m_dfTime); 00728 MOOSTrace("Update DVL: MOOS Time Stamp - %f\n", dfTimeNow); 00729 00730 return false; 00731 } 00732 00733 } 00734 00738 bool CDVLInstrument::GetDVLAttention() 00739 { 00740 string sWhatReply; 00741 double dfWhen; 00742 int nTries = 0; 00743 00744 //change the Termination Character we are looking for 00745 //and stop the DVL from talking 00746 m_Port.SetTermCharacter(m_sPrompt.c_str()[0]); 00747 m_Port.Break(); 00748 00749 //check reply... 00750 while(nTries++ < MAXTRIES) 00751 { 00752 //wait a second to let it stop streaming 00753 MOOSPause(1000); 00754 00755 while(!m_Port.GetLatest(sWhatReply,dfWhen)) 00756 { 00757 MOOSPause(10); 00758 } 00759 00760 if(GoodReply(sWhatReply)) 00761 { 00762 return true; 00763 } 00764 else 00765 { 00766 MOOSTrace("Update DVL: No Prompt Found - Retrying Break\n"); 00767 m_Port.Break(); 00768 } 00769 } 00770 00771 MOOSTrace("Update DVL: Check Cable Connection - Aborted Retry\n"); 00772 00773 return false; 00774 00775 }