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 // GoToDepth.cpp: implementation of the CGoToDepth 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 00045 #include "GoToDepth.h" 00046 #define DEFAULT_GO_TO_DEPTH_TOLERANCE 3.14 00047 00049 // Construction/Destruction 00051 00052 CGoToDepth::CGoToDepth() 00053 { 00054 m_bSetRudder = false; 00055 m_dfRudder = 0; 00056 m_dfTolerance = DEFAULT_GO_TO_DEPTH_TOLERANCE; 00057 m_bSetThrust = false; 00058 m_dfThrust = 0; 00059 } 00060 00061 CGoToDepth::~CGoToDepth() 00062 { 00063 00064 } 00065 00066 bool CGoToDepth::SetParam(string sParam, string sVal) 00067 { 00068 MOOSToUpper(sParam); 00069 MOOSToUpper(sVal); 00070 00071 if(!CConstantDepthTask::SetParam(sParam,sVal)) 00072 { 00073 //this is for us... 00074 if(MOOSStrCmp(sParam,"RUDDER")) 00075 { 00076 m_bSetRudder = true; 00077 m_dfRudder=atof(sVal.c_str()); 00078 } 00079 else if(MOOSStrCmp(sParam,"TOLERANCE")) 00080 { 00081 m_dfTolerance=atof(sVal.c_str()); 00082 } 00083 else if(MOOSStrCmp(sParam,"THRUST")) 00084 { 00085 m_dfThrust=atof(sVal.c_str()); 00086 m_bSetThrust = true; 00087 } 00088 00089 } 00090 return true; 00091 } 00092 00093 00094 bool CGoToDepth::Run(CPathAction &DesiredAction) 00095 { 00096 00097 if(CConstantDepthTask::Run(DesiredAction)) 00098 { 00099 if(fabs(m_DepthDOF.GetError())<m_dfTolerance) 00100 { 00101 Stop("Target Depth Reached"); 00102 } 00103 else 00104 { 00105 if(m_bSetRudder) 00106 { 00107 DesiredAction.Set( ACTUATOR_RUDDER, 00108 m_dfRudder, 00109 m_nPriority, 00110 m_sName.c_str()); 00111 } 00112 if(m_bSetThrust) 00113 { 00114 DesiredAction.Set( ACTUATOR_THRUST, 00115 m_dfThrust, 00116 m_nPriority, 00117 m_sName.c_str()); 00118 } 00119 } 00120 return true; 00121 } 00122 return false; 00123 } 00124 00125