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