transformation_publisher.cpp
Go to the documentation of this file.
1 
19 #ifndef Q_MOC_RUN
20 #include <tf/transform_datatypes.h>
21 #include <tf_conversions/tf_eigen.h>
22 #endif
23 
25 {
26  joint_pub = nh.advertise<sensor_msgs::JointState>("calibration_transforms", 1);
27  geometry_msgs::TransformStamped topToBase;
28  geometry_msgs::TransformStamped topToMarkerLeft;
29  geometry_msgs::TransformStamped topToMarkerRight;
30 
31  topToBase.header.frame_id = "object_top";
32  topToBase.child_frame_id = "object_base";
33  topToMarkerLeft.header.frame_id = "object_top";
34  topToMarkerLeft.child_frame_id = "marker_left";
35  topToMarkerRight.header.frame_id = "object_top";
36  topToMarkerRight.child_frame_id = "marker_right";
37  mapToTop.header.frame_id = "calibration_center";
38  mapToTop.child_frame_id = "object_top";
39  topToScanFrame.header.frame_id = "object_top";
40  topToScanFrame.child_frame_id = "object_scan_frame";
41  markerLeftToCamera.header.frame_id = "marker_left";
42  markerLeftToCamera.child_frame_id = "camera_frame";
43  markerRightToCamera.header.frame_id = "marker_right";
44  markerRightToCamera.child_frame_id = "camera_frame";
45 
46  topToBase.transform.translation.z = -object->side_b;
47  topToBase.transform.rotation = tf::createQuaternionMsgFromYaw(0.0);
48  Eigen::Affine3d eigenTransform = Eigen::Affine3d(object->frame_marker_left);
49  tf::Transform tfTransform;
50  geometry_msgs::Transform gmTransform;
51  tf::transformEigenToTF(eigenTransform, tfTransform);
52  tf::transformTFToMsg(tfTransform, gmTransform);
53  topToMarkerLeft.transform = gmTransform;
54  eigenTransform = Eigen::Affine3d(object->frame_marker_right);
55  tf::transformEigenToTF(eigenTransform, tfTransform);
56  tf::transformTFToMsg(tfTransform, gmTransform);
57  topToMarkerRight.transform = gmTransform;
58  mapToTop.transform.rotation = tf::createQuaternionMsgFromYaw(0.0);
59  topToScanFrame.transform.rotation = tf::createQuaternionMsgFromYaw(0.0);
60 
61  staticTransforms.push_back(topToBase);
62  staticTransforms.push_back(topToMarkerLeft);
63  staticTransforms.push_back(topToMarkerRight);
64 }
65 
66 void Transformation_Publisher::newTransform_Laserscan(const Eigen::Matrix4d& transform, double distanceToTop)
67 {
68  Eigen::Affine3d eigenTransform = Eigen::Affine3d(transform);
69  tf::Transform tfTransform;
70  geometry_msgs::Transform gmTransform;
71  tf::transformEigenToTF(eigenTransform, tfTransform);
72  tf::transformTFToMsg(tfTransform, gmTransform);
73  mapToTop.transform = gmTransform;
74 
75  topToScanFrame.transform.translation.z = -distanceToTop;
76  topToScanFrame.transform.rotation = tf::createQuaternionMsgFromYaw(0.0);
77 }
78 
79 void Transformation_Publisher::newTransform_Camera(const Eigen::Matrix4d& transform, Markertype markertype)
80 {
81  Eigen::Affine3d eigenTransform = Eigen::Affine3d(transform);
82  tf::Transform tfTransform;
83  geometry_msgs::Transform gmTransform;
84  tf::transformEigenToTF(eigenTransform, tfTransform);
85  tf::transformTFToMsg(tfTransform, gmTransform);
86 
87  if (markertype == Markertype::LEFT)
88  {
89  ROS_INFO("Got new camera frame from left marker.");
90  markerLeftToCamera.transform = gmTransform;
91  }
92  else if (markertype == Markertype::RIGHT)
93  {
94  ROS_INFO("Got new camera frame from right marker.");
95  markerRightToCamera.transform = gmTransform;
96  }
97  currentMarkertype = markertype;
98 }
99 
101 {
102  ros::Rate loop_rate(30);
103  while (ros::ok())
104  {
105  //Publish static transforms
106  for (unsigned int i = 0; i < staticTransforms.size(); i++)
107  {
108  staticTransforms[i].header.stamp = ros::Time::now();
109  broadcaster.sendTransform(staticTransforms[i]);
110  }
111 
112  mapToTop.header.stamp = ros::Time::now();
113  broadcaster.sendTransform(mapToTop);
114 
115  topToScanFrame.header.stamp = ros::Time::now();
116  broadcaster.sendTransform(topToScanFrame);
117 
118  try
119  {
121  {
122  markerLeftToCamera.header.stamp = ros::Time::now();
123  broadcaster.sendTransform(markerLeftToCamera);
124  }
126  {
127  markerRightToCamera.header.stamp = ros::Time::now();
128  broadcaster.sendTransform(markerRightToCamera);
129  }
130  }
131  catch (...)
132  {
133  ROS_ERROR("Something went wrong in the tf broadcaster");
134  }
135 
136  loop_rate.sleep();
137  }
138 }
139 
140 geometry_msgs::Transform Transformation_Publisher::matrixToTransform(const Eigen::Matrix4d& matrix)
141 {
142  Eigen::Affine3d eigenTransform = Eigen::Affine3d(matrix);
143  tf::Transform tfTransform;
144  geometry_msgs::Transform gmTransform;
145  tf::transformEigenToTF(eigenTransform, tfTransform);
146  tf::transformTFToMsg(tfTransform, gmTransform);
147  return gmTransform;
148 }
geometry_msgs::TransformStamped markerRightToCamera
Transformation_Publisher(boost::shared_ptr< Calibration_Object > object)
void newTransform_Camera(const Eigen::Matrix4d &transform, Markertype markertype)
void newTransform_Laserscan(const Eigen::Matrix4d &transform, double distanceToTop)
#define ROS_INFO(...)
geometry_msgs::TransformStamped markerLeftToCamera
ROSCPP_DECL bool ok()
tf::TransformBroadcaster broadcaster
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
bool sleep()
geometry_msgs::TransformStamped topToScanFrame
geometry_msgs::Transform matrixToTransform(const Eigen::Matrix4d &matrix)
std::vector< geometry_msgs::TransformStamped > staticTransforms
static Time now()
geometry_msgs::TransformStamped mapToTop
#define ROS_ERROR(...)


asr_mild_calibration_tool
Author(s): Aumann Florian, Heller Florian, Meißner Pascal
autogenerated on Mon Dec 2 2019 03:11:43