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 // SteerThenDriveXYPatternTask.cpp: implementation of the CSteerThenDriveXYPatternTask class. 00032 // 00034 #ifdef _WIN32 00035 #pragma warning(disable : 4786) 00036 #endif 00037 00038 #include "SteerThenDriveXYPatternTask.h" 00039 #include <math.h> 00041 // Construction/Destruction 00043 00044 #define DEFAULT_OUTER_YAW_TOLERANCE MOOSDeg2Rad(40) 00045 #define DEFAULT_INNER_YAW_TOLERANCE MOOSDeg2Rad(10) 00046 00047 CSteerThenDriveXYPatternTask::CSteerThenDriveXYPatternTask() 00048 { 00049 m_dfOuterYawTolerance= DEFAULT_OUTER_YAW_TOLERANCE; 00050 m_dfInnerYawTolerance = DEFAULT_INNER_YAW_TOLERANCE; 00051 m_dfLastThrust = 0; 00052 00053 //if alpha = 0 then no damping 00054 m_dfAlpha = 0.1; 00055 } 00056 00057 CSteerThenDriveXYPatternTask::~CSteerThenDriveXYPatternTask() 00058 { 00059 00060 } 00061 00062 bool CSteerThenDriveXYPatternTask::GetRegistrations(STRING_LIST &List) 00063 { 00064 List.push_front("XYPATTERN_LOCATIONS"); 00065 00066 //always call base class version 00067 CXYPatternTask::GetRegistrations(List); 00068 00069 return true; 00070 } 00071 00072 00073 bool CSteerThenDriveXYPatternTask::OnNewMail(MOOSMSG_LIST & NewMail) 00074 { 00075 CMOOSMsg Msg; 00076 if(PeekMail(NewMail,"XYPATTERN_LOCATIONS",Msg)) 00077 { 00078 DebugNotify("CSteerThenDriveXYPatternTask::reloading locations\n"); 00079 //start afresh... 00080 m_Positions.clear(); 00081 m_XYPoints.clear(); 00082 m_nTotalPositions = 0; 00083 m_nRepCounter = 0; 00084 m_bInitialised = false; 00085 m_nCurrentPosition = 0; 00086 00087 string sData = Msg.m_sVal; 00088 while(!sData.empty()) 00089 { 00090 string sChunk = MOOSChomp(sData,"|"); 00091 string sTok = MOOSChomp(sChunk,"="); 00092 string sVal = sChunk; 00093 SetParam(sTok,sVal); 00094 } 00095 00096 } 00097 00098 //now call base class default; 00099 return CXYPatternTask::OnNewMail(NewMail); 00100 00101 } 00102 00103 bool CSteerThenDriveXYPatternTask::SetParam(string sParam, string sVal) 00104 { 00105 MOOSToUpper(sParam); 00106 MOOSToUpper(sVal); 00107 00108 if(MOOSStrCmp(sParam,"OUTERYAWLIMIT")) 00109 { 00110 m_dfOuterYawTolerance=MOOSDeg2Rad(atof(sVal.c_str())); 00111 } 00112 else if(MOOSStrCmp(sParam,"INNERYAWLIMIT")) 00113 { 00114 m_dfInnerYawTolerance=MOOSDeg2Rad(atof(sVal.c_str())); 00115 } 00116 else if(MOOSStrCmp(sParam,"THRUSTDAMPING")) 00117 { 00118 m_dfAlpha=atof(sVal.c_str()); 00119 } 00120 else 00121 { 00122 if(!CXYPatternTask::SetParam(sParam,sVal)) 00123 { 00124 //hmmm - it wasn't for us at all: base class didn't understand either 00125 MOOSTrace("Param \"%s\" not understood!\n",sParam.c_str()); 00126 return false; 00127 } 00128 } 00129 00130 return true; 00131 } 00132 bool CSteerThenDriveXYPatternTask::SetControl(CPathAction &DesiredAction,double dfRudder,double dfThrust) 00133 { 00134 //we always set rudder 00135 DesiredAction.Set( ACTUATOR_RUDDER, 00136 dfRudder, 00137 m_nPriority, 00138 GetName().c_str()); 00139 00140 //but not always thrust 00141 00142 double dfFE = fabs(m_YawDOF.GetError()); 00143 if(dfFE>m_dfOuterYawTolerance) 00144 { 00145 //too much error! stop we might hit somethging steer first 00146 SetThrust(DesiredAction,0); 00147 } 00148 else if(dfFE<=m_dfInnerYawTolerance) 00149 { 00150 SetThrust(DesiredAction,dfThrust); 00151 } 00152 else 00153 { 00154 00155 if(m_dfInnerYawTolerance>m_dfOuterYawTolerance) 00156 { 00157 MOOSTrace("bad tolerance values - resetting to defaults\n"); 00158 m_dfOuterYawTolerance= DEFAULT_OUTER_YAW_TOLERANCE; 00159 m_dfInnerYawTolerance = DEFAULT_INNER_YAW_TOLERANCE; 00160 } 00161 //some middle ground here... 00162 double dfNewThrust = dfThrust+(dfFE-m_dfInnerYawTolerance)*(-dfThrust)/(m_dfOuterYawTolerance-m_dfInnerYawTolerance); 00163 00164 SetThrust(DesiredAction,dfNewThrust); 00165 } 00166 00167 00168 return true; 00169 00170 } 00171 00172 bool CSteerThenDriveXYPatternTask::SetThrust(CPathAction &DesiredAction, double dfThrust) 00173 { 00174 double dfOut = (1.0-m_dfAlpha)*dfThrust+m_dfAlpha*m_dfLastThrust; 00175 00176 if(dfOut<1) 00177 { 00178 dfOut = 0; 00179 } 00180 00181 DesiredAction.Set(ACTUATOR_THRUST,dfOut,m_nPriority, 00182 GetName().c_str()); 00183 00184 m_dfLastThrust = dfOut; 00185 00186 return true; 00187 00188 } 00189 00190 bool CSteerThenDriveXYPatternTask::OnComplete() 00191 { 00192 //this special task never quite bevause of its spatial 00193 //location only because of a timeout 00194 00195 //overloading it stops the base class version running 00196 return true; 00197 }