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 // MOOSTaskReader.cpp: implementation of the CMOOSTaskReader class. 00032 // 00034 #include "MOOSBehaviour.h" 00035 #include "MOOSTaskDefaults.h" 00036 #include "LimitDepth.h" 00037 #include "SeabedTrack.h" 00038 #include "LimitAltitude.h" 00039 #include "GoToWayPoint.h" 00040 #include "EndMission.h" 00041 #include "TimerTask.h" 00042 #include "HoldingPatternTask.h" 00043 #include "ConstantDepthTask.h" 00044 #include "ConstantHeadingTask.h" 00045 #include "GoToDepth.h" 00046 #include "ZPatternTask.h" 00047 #include "XYPatternTask.h" 00048 #include "SteerThenDriveXYPatternTask.h" 00049 #include "OrbitTask.h" 00050 #include "OverallTimeOut.h" 00051 #include "SurveyTask.h" 00052 #include "ThirdPartyTask.h" 00053 #include "TrackLineTask.h" 00054 #include "LimitBox.h" 00055 #include "PilotTask.h" 00056 #include "VariableHeadingTask.h" 00057 #include "AGVHeadingSpeedTask.h" 00058 #include "VehicleFrameWayPointTask.h" 00059 00060 #include <iostream> 00061 #include <fstream> 00062 #include <sstream> 00063 using namespace std; 00064 #include "MOOSTaskReader.h" 00065 00067 // Construction/Destruction 00069 00070 CMOOSTaskReader::CMOOSTaskReader() 00071 { 00072 00073 } 00074 00075 CMOOSTaskReader::~CMOOSTaskReader() 00076 { 00077 00078 } 00079 00080 bool CMOOSTaskReader::Run(const char *sFile, 00081 CProcessConfigReader* pMissionFileReader, 00082 CMOOSBehaviour::CControllerGains Gains, 00083 TASK_LIST &Tasks) 00084 { 00085 00086 00087 if(SetFile(sFile)) 00088 { 00089 Reset(); 00090 CMOOSBehaviour * pNewTask = NULL; 00091 00092 if(!GetFile()->is_open()) 00093 { 00094 00095 MOOSTrace("CMOOSTaskReader::failed to open task file %s\n",sFile); 00096 return false; 00097 } 00098 00099 while(!GetFile()->eof()) 00100 { 00101 string sLine = GetNextValidLine(); 00102 00103 MOOSToUpper(sLine); 00104 00105 string sTok,sVal; 00106 if(GetTokenValPair(sLine,sTok,sVal)) 00107 { 00108 if(sTok=="TASK") 00109 { 00110 pNewTask = MakeNewTask(sVal); 00111 00112 if(pNewTask!=NULL) 00113 { 00114 //maybe it needs the mission file to get parameters etc 00115 pNewTask->SetMissionFileReader(pMissionFileReader); 00116 00117 if(StuffTask(pNewTask)) 00118 { 00119 //we have already read the gins for it (stops possibly dynaically 00120 //made task having to do file parsing! 00121 pNewTask->SetGains(Gains); 00122 00123 Tasks.push_front(pNewTask); 00124 } 00125 else 00126 { 00127 MOOSTrace("task config failed\n"); 00128 delete pNewTask; 00129 return false; 00130 } 00131 } 00132 else 00133 { 00134 return false; 00135 } 00136 } 00137 } 00138 } 00139 } 00140 else 00141 { 00142 MOOSTrace("Cannot open file containing task specification!!!\n"); 00143 return false; 00144 } 00145 00146 MOOSTrace("TaskReader makes %d tasks\n",Tasks.size()); 00147 00148 return true; 00149 } 00150 00151 00152 00153 bool CMOOSTaskReader::StuffTask(CMOOSBehaviour *pTask) 00154 { 00155 00156 string sBracket = GetNextValidLine(); 00157 00158 if(sBracket!="{") 00159 { 00160 MOOSTrace("CMOOSTaskReader::StuffTask ->no opening bracket\n"); 00161 delete pTask; 00162 return false; 00163 } 00164 00165 string sLine; 00166 while((sLine=GetNextValidLine())!="}") 00167 { 00168 string sTok,sVal; 00169 00170 if(GetTokenValPair(sLine, sTok, sVal)) 00171 { 00172 if(!pTask->SetParam(sTok,sVal)) 00173 { 00174 MOOSTrace("failed parse...line = %s",sLine.c_str()); 00175 return false; 00176 } 00177 } 00178 else 00179 { 00180 MOOSTrace("failed parse...line = %s",sLine.c_str()); 00181 return false; 00182 } 00183 } 00184 00185 00186 return true; 00187 } 00188 00189 CMOOSBehaviour * CMOOSTaskReader::MakeNewTask(string sTaskType) 00190 { 00191 //add new task types here.. 00192 CMOOSBehaviour * pNewTask = NULL; 00193 00194 MOOSToUpper(sTaskType); 00195 00196 if(sTaskType =="GOTOWAYPOINT") 00197 { 00198 pNewTask = new CGoToWayPoint; 00199 } 00200 else if(sTaskType =="TRACKLINE") 00201 { 00202 pNewTask = new CTrackLineTask; 00203 } 00204 else if(sTaskType =="OVERALLTIMEOUT") 00205 { 00206 pNewTask = new COverallTimeOut; 00207 } 00208 else if(sTaskType =="ORBIT") 00209 { 00210 pNewTask = new COrbitTask; 00211 } 00212 else if(sTaskType =="XYPATTERN") 00213 { 00214 pNewTask = new CXYPatternTask; 00215 } 00216 else if(sTaskType =="STEERTHENDRIVEXYPATTERN") 00217 { 00218 pNewTask = new CSteerThenDriveXYPatternTask; 00219 } 00220 else if(sTaskType =="THIRDPARTY") 00221 { 00222 pNewTask = new CThirdPartyTask; 00223 } 00224 else if(sTaskType =="GOTODEPTH") 00225 { 00226 pNewTask = new CGoToDepth; 00227 } 00228 else if(sTaskType == "LIMITDEPTH") 00229 { 00230 pNewTask = new CLimitDepth; 00231 } 00232 else if(sTaskType == "SEABEDTRACK") 00233 { 00234 pNewTask = new CSeabedTrack; 00235 } 00236 else if(sTaskType == "LIMITALTITUDE") 00237 { 00238 pNewTask = new CLimitAltitude; 00239 } 00240 else if(sTaskType == "ENDMISSION") 00241 { 00242 pNewTask = new CEndMission; 00243 } 00244 else if(sTaskType == "TIMER") 00245 { 00246 pNewTask = new CTimerTask; 00247 } 00248 else if(sTaskType == "HOLDINGPATTERN") 00249 { 00250 pNewTask = new CHoldingPatternTask; 00251 } 00252 else if(sTaskType == "CONSTANTDEPTH") 00253 { 00254 pNewTask = new CConstantDepthTask; 00255 } 00256 else if(sTaskType == "CONSTANTHEADING") 00257 { 00258 pNewTask = new CConstantHeadingTask; 00259 } 00260 else if(sTaskType == "DIVE") 00261 { 00262 MOOSTrace("Dive task is depreciated, use GoToDepth\n"); 00263 return NULL; 00264 } 00265 else if(sTaskType == "ZPATTERN") 00266 { 00267 pNewTask = new CZPatternTask; 00268 } 00269 else if(sTaskType == "SURVEY") 00270 { 00271 pNewTask = new CSurveyTask; 00272 } 00273 else if(sTaskType == "LIMITBOX") 00274 { 00275 pNewTask = new CLimitBox; 00276 } 00277 else if(sTaskType == "PILOT") 00278 { 00279 pNewTask = new CPilotTask; 00280 } 00281 else if(sTaskType == "VARIABLEHEADING") 00282 { 00283 pNewTask = new CVariableHeadingTask; 00284 } 00285 else if(MOOSStrCmp(sTaskType,"AGVHeadingSpeed")) 00286 { 00287 pNewTask = new CAGVHeadingSpeedTask; 00288 } 00289 else if(MOOSStrCmp(sTaskType,"VehicleFrameWayPoint")) 00290 { 00291 pNewTask = new CVehicleFrameWayPointTask; 00292 } 00293 00294 else 00295 { 00296 MOOSTrace("Task Type \"%s\" is unknown\n",sTaskType.c_str()); 00297 } 00298 00299 return pNewTask; 00300 }