transformation_publisher.cpp
Go to the documentation of this file.
00001 
00018 #include <Transformation/transformation_publisher.h>
00019 #ifndef Q_MOC_RUN
00020 #include <tf/transform_datatypes.h>
00021 #include <tf_conversions/tf_eigen.h>
00022 #endif
00023 
00024 Transformation_Publisher::Transformation_Publisher(boost::shared_ptr<Calibration_Object> object)
00025 {
00026     joint_pub = nh.advertise<sensor_msgs::JointState>("calibration_transforms", 1);
00027     geometry_msgs::TransformStamped topToBase;
00028     geometry_msgs::TransformStamped topToMarkerLeft;
00029     geometry_msgs::TransformStamped topToMarkerRight;
00030 
00031     topToBase.header.frame_id = "object_top";
00032     topToBase.child_frame_id = "object_base";
00033     topToMarkerLeft.header.frame_id = "object_top";
00034     topToMarkerLeft.child_frame_id = "marker_left";
00035     topToMarkerRight.header.frame_id = "object_top";
00036     topToMarkerRight.child_frame_id = "marker_right";
00037     mapToTop.header.frame_id = "calibration_center";
00038     mapToTop.child_frame_id = "object_top";
00039     topToScanFrame.header.frame_id = "object_top";
00040     topToScanFrame.child_frame_id = "object_scan_frame";
00041     markerLeftToCamera.header.frame_id = "marker_left";
00042     markerLeftToCamera.child_frame_id = "camera_frame";
00043     markerRightToCamera.header.frame_id = "marker_right";
00044     markerRightToCamera.child_frame_id = "camera_frame";
00045 
00046     topToBase.transform.translation.z = -object->side_b;
00047     topToBase.transform.rotation =  tf::createQuaternionMsgFromYaw(0.0);
00048     Eigen::Affine3d eigenTransform = Eigen::Affine3d(object->frame_marker_left);
00049     tf::Transform tfTransform;
00050     geometry_msgs::Transform gmTransform;
00051     tf::transformEigenToTF(eigenTransform, tfTransform);
00052     tf::transformTFToMsg(tfTransform, gmTransform);
00053     topToMarkerLeft.transform = gmTransform;
00054     eigenTransform = Eigen::Affine3d(object->frame_marker_right);
00055     tf::transformEigenToTF(eigenTransform, tfTransform);
00056     tf::transformTFToMsg(tfTransform, gmTransform);
00057     topToMarkerRight.transform = gmTransform;
00058     mapToTop.transform.rotation =  tf::createQuaternionMsgFromYaw(0.0);
00059     topToScanFrame.transform.rotation =  tf::createQuaternionMsgFromYaw(0.0);
00060 
00061     staticTransforms.push_back(topToBase);
00062     staticTransforms.push_back(topToMarkerLeft);
00063     staticTransforms.push_back(topToMarkerRight);
00064 }
00065 
00066 void Transformation_Publisher::newTransform_Laserscan(const Eigen::Matrix4d& transform, double distanceToTop)
00067 {
00068     Eigen::Affine3d eigenTransform = Eigen::Affine3d(transform);
00069     tf::Transform tfTransform;
00070     geometry_msgs::Transform gmTransform;
00071     tf::transformEigenToTF(eigenTransform, tfTransform);
00072     tf::transformTFToMsg(tfTransform, gmTransform);
00073     mapToTop.transform = gmTransform;
00074 
00075     topToScanFrame.transform.translation.z = -distanceToTop;
00076     topToScanFrame.transform.rotation =  tf::createQuaternionMsgFromYaw(0.0);
00077 }
00078 
00079 void Transformation_Publisher::newTransform_Camera(const Eigen::Matrix4d& transform, Markertype markertype)
00080 {
00081     Eigen::Affine3d eigenTransform = Eigen::Affine3d(transform);
00082     tf::Transform tfTransform;
00083     geometry_msgs::Transform gmTransform;
00084     tf::transformEigenToTF(eigenTransform, tfTransform);
00085     tf::transformTFToMsg(tfTransform, gmTransform);
00086 
00087     if (markertype == Markertype::LEFT)
00088     {
00089         ROS_INFO("Got new camera frame from left marker.");
00090         markerLeftToCamera.transform = gmTransform;
00091     }
00092     else if (markertype == Markertype::RIGHT)
00093     {
00094         ROS_INFO("Got new camera frame from right marker.");
00095         markerRightToCamera.transform = gmTransform;
00096     }
00097     currentMarkertype = markertype;
00098 }
00099 
00100 void Transformation_Publisher::run()
00101 {
00102     ros::Rate loop_rate(30);
00103     while (ros::ok())
00104     {
00105         //Publish static transforms
00106         for (unsigned int i = 0; i < staticTransforms.size(); i++)
00107         {
00108             staticTransforms[i].header.stamp = ros::Time::now();
00109             broadcaster.sendTransform(staticTransforms[i]);
00110         }
00111 
00112         mapToTop.header.stamp = ros::Time::now();
00113         broadcaster.sendTransform(mapToTop);
00114 
00115         topToScanFrame.header.stamp = ros::Time::now();
00116         broadcaster.sendTransform(topToScanFrame);
00117 
00118         try
00119         {
00120             if (currentMarkertype == Markertype::LEFT)
00121             {
00122                 markerLeftToCamera.header.stamp = ros::Time::now();
00123                 broadcaster.sendTransform(markerLeftToCamera);
00124             }
00125             else if (currentMarkertype == Markertype::RIGHT)
00126             {
00127                 markerRightToCamera.header.stamp = ros::Time::now();
00128                 broadcaster.sendTransform(markerRightToCamera);
00129             }
00130         }
00131         catch (...)
00132         {
00133             ROS_ERROR("Something went wrong in the tf broadcaster");
00134         }
00135 
00136         loop_rate.sleep();
00137     }
00138 }
00139 
00140 geometry_msgs::Transform Transformation_Publisher::matrixToTransform(const Eigen::Matrix4d& matrix)
00141 {
00142     Eigen::Affine3d eigenTransform = Eigen::Affine3d(matrix);
00143     tf::Transform tfTransform;
00144     geometry_msgs::Transform gmTransform;
00145     tf::transformEigenToTF(eigenTransform, tfTransform);
00146     tf::transformTFToMsg(tfTransform, gmTransform);
00147     return gmTransform;
00148 }


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