SeaBee3GUIIce.C

00001 #ifndef SeaBee3GUIIce_C
00002 #define SeaBee3GUIIce_C
00003 
00004 #include "Qt/SeaBee3GUIIce.H"
00005 #include "Ice/ImageIce.ice.H"
00006 #include "Ice/IceImageUtils.H"
00007 
00008 
00009 #define MSG_BUFF_MAX 5
00010 
00011 SeaBee3GUIIce::SeaBee3GUIIce(OptionManager& mgr,
00012                              const std::string& descrName,
00013                              const std::string& tagName) :
00014   RobotBrainComponent(mgr, descrName, tagName),
00015   itsGUIRegistered(false),
00016   itsFwdRetinaMsgCounter(0),
00017   itsDwnRetinaMsgCounter(0),
00018   itsOrangeSegEnabled(false),
00019   itsRedSegImagesSize(0),
00020   itsSalientPointsSize(0),
00021   itsSalientPointsEnabled(false),
00022   itsVisionMsgCounter(0),
00023   itsBeeStemMsgCounter(0),
00024   itsCompassMeter(140,130),
00025   itsDepthMeter(140,130),
00026   itsPressureMeter(100,90),
00027   itsCircleFillMeter(60,50,20),
00028   itsTargetLineMeter(100,50)
00029 {
00030   itsTimer.reset();
00031   itsFwdVisionImage = Image<PixRGB<byte> >();
00032   itsDwnVisionImage = Image<PixRGB<byte> >();
00033 }
00034 
00035 void SeaBee3GUIIce::registerTopics()
00036 {
00037   registerSubscription("BeeStemMessageTopic");
00038   registerSubscription("XBox360RemoteControlMessageTopic");
00039   registerSubscription("RetinaMessageTopic");
00040   registerSubscription("VisionRectangleMessageTopic");
00041   registerSubscription("SalientPointMessageTopic");
00042   registerSubscription("MovementControllerMessageTopic");
00043   registerPublisher("CameraConfigTopic");
00044   registerPublisher("BeeStemConfigTopic");
00045   registerPublisher("SeaBeeStateConditionMessageTopic");
00046 }
00047 
00048 void SeaBee3GUIIce::evolve()
00049 {
00050   itsUpdateMutex.lock();
00051   if(itsGUIRegistered)
00052     {
00053       if(itsFwdRetinaImages.size() > 0)
00054         {
00055           updateFwdImg();
00056 
00057           if(itsOrangeSegImages.size() > 0 && itsOrangeSegEnabled)
00058             {
00059               Image<PixRGB<byte> > oj = itsOrangeSegImages.front();
00060 
00061               itsFwdVisionImage = oj;
00062               itsOrangeSegImages.pop_front();
00063             }
00064 
00065           if(itsSalientPoints.size() > 0 && itsSalientPointsEnabled)
00066             updateSaliencyImage();
00067 
00068           itsGUIForm->setFwdVisionImage(itsFwdVisionImage);
00069 
00070         }
00071       if(itsDwnRetinaImages.size() > 0)
00072         {
00073           updateDwnImg();
00074 
00075           itsGUIForm->setDwnVisionImage(itsDwnVisionImage);
00076         }
00077 
00078       if(itsBeeStemData.size() > 0)
00079         {
00080           updateBeeStemData();
00081         }
00082     }
00083 
00084 
00085   if(itsTimer.getSecs() >= 1.0)
00086     {
00087       itsGUIForm->setFwdRetinaMsgField(itsFwdRetinaMsgCounter);
00088       itsGUIForm->setDwnRetinaMsgField(itsDwnRetinaMsgCounter);
00089       itsGUIForm->setBeeStemMsgField(itsBeeStemMsgCounter);
00090       itsGUIForm->setVisionMsgField(itsVisionMsgCounter);
00091       Image<PixRGB<byte> > headingAxis = itsCircleFillMeter.render(itsFwdRetinaMsgCounter);
00092       Image<PixRGB<byte> > depthAxis = itsCircleFillMeter.render(itsDwnRetinaMsgCounter);
00093       Image<PixRGB<byte> > strafeAxis = itsCircleFillMeter.render(itsBeeStemMsgCounter);
00094       itsGUIForm->setAxesImages(headingAxis,depthAxis,strafeAxis);
00095 
00096       itsTimer.reset();
00097       itsFwdRetinaMsgCounter = 0;
00098       itsDwnRetinaMsgCounter = 0;
00099       itsBeeStemMsgCounter = 0;
00100       itsVisionMsgCounter = 0;
00101     }
00102   itsUpdateMutex.unlock();
00103 }
00104 
00105 // ######################################################################
00106 void SeaBee3GUIIce::updateFwdImg()
00107 {
00108   Image<PixRGB<byte> > img = itsFwdRetinaImages.front();
00109   itsGUIForm->setFwdImage(img);
00110 
00111   itsFwdVisionImage = img;
00112 
00113   itsFwdRetinaImages.pop_front();
00114 }
00115 
00116 // ######################################################################
00117 void SeaBee3GUIIce::updateDwnImg()
00118 {
00119   Image<PixRGB<byte> > img = itsDwnRetinaImages.front();
00120   itsGUIForm->setDwnImage(img);
00121   itsDwnVisionImage = img;
00122 
00123   itsDwnRetinaImages.pop_front();
00124 }
00125 
00126 // ######################################################################
00127 void SeaBee3GUIIce::updateSaliencyImage()
00128 {
00129   Point2D<int> pt = itsSalientPoints.front();
00130 
00131   //  drawTraj(itsFwdVisionImage,
00132   //&(itsSalientPoints[0]),&(itsSalientPoints[2]));
00133 
00134   //  LINFO("Point %d, %d\n",pt.i,pt.j);
00135   PixRGB<byte> color(0,0,0);
00136   drawCircle(itsFwdVisionImage, pt, 10, PixRGB<byte>(0,150,0), 1);
00137   drawCircle(itsFwdVisionImage, pt, 13, PixRGB<byte>(0,100,0), 1);
00138   drawCircle(itsFwdVisionImage, pt, 16, PixRGB<byte>(0,50,0), 1);
00139   drawCircle(itsFwdVisionImage, pt, 19, PixRGB<byte>(0,0,0), 1);
00140 
00141 
00142   drawDisk(itsFwdVisionImage, pt, 7, PixRGB<byte>(0,0,0));
00143   drawDisk(itsFwdVisionImage, pt, 4, PixRGB<byte>(0,255,0));
00144 
00145   itsSalientPoints.pop_front();
00146 }
00147 
00148 // ######################################################################
00149 void SeaBee3GUIIce::updateBeeStemData()
00150 {
00151   BeeStemData d = itsBeeStemData.front();
00152 
00153   Image<PixRGB<byte> > compassImg = itsCompassMeter.render(d.heading);
00154   Image<PixRGB<byte> > depthImg = itsDepthMeter.render(d.externalPressure);
00155   Image<PixRGB<byte> > pressureImg = itsPressureMeter.render(d.internalPressure);
00156 
00157   itsTargetLineMeter.setDesiredValue(d.desiredDepth);
00158   Image<PixRGB<byte> > depthPIDImg = itsTargetLineMeter.render(d.externalPressure);
00159 
00160   itsGUIForm->setCompassImage(compassImg);
00161   itsGUIForm->setDepthImage(depthImg);
00162   itsGUIForm->setPressureImage(pressureImg);
00163   itsGUIForm->setDepthPIDImage(depthPIDImg);
00164 
00165   itsGUIForm->setBeeStemData(d);
00166 
00167   itsBeeStemData.pop_front();
00168 }
00169 
00170 void SeaBee3GUIIce::setOrangeSegEnabled(bool enabled)
00171 {
00172   itsUpdateMutex.lock();
00173   itsOrangeSegEnabled = enabled;
00174   itsUpdateMutex.unlock();
00175 }
00176 
00177 void SeaBee3GUIIce::setSalientPointsEnabled(bool enabled)
00178 {
00179   itsUpdateMutex.lock();
00180   itsSalientPointsEnabled = enabled;
00181   itsUpdateMutex.unlock();
00182 }
00183 
00184 // ######################################################################
00185 void SeaBee3GUIIce::updateMessage(const RobotSimEvents::EventMessagePtr& eMsg,
00186                                   const Ice::Current&)
00187 {
00188   itsUpdateMutex.lock();
00189   //Get a retina message
00190   if(eMsg->ice_isA("::RobotSimEvents::RetinaMessage"))
00191     {
00192       RobotSimEvents::RetinaMessagePtr msg = RobotSimEvents::RetinaMessagePtr::dynamicCast(eMsg);
00193       if(Ice2Image<PixRGB<byte> >(msg->img).initialized())
00194         {
00195           Image<PixRGB<byte> > retinaImage = Ice2Image<PixRGB<byte> >(msg->img);
00196 
00197           if(msg->cameraID == "FwdCamera")
00198             {
00199               if(itsFwdRetinaImages.size() == MSG_BUFF_MAX)
00200                 {
00201                   LINFO("Dropping fwd retina msg");
00202                   itsFwdRetinaImages.pop_front();
00203                 }
00204 
00205               itsFwdRetinaImages.push_back(retinaImage);
00206               itsFwdRetinaMsgCounter++;
00207             }
00208           else if(msg->cameraID == "DwnCamera")
00209             {
00210               if(itsDwnRetinaImages.size() == MSG_BUFF_MAX)
00211                 itsDwnRetinaImages.pop_front();
00212 
00213               itsDwnRetinaImages.push_back(retinaImage);
00214               itsDwnRetinaMsgCounter++;
00215             }
00216           else if(msg->cameraID == "BuoyColorSegmenter" && itsOrangeSegEnabled)
00217             {
00218               if(itsOrangeSegImages.size() == MSG_BUFF_MAX)
00219                 {
00220                   itsOrangeSegImages.pop_front();
00221                   LINFO("Dropping buoy color segmenter msg");
00222                 }
00223 
00224               itsOrangeSegImages.push_back(retinaImage);
00225               itsVisionMsgCounter++;
00226             }
00227         }
00228     }
00229   else if(eMsg->ice_isA("::RobotSimEvents::BeeStemMessage"))
00230     {
00231 
00232       RobotSimEvents::BeeStemMessagePtr msg = RobotSimEvents::BeeStemMessagePtr::dynamicCast(eMsg);
00233 
00234       BeeStemData d;
00235       d.heading = msg->compassHeading;
00236       d.externalPressure = msg->externalPressure;
00237       d.internalPressure = msg->internalPressure;
00238       d.headingPIDOutput = msg->headingOutput;
00239       d.depthPIDOutput = msg->depthOutput;
00240       d.desiredDepth = msg->desiredDepth;
00241       d.killSwitch = (msg->killSwitch == 1) ? true : false;
00242 
00243       if(itsBeeStemData.size() == MSG_BUFF_MAX)
00244         {
00245           LINFO("Dropping bee stem msg");
00246           itsBeeStemData.pop_front();
00247         }
00248 
00249       itsBeeStemData.push_back(d);
00250       itsBeeStemMsgCounter++;
00251     }
00252   else if(eMsg->ice_isA("::RobotSimEvents::SalientPointMessage"))
00253     {
00254       RobotSimEvents::SalientPointMessagePtr msg = RobotSimEvents::SalientPointMessagePtr::dynamicCast(eMsg);
00255       if(itsSalientPoints.size() == MSG_BUFF_MAX)
00256         itsSalientPoints.pop_front();
00257 
00258       itsSalientPoints.push_back(Point2D<int>((int)(itsFwdVisionImage.getWidth()*msg->x),
00259                                               (int)(itsFwdVisionImage.getHeight()*msg->y)));
00260       itsVisionMsgCounter++;
00261     }
00262 
00263   itsUpdateMutex.unlock();
00264 }
00265 //     itsGUIForm->setThrusterMeters(
00266 //         0,
00267 //         (int)msg->thruster1,
00268 //         (int)msg->thruster2,
00269 //         (int)msg->thruster3,
00270 //         (int)msg->thruster4,
00271 //         (int)msg->thruster5,
00272 //         (int)msg->thruster6,
00273 //         0
00274 //         );
00275 
00276 //   // Get a XBox360RemoteControl Message
00277 //   else if(eMsg->ice_isA("::RobotSimEvents::JoyStickControlMessage"))
00278 //   {
00279 //     RobotSimEvents::JoyStickControlMessagePtr msg = RobotSimEvents::JoyStickControlMessagePtr::dynamicCast(eMsg);
00280 
00281 //     itsGUIFormMutex.lock();
00282 //     if(itsGUIRegistered)
00283 //     {
00284 //       if(msg->axis >= 0)
00285 //         itsGUIForm->setJSAxis(msg->axis, msg->axisVal);
00286 //       else
00287 //         LINFO("Button[%d] = %d",msg->button, msg->butVal);
00288 //     }
00289 //     itsGUIFormMutex.unlock();
00290 //   }
00291 //   // Get a BeeStem Message
00292 
00293 //   else if(eMsg->ice_isA("::RobotSimEvents::VisionRectangleMessage"))
00294 //     {
00295 //       RobotSimEvents::VisionRectangleMessagePtr msg = RobotSimEvents::VisionRectangleMessagePtr::dynamicCast(eMsg);
00296 //       itsGUIFormMutex.lock();
00297 //       if(itsGUIRegistered)
00298 //         {
00299 //           if(msg->isFwdCamera)
00300 //             {
00301 //               for(uint i = 0; i < msg->quads.size(); i++)
00302 //                 {
00303 //                   itsGUIForm->pushFwdRectangle(msg->quads[i]);
00304 //                 }
00305 //             }
00306 //           else
00307 //             {
00308 //               for(uint i = 0; i < msg->quads.size(); i++)
00309 //                 {
00310 
00311 //                   itsGUIForm->pushRectRatio(msg->quads[i].ratio);
00312 //                   itsGUIForm->pushRectAngle(msg->quads[i].angle);
00313 
00314 //                   itsGUIForm->pushContourPoint(Point2D<int>(msg->quads[i].tl.i,msg->quads[i].tl.j));
00315 //                   itsGUIForm->pushContourPoint(Point2D<int>(msg->quads[i].tr.i, msg->quads[i].tr.j));
00316 //                   itsGUIForm->pushContourPoint(Point2D<int>(msg->quads[i].br.i, msg->quads[i].br.j));
00317 //                   itsGUIForm->pushContourPoint(Point2D<int>(msg->quads[i].bl.i, msg->quads[i].bl.j));
00318 //                 }
00319 //             }
00320 //         }
00321 //       itsGUIFormMutex.unlock();
00322 //     }
00323 //   else if(eMsg->ice_isA("::RobotSimEvents::SalientPointMessage"))
00324 //     {
00325 //       RobotSimEvents::SalientPointMessagePtr msg = RobotSimEvents::SalientPointMessagePtr::dynamicCast(eMsg);
00326 //       itsGUIFormMutex.lock();
00327 //       if(itsGUIRegistered)
00328 //         {
00329 //           itsGUIForm->setSalientPoint(Point2D<float>(msg->x,msg->y));
00330 //         }
00331 //       itsGUIFormMutex.unlock();
00332 //     }
00333 //   else if(eMsg->ice_isA("::RobotSimEvents::MovementControllerMessage"))
00334 //     {
00335 //       RobotSimEvents::MovementControllerMessagePtr msg = RobotSimEvents::MovementControllerMessagePtr::dynamicCast(eMsg);
00336 //       itsGUIFormMutex.lock();
00337 //       if(itsGUIRegistered)
00338 //         {
00339 //           itsGUIForm->setSensorVotes(msg->votes);
00340 //           itsGUIForm->setCompositeHeading(msg->compositeHeading);
00341 //           itsGUIForm->setCompositeDepth(msg->compositeDepth);
00342 //         }
00343 //       itsGUIFormMutex.unlock();
00344 //     }
00345 
00346 // ######################################################################
00347 void SeaBee3GUIIce::registerGUI(SeaBee3MainDisplayForm* form)
00348 {
00349   itsGUIFormMutex.lock();
00350   itsGUIForm = form;
00351   itsGUIRegistered = true;
00352   itsGUIFormMutex.unlock();
00353 }
00354 #endif
00355 
Generated on Sun May 8 08:41:15 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3