MOOS 0.2375
/home/toby/moos-ivp/MOOS-2375-Oct0611/Instruments/Ocean/iDepth/MOOSParaSciDepthSensor.cpp
Go to the documentation of this file.
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 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 // MOOSParaSciDepthSensor.cpp: implementation of the CMOOSParaSciDepthSensor class.
00032 //
00034 #include <MOOSLIB/MOOSLib.h>
00035 #include "MOOSParaSciDepthSensor.h"
00036 #include <cstring>
00037 
00039 // Construction/Destruction
00041 
00042 using namespace std;
00043 
00044 CMOOSParaSciDepthSensor::CMOOSParaSciDepthSensor()
00045 {
00046     m_dfResolution = 0.03;
00047 
00048 
00049 }
00050 
00051 CMOOSParaSciDepthSensor::~CMOOSParaSciDepthSensor()
00052 {
00053 
00054 }
00055 
00056 
00057 bool CMOOSParaSciDepthSensor::Initialise()
00058 {
00059     std::string sReply;
00060 
00061     //set units to be m of water
00062     string sUnits = "*0100EW*0100UN=8\r";
00063     if(m_pPort->Write((char*)sUnits.c_str(),sUnits.size()))
00064     {
00065         m_pPort->GetTelegram(sReply,1.0);
00066 
00067         MOOSTrace("set units cmd returns %s\n",sReply.c_str());
00068     }
00069 
00070     //set resolution to be as set in config file
00071 
00072     int nRes = (int)(7000.0/(150*28*m_dfResolution));
00073 
00074     char sTmp[100];
00075 
00076     sprintf(sTmp,"*0100EW*0100PR=%d\r",nRes);
00077 
00078     string sRes = sTmp;
00079     if(m_pPort->Write((char*)sRes.c_str(),sRes.size()))
00080     {
00081         m_pPort->GetTelegram(sReply,1.0);
00082         MOOSTrace("set units cmd returns %s\n",sReply.c_str());
00083     }
00084 
00085     MOOSPause(200);
00086 
00087     //we zero the depth sensor at start up...
00088     Zero();
00089 
00090     return true;
00091 }
00092 
00093 
00094 bool CMOOSParaSciDepthSensor::GetDepth()
00095 {
00096 
00097     const char *     sGetDepthString =  "*0100P3\r";
00098 
00099     if( m_pPort->Write(sGetDepthString,
00100              strlen(sGetDepthString)))
00101     {
00102         //last thing we did was write so now rea
00103         string sReply;
00104         if(m_pPort->GetTelegram(sReply,3.0))
00105         {
00106             //sReply now has ASCII depth
00107             return ParseDepthString(sReply);
00108         }
00109         else
00110         {
00111             MOOSTrace("Depth Sensor: Failed Read on serial port\n");
00112             return false;
00113         }
00114     }
00115 
00116 
00117     return true;
00118 
00119 }
00120 
00121 bool CMOOSParaSciDepthSensor::SetResolution(double dfResolution)
00122 {
00123     m_dfResolution = dfResolution;
00124     return true;
00125 }
00126 
00127 bool CMOOSParaSciDepthSensor::Zero()
00128 {
00129     //zero sensor
00130     string sZero = "*0100EW*0100ZS=1\r";
00131 
00132     if(m_pPort->Write((char*)sZero.c_str(),sZero.size()))
00133     {
00134         string sReply;
00135         m_pPort->GetTelegram(sReply,1.0);
00136         MOOSTrace("zeroing cmd returns %s\n",sReply.c_str());
00137 
00138         //and read once to do the zeroing
00139         GetDepth();
00140 
00141     }
00142 
00143     return true;
00144 
00145 }
00146 
00147 
00148 bool CMOOSParaSciDepthSensor::ParseDepthString(string Str)
00149 {
00150     MOOSChomp(Str,"*0001");
00151 
00152     if(!Str.empty())
00153     {
00154         //we keep a local copy of depth just for ease of debugging
00155         m_dfDepth = atof(Str.c_str());
00156 
00157         return true;
00158 
00159     }
00160     else
00161     {
00162         return false;
00163     }
00164 
00165 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines