MOOS 0.2375
/home/toby/moos-ivp/MOOS-2375-Oct0611/NavigationAndControl/MOOSTaskLib/LimitDepth.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 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 #ifdef _WIN32
00032     #pragma warning(disable : 4786)
00033 #endif
00034 
00035 
00036 // LimitDepth.cpp: implementation of the CLimitDepth class.
00037 //
00039 
00040 #include "LimitDepth.h"
00041 #include <iostream>
00042 
00044 // Construction/Destruction
00046 #define ON_DEPTH_EXCEEDED_ELEVATOR MOOSDeg2Rad(-30.0)
00047 #define DEFAULT_DEPTH_LIMIT 50.0
00048 CLimitDepth::CLimitDepth()
00049 {
00050     m_DepthDOF.SetDesired(DEFAULT_DEPTH_LIMIT);
00051     m_nPriority = 0;
00052 
00053     m_bDoneVerbalNotify = false;
00054 
00055 }
00056 
00057 CLimitDepth::~CLimitDepth()
00058 {
00059 
00060 }
00061 //returns false if we haven't received data in a while..bad news!
00062 bool CLimitDepth::RegularMailDelivery(double dfTimeNow)
00063 {
00064  
00065     return !m_DepthDOF.IsStale(dfTimeNow,GetStartTime());
00066     
00067 }
00068 
00069 
00070 bool CLimitDepth::Run(CPathAction &DesiredAction)
00071 {
00072     if(m_DepthDOF.IsValid())
00073     {
00074         if(m_DepthDOF.GetError()<0)
00075         {
00076 
00077             DesiredAction.Set(  ACTUATOR_ELEVATOR,
00078                                 ON_DEPTH_EXCEEDED_ELEVATOR,
00079                                 m_nPriority,
00080                                 "Depth Limit");
00081 
00082             //we may have some flags to set...
00083            
00084             OnEvent("Depth exceeded",!m_bDoneVerbalNotify);
00085             m_bDoneVerbalNotify = true;
00086             
00087         }
00088         else
00089         {
00090             m_bDoneVerbalNotify = false;
00091         }
00092     }
00093     return true;
00094 }
00095 
00096 bool CLimitDepth::OnNewMail(MOOSMSG_LIST &NewMail)
00097 {
00098 
00099     CMOOSMsg Msg;
00100     if(PeekMail(NewMail,"NAV_DEPTH",Msg))
00101     {
00102          if(!Msg.IsSkewed(GetTimeNow()))
00103          {
00104             m_DepthDOF.SetCurrent(Msg.m_dfVal,Msg.m_dfTime);
00105          }
00106     }
00107 
00108 
00109     //always call base class version
00110     CMOOSBehaviour::OnNewMail(NewMail);
00111 
00112 
00113     return true;
00114 }
00115 
00116 bool CLimitDepth::GetRegistrations(STRING_LIST &List)
00117 {
00118     List.push_front("NAV_DEPTH");
00119 
00120 
00121     //always call base class version
00122     CMOOSBehaviour::GetRegistrations(List);
00123 
00124     return true;
00125 }
00126 
00127 bool CLimitDepth::SetParam(string sParam, string sVal)
00128 {
00129 
00130     MOOSToUpper(sParam);
00131     MOOSToUpper(sVal);
00132 
00133 
00134     if(!CMOOSBehaviour::SetParam(sParam,sVal))
00135     {
00136         //this is for us...
00137         if(sParam=="MAXIMUMDEPTH")
00138         {
00139             double dfMaxDepth=atof(sVal.c_str());
00140 
00141             m_DepthDOF.SetDesired(dfMaxDepth);
00142 
00143         }
00144         else
00145         {
00146             //hmmm - it wasn't for us at all: base class didn't understand either
00147             MOOSTrace("Param \"%s\" not understood!\n",sParam.c_str());
00148             return false;
00149         }
00150     }
00151 
00152     return true;
00153 
00154 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines