89 # if __ROS_VERSION > 0
94 std::string scanner_type;
100 rosGetParam(nh,
"publish_frame_id", tf_lidar_frame_id);
108 rosGetParam(nh,
"tf_base_frame_id", tf_base_frame_id);
110 rosGetParam(nh,
"tf_base_lidar_xyz_rpy", tf_base_lidar_xyz_rpy);
112 rosGetParam(nh,
"tf_publish_rate", tf_publish_rate);
115 if(tf_base_lidar_pose_vec.size() != 6)
117 ROS_ERROR_STREAM(
"## ERROR SickTransformPublisher(): Can't parse config string \"" << tf_base_lidar_xyz_rpy <<
"\", use 6D pose \"x,y,z,roll,pitch,yaw\" in [m] resp. [rad], using TF messages with default pose (0,0,0,0,0,0)");
118 tf_base_lidar_pose_vec = std::vector<float>(6, 0);
120 ROS_INFO_STREAM(
"SickTransformPublisher: broadcasting TF messages parent_frame_id=\"" << tf_base_frame_id <<
"\", child_frame_id=\"" << tf_lidar_frame_id
121 <<
"\", (x,y,z,roll,pitch,yaw)=(" << std::fixed << std::setprecision(1) << tf_base_lidar_pose_vec[0] <<
"," << tf_base_lidar_pose_vec[1] <<
"," << tf_base_lidar_pose_vec[2]
122 <<
"," << (tf_base_lidar_pose_vec[3]*180.0/M_PI) <<
"," << (tf_base_lidar_pose_vec[4]*180.0/M_PI) <<
"," << (tf_base_lidar_pose_vec[5]*180.0/M_PI)
123 <<
"), rate=" << tf_publish_rate);
130 # if __ROS_VERSION > 0
131 if(tf_publish_rate > 1.0e-6)
133 tf_publish_thread_running =
true;
134 tf_publish_thread =
new std::thread(&sick_scan_xd::SickTransformPublisher::runTFpublishThreadCb,
this);
141 # if __ROS_VERSION > 0
142 tf_publish_thread_running =
false;
143 if (tf_publish_thread && tf_publish_thread->joinable())
144 tf_publish_thread->join();
145 if (tf_publish_thread)
146 delete tf_publish_thread;
147 tf_publish_thread = 0;
151 # if __ROS_VERSION > 0
152 void SickTransformPublisher::runTFpublishThreadCb()
154 assert(tf_publish_rate > 0);
155 assert(tf_base_lidar_pose_vec.size() == 6);
156 int publish_sleep_millisec = int(1000.0 / tf_publish_rate);
158 tf_message.header.frame_id = tf_base_frame_id;
159 tf_message.child_frame_id = tf_lidar_frame_id;
160 tf_message.transform.translation.x = tf_base_lidar_pose_vec[0];
161 tf_message.transform.translation.y = tf_base_lidar_pose_vec[1];
162 tf_message.transform.translation.z = tf_base_lidar_pose_vec[2];
164 q.
setRPY(tf_base_lidar_pose_vec[3], tf_base_lidar_pose_vec[4], tf_base_lidar_pose_vec[5]);
165 tf_message.transform.rotation.x = q.x();
166 tf_message.transform.rotation.y = q.y();
167 tf_message.transform.rotation.z = q.z();
168 tf_message.transform.rotation.w = q.w();
169 # if __ROS_VERSION == 1
171 # elif __ROS_VERSION == 2
174 while (
rosOk() && tf_publish_thread_running)
178 std::this_thread::sleep_for(std::chrono::milliseconds(publish_sleep_millisec));
180 tf_publish_thread_running =
false;