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