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 // SeabedTrack.cpp: implementation of the CSeabedTrack class. 00032 // 00034 00035 #ifdef _WIN32 00036 #pragma warning(disable : 4786) 00037 #endif 00038 00039 00040 00041 00042 #include <math.h> 00043 #include <iostream> 00044 using namespace std; 00045 00046 #include "MOOSTaskDefaults.h" 00047 #include "SeabedTrack.h" 00048 00050 // Construction/Destruction 00052 00053 00054 CSeabedTrack::CSeabedTrack() 00055 { 00056 00057 00058 m_nPriority = 3; 00059 00060 m_AltitudeDOF.SetDesired(6.0); 00061 00062 m_bInitialised = false; 00063 00064 } 00065 00066 CSeabedTrack::~CSeabedTrack() 00067 { 00068 00069 } 00070 00071 //returns false if we haven't received data in a while..bad news! 00072 bool CSeabedTrack::RegularMailDelivery(double dfTimeNow) 00073 { 00074 00075 return !m_AltitudeDOF.IsStale(dfTimeNow,GetStartTime()); 00076 00077 } 00078 00079 00080 bool CSeabedTrack::Run(CPathAction &DesiredAction) 00081 { 00082 00083 if(!m_bInitialised) 00084 { 00085 Initialise(); 00086 } 00087 00088 if(m_AltitudeDOF.IsValid()) 00089 { 00090 double dfError = m_AltitudeDOF.GetError(); 00091 double dfCmd= 0; 00092 00093 //this is for logging purposes only 00094 m_ZPID.SetGoal(m_AltitudeDOF.GetDesired()); 00095 00096 if(m_ZPID.Run( dfError, 00097 m_AltitudeDOF.GetErrorTime(), 00098 dfCmd, 00099 m_PitchDOF.GetCurrent(), 00100 m_PitchDOF.GetErrorTime())) 00101 { 00102 //OK we need to change something 00103 DesiredAction.Set( ACTUATOR_ELEVATOR, 00104 dfCmd, 00105 m_nPriority, 00106 "Seabed Track"); 00107 00108 } 00109 } 00110 return true; 00111 } 00112 00113 bool CSeabedTrack::OnNewMail(MOOSMSG_LIST &NewMail) 00114 { 00115 CMOOSMsg Msg; 00116 00117 if(PeekMail(NewMail,"NAV_ALTITUDE",Msg)) 00118 { 00119 if(!Msg.IsSkewed(GetTimeNow())) 00120 { 00121 m_AltitudeDOF.SetCurrent(Msg.m_dfVal, Msg.m_dfTime); 00122 } 00123 } 00124 00125 if(PeekMail(NewMail,"NAV_PITCH",Msg)) 00126 { 00127 if(!Msg.IsSkewed(GetTimeNow())) 00128 { 00129 m_PitchDOF.SetCurrent(Msg.m_dfVal,Msg.m_dfTime); 00130 } 00131 } 00132 00133 //always call base class version 00134 CMOOSBehaviour::OnNewMail(NewMail); 00135 00136 return true; 00137 } 00138 00139 bool CSeabedTrack::GetNotifications(MOOSMSG_LIST & List) 00140 { 00141 if(m_bActive) 00142 { 00143 CMOOSMsg Msg(MOOS_NOTIFY, 00144 "DESIRED_PITCH", 00145 m_ZPID.GetPitchDesired()); 00146 00147 List.push_back(Msg); 00148 } 00149 00150 return CMOOSBehaviour::GetNotifications(List); 00151 } 00152 00153 00154 00155 bool CSeabedTrack::GetRegistrations(STRING_LIST &List) 00156 { 00157 00158 List.push_front("NAV_ALTITUDE"); 00159 List.push_front("NAV_PITCH"); 00160 00161 //always call base class version 00162 CMOOSBehaviour::GetRegistrations(List); 00163 00164 return true; 00165 } 00166 00167 00168 bool CSeabedTrack::SetParam(string sParam, string sVal) 00169 { 00170 MOOSToUpper(sParam); 00171 MOOSToUpper(sVal); 00172 00173 00174 if(!CMOOSBehaviour::SetParam(sParam,sVal)) 00175 { 00176 //this is for us... 00177 if(sParam=="ALTITUDE") 00178 { 00179 double dfDesiredAltitude=atof(sVal.c_str()); 00180 m_AltitudeDOF.SetDesired(dfDesiredAltitude); 00181 } 00182 else 00183 { 00184 //hmmm - it wasn't for us at all: base class didn't understand either 00185 MOOSTrace("Param \"%s\" not understood!\n",sParam.c_str()); 00186 return false; 00187 } 00188 } 00189 00190 return true; 00191 00192 } 00193 00194 bool CSeabedTrack::Initialise() 00195 { 00196 //we control altitude NOT depth 00197 m_ZPID.SetAsDepthController(false); 00198 00199 00200 m_bInitialised = true; 00201 00202 return true; 00203 }