21 #include <QFileDialog> 30 this->
init(myMarkerPublisher,
calibrationObject, myTransformationPublisher, Eigen::Matrix4d::Identity());
36 this->
init(markerPublisher, calibrationObject, transformationPublisher, calObjTransformation);
41 this->setWindowTitle(
"PTU Calibration");
45 int pan_step_count, tilt_step_count;
47 mNodeHandle.
getParam(
"pan_min_angle", pan_min_angle);
48 mNodeHandle.
getParam(
"pan_max_angle", pan_max_angle);
49 mNodeHandle.
getParam(
"tilt_min_angle", tilt_min_angle);
50 mNodeHandle.
getParam(
"tilt_max_angle", tilt_max_angle);
51 mNodeHandle.
getParam(
"pan_step_count", pan_step_count);
52 mNodeHandle.
getParam(
"tilt_step_count", tilt_step_count);
53 mNodeHandle.
getParam(
"marker_recognizer_timeout", marker_recognizer_timeout);
54 mNodeHandle.
getParam(
"marker_recognizer_early_abort_timeout", marker_recognizer_early_abort_timeout);
55 mNodeHandle.
getParam(
"marker_min_distance", marker_min_distance);
56 mNodeHandle.
getParam(
"marker_max_distance", marker_max_distance);
57 mNodeHandle.
getParam(
"useAveragedMarkerData", useAveragedMarkerData);
65 ptuManager =
new PTU_Manager(pan_min_angle, pan_max_angle, tilt_min_angle, tilt_max_angle, pan_step_count, tilt_step_count);
148 QString text =
"Camera datasets found: ";
152 text =
"Relative marker frames found: ";
157 double standardDeviation = 0.0;
161 standardDeviation += pow(averageTranslation.norm(), 2.0);
164 text +=
", standarddeviation: ";
165 text += QString::number(standardDeviation);
173 cameraLeft->resize(this->width()/2-60,this->height()-150);
175 cameraRight->resize(this->width()/2-60,this->height()-150);
184 QDialog::resizeEvent(event);
199 ROS_INFO(
"PTU: Starting iteration..");
206 disconnect(
this, SLOT(
ptu_moved(
double,
double)));
207 disconnect(
this, SLOT(
markerFound(std::string,
const Eigen::Matrix4d)));
217 QString fileName = QFileDialog::getSaveFileName(
this,
"Save file",
"CameraOffset.off", tr(
"Offsetfile (*.off)"));
218 if (fileName.length() > 0)
232 QString fileName = QFileDialog::getSaveFileName(
this,
"Save file",
"CalibrationData.data", tr(
"Calibrationfile (*.data)"));
233 if (fileName.length() > 0)
246 QString fileName = QFileDialog::getSaveFileName(
this,
"Save file",
"CalibrationData.data", tr(
"Calibrationfile (*.data)"));
247 if (fileName.length() > 0)
267 ROS_INFO(
"PTU: Starting iteration..");
274 ROS_INFO(
"Averaging PTU frame OFF");
281 ROS_INFO(
"PTU: No iteration possible.");
283 disconnect(
this, SLOT(
ptu_moved(
double,
double)));
284 disconnect(
this, SLOT(
markerFound(std::string,
const Eigen::Matrix4d)));
311 if (markerNumber !=
"")
317 if (markerRight || markerLeft)
319 Eigen::Matrix4d markerBase;
321 Eigen::Affine3d cameraCorrectionMatrix;
322 cameraCorrectionMatrix = Eigen::Affine3d (Eigen::AngleAxisd(M_PI/2.0, Eigen::Vector3d(1.0,0.0,0.0)));
324 Eigen::Affine3d markerFrame(transformation);
325 Eigen::Matrix4d markerToCamera = markerFrame.inverse().matrix();
326 markerToCamera = markerToCamera;
327 if (markerToCamera(1,3) < 0)
359 Eigen::Matrix4d scannerToPTU = markerBase * markerToCamera;
360 Eigen::Vector3d startPoint(markerBase(0,3), markerBase(1,3),markerBase(2,3));
361 Eigen::Vector3d endPoint(scannerToPTU(0,3), scannerToPTU(1,3),scannerToPTU(2,3));
384 markerPublisher->publishCameraFramePointer(startPoint, endPoint,
true);
390 tf::StampedTransform cameraOffsetTF, cameraOffsetOldTF;
391 Eigen::Affine3d cameraOffsetEigen, cameraOffsetOldEigen;
392 mTFlistener->lookupTransform(
"/calibration_center",
"/camera_right_frame",
ros::Time(0), cameraOffsetTF);
393 mTFlistener->lookupTransform(
"/calibration_center",
"/camera_right_frame_old",
ros::Time(0), cameraOffsetOldTF);
394 tf::poseTFToEigen(cameraOffsetTF, cameraOffsetEigen);
395 tf::poseTFToEigen(cameraOffsetOldTF, cameraOffsetOldEigen);
396 cameraOffsetEigen = cameraOffsetEigen.inverse() * scannerToPTU;
397 cameraOffsetOldEigen = cameraOffsetOldEigen.inverse() * scannerToPTU;
398 ROS_INFO_STREAM(
"Offset between camera frames (new): " << cameraOffsetEigen(0,3) <<
", "<< cameraOffsetEigen(1,3) <<
", "<< cameraOffsetEigen(2,3) <<
" for (Pan: " << pan <<
", Tilt: " << tilt <<
")");
399 ROS_INFO_STREAM(
"Offset between camera frames (old): " << cameraOffsetOldEigen(0,3) <<
", "<< cameraOffsetOldEigen(1,3) <<
", "<< cameraOffsetOldEigen(2,3) <<
" for (Pan: " << pan <<
", Tilt: " << tilt <<
")");
400 PanTiltOffsetTuple offsetParameter = std::make_tuple (pan,tilt, cameraOffsetEigen.matrix(), cameraOffsetOldEigen.matrix());
405 ROS_ERROR(
"TF lookup timed out. Is the transformation publisher running?");
410 markerPublisher->publishCameraFramePointer(startPoint, endPoint,
false);
449 markerRightReferencePose = markerLeftReferencePose.inverse() * markerRightReferencePose;
459 ROS_INFO(
"PTU: Moving to next pose..");
466 disconnect(
this, SLOT(
ptu_moved(
double,
double)));
467 disconnect(
this, SLOT(
markerFound(std::string, Eigen::Matrix4d)));
479 std::vector<Eigen::Matrix4d , Eigen::aligned_allocator<Eigen::Matrix4d > > tempFrames;
505 Eigen::Affine3d averageFrame;
506 if (frames.size() > 0)
508 Eigen::Vector3d averageTranslation(frames.at(0)(0,3), frames.at(0)(1,3),frames.at(0)(2,3));
509 Eigen::Affine3d transformation(frames.at(0));
510 Eigen::Quaterniond averageRotation((transformation.rotation().matrix()));
512 for (
unsigned int i = 1; i < frames.size(); i++)
514 Eigen::Affine3d tempTransformation(frames.at(i));
515 Eigen::Quaterniond tempRotation((tempTransformation.rotation().matrix()));
516 Eigen::Vector3d tempTranslation(tempTransformation(0,3), tempTransformation(1,3), tempTransformation(2,3));
517 averageTranslation = averageTranslation + tempTranslation;
518 averageRotation = averageRotation.slerp((
double)i/(i+1.0), tempRotation);
520 averageTranslation = averageTranslation * 1.0/(double)frames.size();
522 averageFrame = Eigen::Affine3d(Eigen::Translation3d(averageTranslation));
523 averageFrame = averageFrame * averageRotation;
525 return averageFrame.matrix();
530 Eigen::Vector3d vec3(transform(0,3), transform(1,3), transform(2,3));
532 double length = vec3.norm();
535 ROS_ERROR_STREAM(
"Length (" << length <<
") was smaller than min distance");
540 ROS_ERROR_STREAM(
"Length (" << length <<
") was greater than max distance");
std::vector< Eigen::Matrix4d, Eigen::aligned_allocator< Eigen::Matrix4d > > markerRightPoses
std::vector< Eigen::Matrix4d, Eigen::aligned_allocator< Eigen::Matrix4d > > tempMarkerLeftPoses
CameraWidget * cameraRight
std::vector< Eigen::Matrix4d, Eigen::aligned_allocator< Eigen::Matrix4d > > markerLeftPoses
QPushButton * btnExportCameraOffset
std::vector< Transformation_Data > tempTransformationData
double marker_max_distance
double marker_min_distance
bool markerPoseWithinBounds(const Eigen::Matrix4d &transform)
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Eigen::Matrix4d pose
void resizeEvent(QResizeEvent *event)
void btnSkipFramePTUSearch_clicked()
ROSCPP_DECL const std::string & getName()
boost::shared_ptr< MarkerPublisher > markerPublisher
std::vector< colouredCameraFrame, Eigen::aligned_allocator< colouredCameraFrame > > colouredCameraFrames
std_msgs::ColorRGBA color
boost::shared_ptr< Transformation_Publisher > transformationPublisher
void stopMarkerCapturing()
tf::TransformListener * mTFlistener
void btnExportRelativeMarkerPoses_clicked()
QLabel * lblRelativeMarkerFrameCount
Marker_Manager * markerManager
PTUWindow(QWidget *parent=0)
QPushButton * btnSkipFramePTUSearch
void markerFound(std::string markerNumber, const Eigen::Matrix4d &transformation)
std::vector< Eigen::Matrix4d, Eigen::aligned_allocator< Eigen::Matrix4d > > relativeMarkerPoses
PanTiltOffsetTupleList cameraOffsetParameters
void newTransform_Camera(const Eigen::Matrix4d &transform, Markertype markertype)
QPushButton * btnExportCameraPoses
void btnExportCameraPoses_clicked()
void handleNewTransformationData(Transformation_Data &data)
std::vector< Transformation_Data > transformationData
CameraWidget * cameraLeft
Eigen::Matrix4d calculateAverageDataFrame(std::vector< Eigen::Matrix4d, Eigen::aligned_allocator< Eigen::Matrix4d > > frames)
std::vector< Eigen::Matrix4d, Eigen::aligned_allocator< Eigen::Matrix4d > > tempMarkerRightPoses
void btnStartStopPTUSearch_clicked()
void ptu_moved(double pan, double tilt)
#define ROS_DEBUG_STREAM(args)
QPushButton * btnExportRelativeMarkerPoses
QPushButton * btnStartStopPTUSearch
QLabel * lblCameraFrameCount
void init(boost::shared_ptr< MarkerPublisher > markerManager, boost::shared_ptr< Calibration_Object > calibrationObject, boost::shared_ptr< Transformation_Publisher > transformationPublisher, const Eigen::Matrix4d calObjTransformation)
#define ROS_INFO_STREAM(args)
boost::shared_ptr< Calibration_Object > calibrationObject
void calculateAllAverageDataFrames()
bool getParam(const std::string &key, std::string &s) const
bool useAveragedMarkerData
void btnExportCameraOffset_clicked()
Eigen::Matrix4d transformation_LaserScanner
#define ROS_ERROR_STREAM(args)