ptuwindow.cpp
Go to the documentation of this file.
00001 
00018 #include "GUI/ptuwindow.h"
00019 #include "QImage"
00020 #include "QRgb"
00021 #include <QFileDialog>
00022 
00023 
00024 PTUWindow::PTUWindow(QWidget *parent) :
00025     QDialog(parent)
00026 {
00027     transformationData.clear();
00028     boost::shared_ptr<MarkerPublisher> myMarkerPublisher(new MarkerPublisher(calibrationObject));
00029     boost::shared_ptr<Transformation_Publisher> myTransformationPublisher(new Transformation_Publisher(calibrationObject));
00030     this->init(myMarkerPublisher, calibrationObject, myTransformationPublisher, Eigen::Matrix4d::Identity());
00031 }
00032 
00033 PTUWindow::PTUWindow(boost::shared_ptr<MarkerPublisher> markerPublisher, boost::shared_ptr<Calibration_Object> calibrationObject, boost::shared_ptr<Transformation_Publisher> transformationPublisher,const Eigen::Matrix4d calObjTransformation, QWidget *parent) :
00034     QDialog(parent)
00035 {
00036     this->init(markerPublisher, calibrationObject, transformationPublisher, calObjTransformation);
00037 }
00038 
00039 void PTUWindow::init(boost::shared_ptr<MarkerPublisher> markerPublisher, boost::shared_ptr<Calibration_Object> calibrationObject, boost::shared_ptr<Transformation_Publisher> transformationPublisher, const Eigen::Matrix4d calObjTransformation)
00040 {
00041     this->setWindowTitle( "PTU Calibration");
00042     ros::NodeHandle mNodeHandle(ros::this_node::getName());
00043     double pan_min_angle, pan_max_angle, tilt_min_angle, tilt_max_angle;
00044     double marker_recognizer_timeout,marker_recognizer_early_abort_timeout, marker_min_distance, marker_max_distance;
00045     int pan_step_count, tilt_step_count;
00046     bool useAveragedMarkerData;
00047     mNodeHandle.getParam("pan_min_angle", pan_min_angle);
00048     mNodeHandle.getParam("pan_max_angle", pan_max_angle);
00049     mNodeHandle.getParam("tilt_min_angle", tilt_min_angle);
00050     mNodeHandle.getParam("tilt_max_angle", tilt_max_angle);
00051     mNodeHandle.getParam("pan_step_count", pan_step_count);
00052     mNodeHandle.getParam("tilt_step_count", tilt_step_count);
00053     mNodeHandle.getParam("marker_recognizer_timeout", marker_recognizer_timeout);
00054     mNodeHandle.getParam("marker_recognizer_early_abort_timeout", marker_recognizer_early_abort_timeout);
00055     mNodeHandle.getParam("marker_min_distance", marker_min_distance);
00056     mNodeHandle.getParam("marker_max_distance", marker_max_distance);
00057     mNodeHandle.getParam("useAveragedMarkerData", useAveragedMarkerData);
00058     this->marker_min_distance = marker_min_distance;
00059     this->marker_max_distance = marker_max_distance;
00060     this->tilt_min_angle = tilt_min_angle;
00061     this->tilt_max_angle = tilt_max_angle;
00062     this->pan_min_angle = pan_min_angle;
00063     this->pan_max_angle = pan_max_angle;
00064     this->useAveragedMarkerData = useAveragedMarkerData;
00065     ptuManager = new PTU_Manager(pan_min_angle, pan_max_angle, tilt_min_angle, tilt_max_angle, pan_step_count, tilt_step_count);
00066     ROS_INFO("Manager started");
00067 
00068     ptuManager->setNeutralPose();
00069 
00070     this->markerPublisher = markerPublisher;
00071     this->calibrationObject = calibrationObject;
00072     this->transformationPublisher = transformationPublisher;
00073     this->transformation_LaserScanner = calObjTransformation;
00074     this->markerManager = new Marker_Manager(marker_recognizer_timeout, marker_recognizer_early_abort_timeout);
00075 
00076     markerPublisher->publishARMarkers(false, false, transformation_LaserScanner);
00077 
00078     btnStartStopPTUSearch = new QPushButton(this);
00079     btnStartStopPTUSearch->resize(100, 25);
00080     btnStartStopPTUSearch->setVisible(true);
00081     btnStartStopPTUSearch->setText("Start");
00082 
00083     btnExportCameraPoses = new QPushButton(this);
00084     btnExportCameraPoses->resize(100, 25);
00085     btnExportCameraPoses->setVisible(true);
00086     btnExportCameraPoses->setText("Export Camera");
00087     btnExportCameraPoses->setEnabled(false);
00088 
00089     btnExportRelativeMarkerPoses = new QPushButton(this);
00090     btnExportRelativeMarkerPoses->resize(100, 25);
00091     btnExportRelativeMarkerPoses->setVisible(true);
00092     btnExportRelativeMarkerPoses->setText("Export Marker");
00093     btnExportCameraPoses->setEnabled(false);
00094 
00095     btnSkipFramePTUSearch = new QPushButton(this);
00096     btnSkipFramePTUSearch->resize(100, 25);
00097     btnSkipFramePTUSearch->setVisible(true);
00098     btnSkipFramePTUSearch->setText("Skip Frame");
00099     btnSkipFramePTUSearch->setEnabled(false);
00100 
00101     btnExportCameraOffset = new QPushButton(this);
00102     btnExportCameraOffset->resize(100, 25);
00103     btnExportCameraOffset->setVisible(true);
00104     btnExportCameraOffset->setText("Export Offset");
00105     btnExportCameraOffset->setEnabled(false);
00106 
00107     lblCameraFrameCount = new QLabel(this);
00108     lblCameraFrameCount->resize(200, 30);
00109     lblCameraFrameCount->setVisible(true);
00110 
00111     lblRelativeMarkerFrameCount = new QLabel(this);
00112     lblRelativeMarkerFrameCount->resize(350, 30);
00113     lblRelativeMarkerFrameCount->setVisible(true);
00114 
00115     CameraThread * camThreadLeft = new CameraThread(0, "/stereo/left/image_raw");
00116     cameraLeft = new CameraWidget(this, camThreadLeft);
00117 
00118     cameraLeft->resize(320,240);
00119     cameraLeft->move(50,50);
00120 
00121     CameraThread * camThreadRight = new CameraThread(0, "/stereo/right/image_raw");
00122     cameraRight = new CameraWidget(this, camThreadRight);
00123     cameraRight->resize(320,240);
00124     cameraRight->move(400,50);
00125 
00126     connect(btnStartStopPTUSearch, SIGNAL(clicked()),this, SLOT(btnStartStopPTUSearch_clicked()));
00127     connect(btnExportCameraPoses, SIGNAL(clicked()),this, SLOT(btnExportCameraPoses_clicked()));
00128     connect(btnExportRelativeMarkerPoses, SIGNAL(clicked()),this, SLOT(btnExportRelativeMarkerPoses_clicked()));
00129     connect(btnExportCameraOffset, SIGNAL(clicked()),this, SLOT(btnExportCameraOffset_clicked()));
00130     connect(btnSkipFramePTUSearch, SIGNAL(clicked()),this, SLOT(btnSkipFramePTUSearch_clicked()));
00131 
00132     connect(this, SIGNAL(newTransform_Camera(const Eigen::Matrix4d, Markertype)),this->transformationPublisher.get(), SLOT(newTransform_Camera(const Eigen::Matrix4d, Markertype)));
00133 
00134     ROS_INFO("PTU Window started");
00135     stopSignal = true;
00136 
00137     mTFlistener = new tf::TransformListener();
00138 
00139     setUI_Elements();
00140 }
00141 
00142 void PTUWindow::setUI_Elements()
00143 {
00144     btnExportCameraPoses->setEnabled(transformationData.size() > 0);
00145     btnExportRelativeMarkerPoses->setEnabled(relativeMarkerPoses.size() > 0);
00146     btnExportCameraOffset->setEnabled(relativeMarkerPoses.size() > 0);
00147 
00148     QString text = "Camera datasets found: ";
00149     text += QString::number(transformationData.size());
00150     lblCameraFrameCount->setText(text);
00151 
00152     text = "Relative marker frames found: ";
00153     text += QString::number(relativeMarkerPoses.size());
00154     //Calculate standard deviation
00155     if (relativeMarkerPoses.size() > 0)
00156     {
00157         double standardDeviation = 0.0;
00158         for (unsigned int i = 0; i < relativeMarkerPoses.size(); i++)
00159         {
00160             Eigen::Vector3d averageTranslation(relativeMarkerPoses.at(i)(0,3), relativeMarkerPoses.at(i)(1,3),relativeMarkerPoses.at(i)(2,3));
00161             standardDeviation += pow(averageTranslation.norm(), 2.0);
00162         }
00163         standardDeviation = sqrt(standardDeviation/(double)relativeMarkerPoses.size());
00164         text += ", standarddeviation: ";
00165         text += QString::number(standardDeviation);
00166     }
00167 
00168     lblRelativeMarkerFrameCount->setText(text);
00169 }
00170 
00171 void PTUWindow::resizeEvent(QResizeEvent * event)
00172 {
00173     cameraLeft->resize(this->width()/2-60,this->height()-150);
00174     cameraLeft->move(30,50);
00175     cameraRight->resize(this->width()/2-60,this->height()-150);
00176     cameraRight->move(this->width()/2+30,50);
00177     btnSkipFramePTUSearch->move(this->width()-540,this->height()-40);
00178     btnStartStopPTUSearch->move(this->width()-435,this->height()-40);
00179     btnExportCameraPoses->move(this->width()-330,this->height()-40);
00180     btnExportRelativeMarkerPoses->move(this->width()-225,this->height()-40);
00181     btnExportCameraOffset->move(this->width()-120,this->height()-40);
00182     lblCameraFrameCount->move(30,this->height()-75);
00183     lblRelativeMarkerFrameCount->move(30,this->height()-45);
00184     QDialog::resizeEvent(event);
00185 }
00186 
00187 void PTUWindow::btnSkipFramePTUSearch_clicked()
00188 {
00189     if(!stopSignal && slotEnabled_Marker)
00190     {
00191         stopMarkerCapturing();
00192     }
00193 }
00194 
00195 void PTUWindow::btnStartStopPTUSearch_clicked()
00196 {
00197     if (stopSignal)
00198     {
00199         ROS_INFO("PTU: Starting iteration..");
00200         btnStartStopPTUSearch->setText("Stop");
00201         stopSignal = false;
00202         startCapture();
00203     }
00204     else
00205     {
00206         disconnect(this, SLOT(ptu_moved(double, double)));
00207         disconnect(this, SLOT(markerFound(std::string, const Eigen::Matrix4d)));
00208         btnStartStopPTUSearch->setText("Start");
00209         stopSignal = true;
00210     }
00211 }
00212 
00213 void PTUWindow::btnExportCameraOffset_clicked()
00214 {
00215     if (cameraOffsetParameters.size() > 0)
00216     {
00217         QString fileName = QFileDialog::getSaveFileName(this, "Save file", "CameraOffset.off", tr("Offsetfile (*.off)"));
00218         if (fileName.length() > 0)
00219         {
00220             ROS_INFO_STREAM("File: " << fileName.toStdString());
00221             TransformationFile_Manager_Data fileManager(fileName.toStdString());
00222             fileManager.writeCameraOffsetToFile(cameraOffsetParameters);
00223         }
00224     }
00225 
00226 }
00227 
00228 void PTUWindow::btnExportCameraPoses_clicked()
00229 {
00230     if (transformationData.size() > 0)
00231     {
00232         QString fileName = QFileDialog::getSaveFileName(this, "Save file", "CalibrationData.data", tr("Calibrationfile (*.data)"));
00233         if (fileName.length() > 0)
00234         {
00235             ROS_INFO_STREAM("File: " << fileName.toStdString());
00236             TransformationFile_Manager_Data fileManager(fileName.toStdString());
00237             fileManager.writeToFile(transformationData);
00238         }
00239     }
00240 }
00241 
00242 void PTUWindow::btnExportRelativeMarkerPoses_clicked()
00243 {
00244     if (relativeMarkerPoses.size() > 0)
00245     {
00246         QString fileName = QFileDialog::getSaveFileName(this, "Save file", "CalibrationData.data", tr("Calibrationfile (*.data)"));
00247         if (fileName.length() > 0)
00248         {
00249             ROS_INFO_STREAM("File: " << fileName.toStdString());
00250             TransformationFile_Manager_Data fileManager(fileName.toStdString());
00251             fileManager.writeTransformationToFile(relativeMarkerPoses);
00252         }
00253     }
00254 }
00255 
00256 void PTUWindow::startCapture()
00257 {
00258     ptuManager->setStartPose();
00259     colouredCameraFrames.clear();
00260     markerLeftPoses.clear();
00261     markerRightPoses.clear();
00262     tempMarkerLeftPoses.clear();
00263     tempMarkerRightPoses.clear();
00264     cameraOffsetParameters.clear();
00265     connect(ptuManager, SIGNAL(ptu_moved(double, double)),this, SLOT(ptu_moved(double, double)));
00266     connect(markerManager, SIGNAL(markerFound(std::string,const Eigen::Matrix4d)),this, SLOT(markerFound(std::string, const Eigen::Matrix4d)));
00267     ROS_INFO("PTU: Starting iteration..");
00268     if (this->useAveragedMarkerData)
00269     {
00270         ROS_INFO("Averaging PTU frame ON");
00271     }
00272     else
00273     {
00274         ROS_INFO("Averaging PTU frame OFF");
00275     }
00276     slotEnabled_PTU = true;
00277     slotEnabled_Marker = false;
00278     btnSkipFramePTUSearch->setEnabled(true);
00279     if (!ptuManager->nextPose())
00280     {
00281         ROS_INFO("PTU: No iteration possible.");
00282         btnStartStopPTUSearch->setText("Stop");
00283         disconnect(this, SLOT(ptu_moved(double, double)));
00284         disconnect(this, SLOT(markerFound(std::string, const Eigen::Matrix4d)));
00285         stopSignal = true;
00286         btnSkipFramePTUSearch->setEnabled(false);
00287     }
00288 }
00289 
00290 void PTUWindow::handleNewTransformationData(Transformation_Data &data)
00291 {
00292     //Create visualization markers
00293     colouredCameraFrame cCF;
00294     cCF.pose = data.PTU_Frame;
00295     cCF.color.r = 1.0;
00296     cCF.color.g = (data.pan - pan_min_angle) / (pan_max_angle - pan_min_angle);
00297     cCF.color.b = (data.tilt - tilt_min_angle) / (tilt_max_angle - tilt_min_angle);
00298     cCF.color.a = 1.0;
00299     colouredCameraFrames.push_back(cCF);
00300     //Store dataset
00301     transformationData.push_back(data);
00302 
00303     //Publish visualization
00304     markerPublisher->publishColouredCameraFrames(&colouredCameraFrames);
00305 }
00306 
00307 void PTUWindow::markerFound(std::string markerNumber, const Eigen::Matrix4d &transformation)
00308 {
00309     if (slotEnabled_Marker && !stopSignal)
00310     {
00311         if (markerNumber != "")
00312         {
00313             ROS_INFO_STREAM(markerNumber);
00314             bool markerLeft = (markerNumber == calibrationObject->marker_id_left);
00315             bool markerRight = (markerNumber == calibrationObject->marker_id_right);
00316             markerPublisher->publishARMarkers(markerLeft, markerRight, transformation_LaserScanner);
00317             if (markerRight ||  markerLeft)
00318             {
00319                 Eigen::Matrix4d markerBase;
00320                 // Constant transformation frame that is multiplied to the detected marker frame due to recent changes in the markers coordinate system
00321                 Eigen::Affine3d cameraCorrectionMatrix;
00322                 cameraCorrectionMatrix = Eigen::Affine3d (Eigen::AngleAxisd(M_PI/2.0, Eigen::Vector3d(1.0,0.0,0.0)));
00323 
00324                 Eigen::Affine3d markerFrame(transformation);
00325                 Eigen::Matrix4d markerToCamera = markerFrame.inverse().matrix();
00326                 markerToCamera = markerToCamera;
00327                 if (markerToCamera(1,3) < 0)
00328                 {
00329                     Markertype markertype;
00330                     if (markerRight)
00331                     {
00332                         if (this->useAveragedMarkerData)
00333                         {
00334                             tempMarkerRightPoses.push_back(transformation);
00335                         }
00336                         else
00337                         {
00338                             markerRightPoses.push_back(transformation);
00339                         }
00340                         markerBase = transformation_LaserScanner * calibrationObject->frame_marker_right*cameraCorrectionMatrix.matrix();
00341                         markertype = Markertype::RIGHT;
00342                         ROS_INFO_STREAM("Marker right found");
00343                     }
00344                     else
00345                     {
00346                         if (this->useAveragedMarkerData)
00347                         {
00348                             tempMarkerLeftPoses.push_back(transformation);
00349                         }
00350                         else
00351                         {
00352                             markerLeftPoses.push_back(transformation);
00353                         }
00354                         markerBase = transformation_LaserScanner * calibrationObject->frame_marker_left*cameraCorrectionMatrix.matrix();
00355                         markertype = Markertype::LEFT;
00356                         ROS_INFO_STREAM("Marker left found");
00357                     }
00358 
00359                     Eigen::Matrix4d scannerToPTU = markerBase * markerToCamera;
00360                     Eigen::Vector3d startPoint(markerBase(0,3), markerBase(1,3),markerBase(2,3));
00361                     Eigen::Vector3d endPoint(scannerToPTU(0,3), scannerToPTU(1,3),scannerToPTU(2,3));
00362                     if (markerPoseWithinBounds(transformation))
00363                     {
00364                         double pan = ptuManager->getPan();
00365                         double tilt = ptuManager->getTilt();
00366 
00367                         //Publish tf
00368                         this->newTransform_Camera(markerToCamera, markertype);
00369 
00370                         Transformation_Data dataSet;
00371                         dataSet.pan = pan;
00372                         dataSet.tilt = tilt;
00373                         dataSet.PTU_Frame = scannerToPTU;
00374                         dataSet.LaserScan_Frame = transformation_LaserScanner;
00375                         if (this->useAveragedMarkerData)
00376                         {
00377                             tempTransformationData.push_back(dataSet);
00378                         }
00379                         else
00380                         {
00381                             handleNewTransformationData(dataSet);
00382                         }
00383 
00384                         markerPublisher->publishCameraFramePointer(startPoint, endPoint, true);
00385 
00386                         //Publish difference to camera model
00387                         if (mTFlistener->waitForTransform("/calibration_center", "/camera_right_frame", ros::Time(), ros::Duration(4.0)))
00388                         {
00389                             //Assume that tf is alive and lookups will be successful
00390                             tf::StampedTransform cameraOffsetTF, cameraOffsetOldTF;
00391                             Eigen::Affine3d cameraOffsetEigen, cameraOffsetOldEigen;
00392                             mTFlistener->lookupTransform("/calibration_center", "/camera_right_frame", ros::Time(0), cameraOffsetTF);
00393                             mTFlistener->lookupTransform("/calibration_center", "/camera_right_frame_old", ros::Time(0), cameraOffsetOldTF);
00394                             tf::poseTFToEigen(cameraOffsetTF, cameraOffsetEigen);
00395                             tf::poseTFToEigen(cameraOffsetOldTF, cameraOffsetOldEigen);
00396                             cameraOffsetEigen = cameraOffsetEigen.inverse() * scannerToPTU;
00397                             cameraOffsetOldEigen = cameraOffsetOldEigen.inverse() * scannerToPTU;
00398                             ROS_INFO_STREAM("Offset between camera frames (new): " << cameraOffsetEigen(0,3) << ", "<< cameraOffsetEigen(1,3) << ", "<< cameraOffsetEigen(2,3) << " for (Pan: " << pan <<", Tilt: " << tilt << ")");
00399                             ROS_INFO_STREAM("Offset between camera frames (old): " << cameraOffsetOldEigen(0,3) << ", "<< cameraOffsetOldEigen(1,3) << ", "<< cameraOffsetOldEigen(2,3) << " for (Pan: " << pan <<", Tilt: " << tilt << ")");
00400                             PanTiltOffsetTuple offsetParameter = std::make_tuple (pan,tilt, cameraOffsetEigen.matrix(), cameraOffsetOldEigen.matrix());
00401                             cameraOffsetParameters.push_back(offsetParameter);
00402                         }
00403                         else
00404                         {
00405                             ROS_ERROR("TF lookup timed out. Is the transformation publisher running?");
00406                         }
00407                     }
00408                     else
00409                     {
00410                         markerPublisher->publishCameraFramePointer(startPoint, endPoint, false);
00411                         ROS_ERROR_STREAM("Marker " << markerNumber << " was out of bounds.");
00412                     }
00413                 }
00414                 else
00415                 {
00416                     ROS_ERROR_STREAM("Marker " << markerNumber << ": unexpected position.");
00417                 }
00418             }
00419             else
00420             {
00421                 ROS_ERROR_STREAM("Unexpected marker: " << markerNumber);
00422             }
00423         }
00424         else
00425         {
00426             stopMarkerCapturing();
00427         }
00428     }
00429     setUI_Elements();
00430 }
00431 
00432 void PTUWindow::stopMarkerCapturing()
00433 {
00434     slotEnabled_Marker = false;
00435     markerPublisher->publishARMarkers(false, false, transformation_LaserScanner);
00436     markerManager->terminate();
00437 
00438     if (this->useAveragedMarkerData)
00439     {
00440         calculateAllAverageDataFrames();
00441     }
00442 
00443     for(unsigned int i = 0; i < markerRightPoses.size(); i++)
00444     {
00445         for(unsigned int j = 0; j < markerLeftPoses.size(); j++)
00446         {
00447             Eigen::Affine3d markerLeftReferencePose(markerLeftPoses.at(j));
00448             Eigen::Affine3d markerRightReferencePose(markerRightPoses.at(i));
00449             markerRightReferencePose = markerLeftReferencePose.inverse() * markerRightReferencePose;
00450             relativeMarkerPoses.push_back(markerRightReferencePose.matrix());
00451         }
00452     }
00453     markerLeftPoses.clear();
00454     markerRightPoses.clear();
00455     btnSkipFramePTUSearch->setEnabled(false);
00456     if (ptuManager->nextPose())
00457     {
00458         slotEnabled_PTU = true;
00459         ROS_INFO("PTU: Moving to next pose..");
00460     }
00461     else
00462     {
00463         ROS_INFO("PTU: Finished");
00464         btnStartStopPTUSearch->setText("Start");
00465         stopSignal = true;
00466         disconnect(this, SLOT(ptu_moved(double, double)));
00467         disconnect(this, SLOT(markerFound(std::string, Eigen::Matrix4d)));
00468     }
00469 }
00470 
00471 void PTUWindow::calculateAllAverageDataFrames()
00472 {
00473     //Calculate average camera frame
00474     if (tempTransformationData.size() > 0)
00475     {
00476         Transformation_Data dataSet;
00477         dataSet.pan = tempTransformationData.at(0).pan;
00478         dataSet.tilt = tempTransformationData.at(0).tilt;
00479         std::vector<Eigen::Matrix4d , Eigen::aligned_allocator<Eigen::Matrix4d > > tempFrames;
00480         for (unsigned int i = 0; i < tempTransformationData.size(); i++)
00481         {
00482             tempFrames.push_back(tempTransformationData.at(i).PTU_Frame);
00483         }
00484         dataSet.PTU_Frame = calculateAverageDataFrame(tempFrames);
00485         handleNewTransformationData(dataSet);
00486     }
00487     //Calculate marker frames of left and right marker
00488     if (this->tempMarkerLeftPoses.size() > 0)
00489     {
00490         Eigen::Matrix4d averageLeftFrame = calculateAverageDataFrame(this->tempMarkerLeftPoses);
00491         markerLeftPoses.push_back(averageLeftFrame);
00492     }
00493     if (this->tempMarkerRightPoses.size() > 0)
00494     {
00495         Eigen::Matrix4d averageRightFrame = calculateAverageDataFrame(this->tempMarkerRightPoses);
00496         markerRightPoses.push_back(averageRightFrame);
00497     }
00498     tempTransformationData.clear();
00499     tempMarkerLeftPoses.clear();
00500     tempMarkerRightPoses.clear();
00501 }
00502 
00503 Eigen::Matrix4d PTUWindow::calculateAverageDataFrame(std::vector<Eigen::Matrix4d , Eigen::aligned_allocator<Eigen::Matrix4d > > frames)
00504 {
00505     Eigen::Affine3d averageFrame;
00506     if (frames.size() > 0)
00507     {
00508         Eigen::Vector3d averageTranslation(frames.at(0)(0,3), frames.at(0)(1,3),frames.at(0)(2,3));
00509         Eigen::Affine3d transformation(frames.at(0));
00510         Eigen::Quaterniond averageRotation((transformation.rotation().matrix()));
00511 
00512         for (unsigned int i = 1; i < frames.size(); i++)
00513         {
00514             Eigen::Affine3d tempTransformation(frames.at(i));
00515             Eigen::Quaterniond tempRotation((tempTransformation.rotation().matrix()));
00516             Eigen::Vector3d tempTranslation(tempTransformation(0,3), tempTransformation(1,3), tempTransformation(2,3));
00517             averageTranslation = averageTranslation + tempTranslation;
00518             averageRotation = averageRotation.slerp((double)i/(i+1.0), tempRotation);
00519         }
00520         averageTranslation = averageTranslation * 1.0/(double)frames.size();
00521 
00522         averageFrame = Eigen::Affine3d(Eigen::Translation3d(averageTranslation));
00523         averageFrame = averageFrame * averageRotation;
00524     }
00525     return averageFrame.matrix();
00526 }
00527 
00528 bool PTUWindow::markerPoseWithinBounds(const Eigen::Matrix4d& transform)
00529 {
00530     Eigen::Vector3d vec3(transform(0,3), transform(1,3), transform(2,3));
00531 
00532     double length = vec3.norm();
00533     if (length < marker_min_distance)
00534     {
00535         ROS_ERROR_STREAM("Length (" << length << ") was smaller than min distance");
00536         return false;
00537     }
00538     if (length > marker_max_distance)
00539     {
00540         ROS_ERROR_STREAM("Length (" << length << ") was greater than max distance");
00541         return false;
00542     }
00543     if (vec3(1) > 0.0)
00544     {
00545         //ROS_ERROR_STREAM("Vector is going upwards");
00546         //return false;
00547     }
00548     return true;
00549 }
00550 
00551 void PTUWindow::ptu_moved(double pan, double tilt)
00552 {
00553     if (slotEnabled_PTU && !stopSignal)
00554     {
00555         slotEnabled_PTU = false;
00556         ROS_DEBUG_STREAM("PTU: Moved to " << pan << ", " << tilt);
00557         markerManager->start();
00558         btnSkipFramePTUSearch->setEnabled(true);
00559         slotEnabled_Marker = true;
00560     }
00561 }


asr_mild_calibration_tool
Author(s): Aumann Florian, Heller Florian, Meißner Pascal
autogenerated on Thu Jun 6 2019 21:22:44