00001 #ifndef SeaBee3GUICommunicator_C
00002 #define SeaBee3GUICommunicator_C
00003
00004 #include "Qt/SeaBee3GUICommunicator.H"
00005 #include "Ice/ImageIce.ice.H"
00006 #include "Ice/IceImageUtils.H"
00007
00008
00009 SeaBee3GUICommunicator::SeaBee3GUICommunicator(OptionManager& mgr,
00010 const std::string& descrName,
00011 const std::string& tagName) :
00012 RobotBrainComponent(mgr, descrName, tagName),
00013 itsGUIRegistered(false),
00014 itsFwdFrameCount(0),
00015 itsLastFwdFrameCount(0),
00016 itsDwnFrameCount(0),
00017 itsLastDwnFrameCount(0)
00018 {
00019 }
00020
00021 void SeaBee3GUICommunicator::registerTopics()
00022 {
00023 registerSubscription("BeeStemMessageTopic");
00024 registerSubscription("XBox360RemoteControlMessageTopic");
00025 registerSubscription("RetinaMessageTopic");
00026 registerSubscription("VisionRectangleMessageTopic");
00027 registerSubscription("SalientPointMessageTopic");
00028 registerSubscription("MovementControllerMessageTopic");
00029 registerPublisher("CameraConfigTopic");
00030 registerPublisher("BeeStemConfigTopic");
00031 registerPublisher("SeaBeeStateConditionMessageTopic");
00032 }
00033
00034 void SeaBee3GUICommunicator::evolve()
00035 {
00036 itsImageMutex.lock();
00037 Image<PixRGB<byte> > fwdImg = itsFwdImg;
00038 Image<PixRGB<byte> > dwnImg = itsDwnImg;
00039 itsImageMutex.unlock();
00040
00041 itsGUIFormMutex.lock();
00042 if(itsGUIRegistered)
00043 {
00044 if(fwdImg.initialized() && itsFwdFrameCount != itsLastFwdFrameCount)
00045 {
00046 itsLastFwdFrameCount = itsFwdFrameCount;
00047 itsGUIForm->setImage(fwdImg, "FwdCamera");
00048 }
00049
00050 if(dwnImg.initialized() && itsDwnFrameCount != itsLastDwnFrameCount)
00051 {
00052 itsLastDwnFrameCount = itsDwnFrameCount;
00053 itsGUIForm->setImage(dwnImg, "DwnCamera");
00054 }
00055 }
00056 itsGUIFormMutex.unlock();
00057 }
00058
00059 void SeaBee3GUICommunicator::toggleCamera(std::string cameraID, bool active) {
00060
00061 RobotSimEvents::CameraConfigMessagePtr msg = new RobotSimEvents::CameraConfigMessage;
00062 msg->cameraID=cameraID;
00063 msg->active=active;
00064
00065 this->publish("CameraConfigTopic", msg);
00066 }
00067
00068 void SeaBee3GUICommunicator::updatePoseSettings(int updateSelect, int heading, int depth, int speed)
00069 {
00070
00071 RobotSimEvents::BeeStemConfigMessagePtr msg = new RobotSimEvents::BeeStemConfigMessage;
00072 msg->desiredHeading = heading;
00073 msg->desiredDepth = depth;
00074 msg->desiredSpeed = speed;
00075 msg->updateDesiredValue = updateSelect;
00076
00077 msg->headingK = 0.0;
00078 msg->headingP = 0.0;
00079 msg->headingI = 0.0;
00080 msg->headingD = 0.0;
00081 msg->updateHeadingPID = false;
00082
00083 msg->depthK = 0.0;
00084 msg->depthP = 0.0;
00085 msg->depthI = 0.0;
00086 msg->depthD = 0.0;
00087 msg->updateDepthPID = false;
00088
00089 msg->enablePID = 0;
00090 msg->enableVal = 0;
00091
00092
00093 this->publish("BeeStemConfigTopic", msg);
00094 }
00095
00096 void SeaBee3GUICommunicator::updatePID(int pidSelect, float k, float p, float i, float d)
00097 {
00098
00099
00100 RobotSimEvents::BeeStemConfigMessagePtr msg = new RobotSimEvents::BeeStemConfigMessage;
00101 msg->desiredHeading = 0.0;
00102 msg->desiredDepth = 0.0;
00103 msg->desiredSpeed = 0.0;
00104 msg->updateDesiredValue = 0;
00105
00106 msg->headingK = 0.0;
00107 msg->headingP = 0.0;
00108 msg->headingI = 0.0;
00109 msg->headingD = 0.0;
00110 msg->updateHeadingPID = false;
00111
00112 msg->depthK = 0.0;
00113 msg->depthP = 0.0;
00114 msg->depthI = 0.0;
00115 msg->depthD = 0.0;
00116 msg->updateDepthPID = false;
00117
00118 msg->enablePID = 0;
00119 msg->enableVal = 0;
00120
00121
00122 if(pidSelect == 1)
00123 {
00124 msg->headingK = k;
00125 msg->headingP = p;
00126 msg->headingI = i;
00127 msg->headingD = d;
00128 msg->updateHeadingPID = 1;
00129 }
00130
00131 else if(pidSelect == 0)
00132 {
00133 msg->depthK = k;
00134 msg->depthP = p;
00135 msg->depthI = i;
00136 msg->depthD = d;
00137 msg->updateDepthPID = 1;
00138 }
00139
00140
00141
00142 this->publish("BeeStemConfigTopic", msg);
00143 }
00144
00145
00146
00147 void SeaBee3GUICommunicator::updateMessage(const RobotSimEvents::EventMessagePtr& eMsg,
00148 const Ice::Current&)
00149 {
00150
00151 if(eMsg->ice_isA("::RobotSimEvents::RetinaMessage"))
00152 {
00153 RobotSimEvents::RetinaMessagePtr retinaMessage = RobotSimEvents::RetinaMessagePtr::dynamicCast(eMsg);
00154 Image<PixRGB<byte> > retinaImage = Ice2Image<PixRGB<byte> >(retinaMessage->img);
00155
00156 itsImageMutex.lock();
00157
00158 if(retinaMessage->cameraID == "FwdCamera")
00159 {
00160 itsFwdImg = retinaImage;
00161 itsFwdFrameCount++;
00162 }
00163 else
00164 {
00165 itsDwnImg = retinaImage;
00166 itsDwnFrameCount++;
00167 }
00168
00169 itsImageMutex.unlock();
00170 }
00171
00172 else if(eMsg->ice_isA("::RobotSimEvents::JoyStickControlMessage"))
00173 {
00174 RobotSimEvents::JoyStickControlMessagePtr msg = RobotSimEvents::JoyStickControlMessagePtr::dynamicCast(eMsg);
00175
00176 itsGUIFormMutex.lock();
00177 if(itsGUIRegistered)
00178 {
00179 if(msg->axis >= 0)
00180 itsGUIForm->setJSAxis(msg->axis, msg->axisVal);
00181 else
00182 LINFO("Button[%d] = %d",msg->button, msg->butVal);
00183 }
00184 itsGUIFormMutex.unlock();
00185 }
00186
00187 else if(eMsg->ice_isA("::RobotSimEvents::BeeStemMessage"))
00188 {
00189
00190 RobotSimEvents::BeeStemMessagePtr msg = RobotSimEvents::BeeStemMessagePtr::dynamicCast(eMsg);
00191 itsGUIFormMutex.lock();
00192 if(itsGUIRegistered)
00193 {
00194 int killSwitch = msg->killSwitch;
00195 killSwitch = killSwitch;
00196 itsGUIForm->setSensorValues(msg->compassHeading,
00197 msg->compassPitch,
00198 msg->compassRoll,
00199 msg->internalPressure,
00200 msg->externalPressure,
00201 msg->headingOutput,
00202 msg->depthOutput);
00203 }
00204
00205
00206 itsGUIForm->setThrusterMeters(
00207 0,
00208 (int)msg->thruster1,
00209 (int)msg->thruster2,
00210 (int)msg->thruster3,
00211 (int)msg->thruster4,
00212 (int)msg->thruster5,
00213 (int)msg->thruster6,
00214 0
00215 );
00216
00217
00218
00219 itsGUIFormMutex.unlock();
00220 }
00221 else if(eMsg->ice_isA("::RobotSimEvents::VisionRectangleMessage"))
00222 {
00223 RobotSimEvents::VisionRectangleMessagePtr msg = RobotSimEvents::VisionRectangleMessagePtr::dynamicCast(eMsg);
00224 itsGUIFormMutex.lock();
00225 if(itsGUIRegistered)
00226 {
00227 if(msg->isFwdCamera)
00228 {
00229 for(uint i = 0; i < msg->quads.size(); i++)
00230 {
00231 itsGUIForm->pushFwdRectangle(msg->quads[i]);
00232 }
00233 }
00234 else
00235 {
00236 for(uint i = 0; i < msg->quads.size(); i++)
00237 {
00238
00239 itsGUIForm->pushRectRatio(msg->quads[i].ratio);
00240 itsGUIForm->pushRectAngle(msg->quads[i].angle);
00241
00242 itsGUIForm->pushContourPoint(Point2D<int>(msg->quads[i].tl.i,msg->quads[i].tl.j));
00243 itsGUIForm->pushContourPoint(Point2D<int>(msg->quads[i].tr.i, msg->quads[i].tr.j));
00244 itsGUIForm->pushContourPoint(Point2D<int>(msg->quads[i].br.i, msg->quads[i].br.j));
00245 itsGUIForm->pushContourPoint(Point2D<int>(msg->quads[i].bl.i, msg->quads[i].bl.j));
00246 }
00247 }
00248 }
00249 itsGUIFormMutex.unlock();
00250 }
00251 else if(eMsg->ice_isA("::RobotSimEvents::SalientPointMessage"))
00252 {
00253 RobotSimEvents::SalientPointMessagePtr msg = RobotSimEvents::SalientPointMessagePtr::dynamicCast(eMsg);
00254 itsGUIFormMutex.lock();
00255 if(itsGUIRegistered)
00256 {
00257 itsGUIForm->setSalientPoint(Point2D<float>(msg->x,msg->y));
00258 }
00259 itsGUIFormMutex.unlock();
00260 }
00261 else if(eMsg->ice_isA("::RobotSimEvents::MovementControllerMessage"))
00262 {
00263 RobotSimEvents::MovementControllerMessagePtr msg = RobotSimEvents::MovementControllerMessagePtr::dynamicCast(eMsg);
00264 itsGUIFormMutex.lock();
00265 if(itsGUIRegistered)
00266 {
00267 itsGUIForm->setSensorVotes(msg->votes);
00268 itsGUIForm->setCompositeHeading(msg->compositeHeading);
00269 itsGUIForm->setCompositeDepth(msg->compositeDepth);
00270 }
00271 itsGUIFormMutex.unlock();
00272 }
00273 }
00274
00275
00276 void SeaBee3GUICommunicator::enablePID()
00277 {
00278 RobotSimEvents::BeeStemConfigMessagePtr msg = new RobotSimEvents::BeeStemConfigMessage;
00279 msg->desiredHeading = 0.0;
00280 msg->desiredDepth = 0.0;
00281 msg->desiredSpeed = 0.0;
00282 msg->updateDesiredValue = 0;
00283
00284 msg->headingK = 0.0;
00285 msg->headingP = 0.0;
00286 msg->headingI = 0.0;
00287 msg->headingD = 0.0;
00288 msg->updateHeadingPID = false;
00289
00290 msg->depthK = 0.0;
00291 msg->depthP = 0.0;
00292 msg->depthI = 0.0;
00293 msg->depthD = 0.0;
00294 msg->updateDepthPID = false;
00295
00296 msg->enablePID = 1;
00297 msg->enableVal = 1;
00298
00299 this->publish("BeeStemConfigTopic", msg);
00300 }
00301
00302
00303 void SeaBee3GUICommunicator::disablePID()
00304 {
00305 RobotSimEvents::BeeStemConfigMessagePtr msg = new RobotSimEvents::BeeStemConfigMessage;
00306 msg->desiredHeading = 0.0;
00307 msg->desiredDepth = 0.0;
00308 msg->desiredSpeed = 0.0;
00309 msg->updateDesiredValue = 0;
00310
00311 msg->headingK = 0.0;
00312 msg->headingP = 0.0;
00313 msg->headingI = 0.0;
00314 msg->headingD = 0.0;
00315 msg->updateHeadingPID = false;
00316
00317 msg->depthK = 0.0;
00318 msg->depthP = 0.0;
00319 msg->depthI = 0.0;
00320 msg->depthD = 0.0;
00321 msg->updateDepthPID = false;
00322
00323 msg->enablePID = 1;
00324 msg->enableVal = 0;
00325 this->publish("BeeStemConfigTopic", msg);
00326
00327 }
00328
00329 void SeaBee3GUICommunicator::registerGUI(SeaBee3MainDisplayForm* form)
00330 {
00331 itsGUIFormMutex.lock();
00332 itsGUIForm = form;
00333 itsGUIRegistered = true;
00334 itsGUIFormMutex.unlock();
00335 }
00336
00337 void SeaBee3GUICommunicator::SeaBeeInjectorMsg(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j)
00338 {
00339 RobotSimEvents::SeaBeeStateConditionMessagePtr msg;
00340 msg = new RobotSimEvents::SeaBeeStateConditionMessage;
00341
00342 msg->InitDone = a;
00343 msg->GateFound = b;
00344 msg->GateDone = c;
00345 msg->ContourFoundFlare = d;
00346 msg->FlareDone = e;
00347 msg->ContourFoundBarbwire = f;
00348 msg->BarbwireDone = g;
00349 msg->ContourFoundBoxes = h;
00350 msg->BombingRunDone = i;
00351 msg->BriefcaseFound = j;
00352 msg->TimeUp = 0;
00353
00354 publish("SeaBeeStateConditionMessageTopic",msg);
00355 }
00356 #endif
00357