00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include "Beowulf/Beowulf.H"
00041 #include "Component/ModelManager.H"
00042 #include "Media/FrameSeries.H"
00043 #include "Transport/FrameIstream.H"
00044 #include "Raster/Raster.H"
00045 #include "Media/MediaOpts.H"
00046 #include "GUI/XWinManaged.H"
00047
00048 #include "Video/VideoFormat.H"
00049 #include "Devices/FrameGrabberConfigurator.H"
00050 #include "Devices/FrameGrabberFactory.H"
00051
00052 #include "Devices/DeviceOpts.H"
00053 #include "Image/CutPaste.H"
00054
00055 #include "Globals.H"
00056 #include "AgentManagerB.H"
00057 #include "Mission.H"
00058 #include "SubController.H"
00059
00060 #include <signal.h>
00061
00062 #define SIM_MODE false
00063
00064 volatile bool goforever = false;
00065 uint fNum = 0;
00066
00067
00068 void checkInMessages
00069 ( nub::soft_ref<Beowulf> beo,
00070 nub::ref<AgentManagerB> agentManager,
00071 rutz::shared_ptr<XWinManaged> cwin);
00072
00073
00074 void checkOutMessages
00075 ( nub::ref<AgentManagerB> agentManager,
00076 nub::soft_ref<Beowulf> beo);
00077
00078
00079 void packageSensorResult
00080 ( SensorResult sensorResult,
00081 TCPmessage &smsg);
00082
00083
00084
00085
00086 void terminate(int s)
00087 {
00088 LERROR("*** INTERRUPT ***");
00089 goforever = false;
00090 exit(1);
00091 }
00092
00093
00094
00095 int main( int argc, const char* argv[] )
00096 {
00097 MYLOGVERB = LOG_INFO;
00098
00099
00100 ModelManager manager("SeaBee 2008 competition slave");
00101
00102
00103 nub::soft_ref<Beowulf>
00104 beo(new Beowulf(manager, "Beowulf Slave", "BeowulfSlave", false));
00105 manager.addSubComponent(beo);
00106
00107 #if SIM_MODE == false
00108
00109
00110
00111 nub::soft_ref<FrameIstream> gbB(makeV4L2grabber(manager));
00112
00113 gbB->setModelParamVal("FrameGrabberDevice",std::string("/dev/video0"));
00114 gbB->setModelParamVal("FrameGrabberChannel",0);
00115
00116
00117
00118
00119 manager.addSubComponent(gbB);
00120 #endif
00121
00122
00123
00124 nub::ref<AgentManagerB> agentManager(new AgentManagerB(manager));
00125 manager.addSubComponent(agentManager);
00126
00127 manager.exportOptions(MC_RECURSE);
00128
00129
00130 if (manager.parseCommandLine(argc, argv, "", 0, 0) == false) return(1);
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140 TCPmessage rmsg;
00141 TCPmessage smsg;
00142 int32 rframe = 0, raction = 0, rnode = -1;
00143
00144
00145 signal(SIGHUP, terminate); signal(SIGINT, terminate);
00146 signal(SIGQUIT, terminate); signal(SIGTERM, terminate);
00147 signal(SIGALRM, terminate);
00148
00149
00150 manager.start();
00151
00152 while(!beo->receive(rnode, rmsg, rframe, raction, 5));
00153 int initval = uint(rmsg.getElementInt32());
00154 LINFO("Recieved INIT(%d) from COM_A", initval);
00155
00156
00157 uint w, h;
00158
00159 #if SIM_MODE == false
00160
00161
00162 w = gbB->getWidth();
00163 h = gbB->getHeight();
00164 #else
00165 w = 320;
00166 h = 240;
00167 #endif
00168
00169
00170 rutz::shared_ptr<XWinManaged> cwin
00171 (new XWinManaged(Dims(w,h), 0, 0, "SeaBeeMainB Window"));
00172
00173
00174
00175
00176
00177 agentManager->setWindow(cwin);
00178
00179
00180
00181 smsg.reset(rframe, INIT_DONE);
00182 beo->send(rnode, smsg);
00183
00184 #if SIM_MODE == false
00185
00186
00187
00188
00189 gbB->startStream();
00190 #endif
00191
00192 goforever = true;
00193
00194 Image<PixRGB<byte> > img(w,h,ZEROS);
00195
00196
00197
00198
00199 while(goforever)
00200 {
00201
00202 #if SIM_MODE == false
00203
00204
00205
00206 img = gbB->readRGB();
00207 agentManager->setCurrentImageF(img, fNum);
00208 agentManager->setCurrentImageB(img, fNum);
00209
00210
00211 #else
00212
00213
00214 #endif
00215
00216 fNum++;
00217
00218
00219 checkInMessages(beo, agentManager, cwin);
00220
00221
00222 checkOutMessages(agentManager, beo);
00223 }
00224
00225
00226 manager.stop();
00227 return 0;
00228 }
00229
00230
00231 void checkInMessages
00232 ( nub::soft_ref<Beowulf> beo,
00233 nub::ref<AgentManagerB> agentManager,
00234 rutz::shared_ptr<XWinManaged> cwin
00235 )
00236 {
00237 int32 rframe = 0, raction = 0, rnode = -1;
00238 TCPmessage rmsg;
00239
00240
00241 if(beo->receive(rnode, rmsg, rframe, raction, 5))
00242 {
00243
00244
00245 Image<PixRGB<byte> > img;
00246
00247 switch(raction)
00248 {
00249 case ABORT:
00250 {
00251 goforever = false; LINFO("Stop SeaBee COM-B");
00252 break;
00253 }
00254 case UPDATE_MISSION:
00255 {
00256
00257 Mission theMission;
00258 theMission.missionName = Mission::MissionName(rmsg.getElementInt32());
00259 theMission.timeForMission = int(rmsg.getElementInt32());
00260 theMission.missionState = Mission::MissionState(rmsg.getElementInt32());
00261
00262
00263 agentManager->updateAgentsMission(theMission);
00264 break;
00265 }
00266 case IMAGE_UPDATE:
00267 fNum++;
00268 img = rmsg.getElementColByteIma();
00269 agentManager->setCurrentImageF(img, fNum);
00270
00271 break;
00272 default:
00273 LINFO("Unknown purpose");
00274 }
00275 }
00276 }
00277
00278
00279 void checkOutMessages
00280 ( nub::ref<AgentManagerB> agentManager,
00281 nub::soft_ref<Beowulf> beo)
00282 {
00283 int32 rnode = -1;
00284 TCPmessage smsg;
00285
00286
00287 if(agentManager->getNumResults() > 0)
00288 {
00289
00290 SensorResult result = agentManager->popResult();
00291
00292
00293 packageSensorResult(result, smsg);
00294
00295
00296 beo->send(rnode, smsg);
00297 }
00298 }
00299
00300
00301 void packageSensorResult
00302 ( SensorResult sensorResult,
00303 TCPmessage &smsg)
00304 {
00305 int32 rframe = 0;
00306
00307 smsg.reset(rframe, SENSOR_RESULT);
00308
00309 SensorResult::SensorResultType type =
00310 sensorResult.getType();
00311
00312 smsg.addInt32(type);
00313
00314 smsg.addInt32(sensorResult.getStatus());
00315
00316
00317 switch(type)
00318 {
00319 case SensorResult::BUOY:
00320 {
00321 Point3D pos = sensorResult.getPosition();
00322 smsg.addInt32(int32(pos.x));
00323 smsg.addInt32(int32(pos.y));
00324 smsg.addInt32(int32(pos.z));
00325 break;
00326 }
00327 case SensorResult::PIPE:
00328 {
00329 Point3D pos = sensorResult.getPosition();
00330 smsg.addInt32(int32(pos.x));
00331 smsg.addInt32(int32(pos.y));
00332 smsg.addInt32(int32(pos.z));
00333 Angle ori = sensorResult.getOrientation();
00334 smsg.addDouble(ori.getVal());
00335 uint fnum = sensorResult.getFrameNum();
00336 smsg.addInt32(int32(fnum));
00337 break;
00338 }
00339 case SensorResult::BIN:
00340 {
00341 Point3D pos = sensorResult.getPosition();
00342 smsg.addInt32(int32(pos.x));
00343 smsg.addInt32(int32(pos.y));
00344 smsg.addInt32(int32(pos.z));
00345 break;
00346 }
00347 case SensorResult::PINGER:
00348 {
00349 Angle ori = sensorResult.getOrientation();
00350 smsg.addDouble(ori.getVal());
00351 break;
00352 }
00353 case SensorResult::SALIENCY:
00354 {
00355 Point3D pos = sensorResult.getPosition();
00356 smsg.addInt32(int32(pos.x));
00357 smsg.addInt32(int32(pos.y));
00358 smsg.addInt32(int32(pos.z));
00359 break;
00360 }
00361 default: LINFO("Unknown sensor result type: %d",type);
00362 }
00363 }
00364
00365
00366
00367
00368
00369