5 #include <geometry_msgs/TransformStamped.h>
13 #include <tf2_ros/transform_listener.h>
56 ROS_ERROR_NAMED(
"image_buffer",
"[IMAGE_BUFFER] No RGBD client");
62 ros::Time t_start = ros::Time::now();
63 ros::Time t_end = t_start + ros::Duration(timeout_sec);
66 ROS_DEBUG_STREAM_NAMED(
"iamge_buffer",
"[IMAGE_BUFFER](waitForRecentImage) defaulting to 10Hz instead of '" << check_rate <<
"'");
69 ros::Rate r(check_rate);
80 else if (ros::Time::now() > t_end)
82 ROS_ERROR_NAMED(
"image_buffer",
"[IMAGE_BUFFER] timeout waiting for rgbd image");
93 if (!
tf_buffer_.canTransform(
root_frame_, rgbd_image->getFrameId(), ros::Time(rgbd_image->getTimestamp())))
94 if (!
tf_buffer_.canTransform(
root_frame_, rgbd_image->getFrameId(), ros::Time(rgbd_image->getTimestamp()), t_end - ros::Time::now()))
96 ROS_ERROR_THROTTLE_NAMED(5,
"image_buffer",
"[IMAGE_BUFFER] timeout waiting for tf");
105 geometry_msgs::TransformStamped t_sensor_pose =
tf_buffer_.lookupTransform(
root_frame_, rgbd_image->getFrameId(), ros::Time(rgbd_image->getTimestamp()));
108 catch(tf2::TransformException& ex)
110 ROS_ERROR_NAMED(
"image_buffer",
"[IMAGE_BUFFER] Could not get sensor pose: %s", ex.what());
115 sensor_pose.
R = sensor_pose.
R *
geo::Matrix3(1, 0, 0, 0, -1, 0, 0, 0, -1);
126 if (timeout_tries <= 0)
128 ROS_DEBUG_STREAM_NAMED(
"iamge_buffer",
"[IMAGE_BUFFER](waitForRecentImage) defaulting to 25 tries instead of '" << timeout_tries <<
"'");
131 double freq = timeout_sec > 0 ? timeout_tries/timeout_sec : 1000;
143 ROS_DEBUG(
"[IMAGE_BUFFER] No new image");
161 ROS_ERROR_NAMED(
"image_buffer",
"[IMAGE_BUFFER] No RGBD client");
173 ROS_DEBUG_STREAM_NAMED(
"image_buffer",
"[IMAGE_BUFFER] New image from the RGBD client with timestamp: " <<
std::fixed <<
std::setprecision(12) << new_image->getTimestamp());
177 ROS_DEBUG_NAMED(
"image_buffer",
"[IMAGE_BUFFER] No new image from the RGBD client");
188 geometry_msgs::TransformStamped t_sensor_pose =
tf_buffer_.lookupTransform(
root_frame_, rgbd_image->getFrameId(), ros::Time(rgbd_image->getTimestamp()));
191 catch (tf2::ExtrapolationException& ex)
197 geometry_msgs::TransformStamped latest_sensor_pose =
tf_buffer_.lookupTransform(
root_frame_, rgbd_image->getFrameId(), ros::Time(0));
199 if ( latest_sensor_pose.header.stamp > ros::Time(rgbd_image->getTimestamp()) )
202 ROS_DEBUG_STREAM_NAMED(
"image_buffer",
"[IMAGE_BUFFER] Image too old to look-up tf. Deleting all images older than timestamp: " <<
std::fixed
203 << ros::Time(rgbd_image->getTimestamp()));
211 ROS_DEBUG_STREAM_DELAYED_THROTTLE_NAMED(10,
"image_buffer",
"[IMAGE_BUFFER] Image too new to look-up tf: image timestamp: " <<
std::fixed << ros::Time(rgbd_image->getTimestamp()) <<
", what: " << ex.what());
215 catch (tf2::TransformException& ex)
217 ROS_ERROR_DELAYED_THROTTLE_NAMED(10,
"image_buffer",
"[IMAGE_BUFFER] Could not get latest sensor pose (probably because tf is still initializing): %s", ex.what());
218 ROS_DEBUG_NAMED(
"image_buffer",
"[IMAGE_BUFFER] Could not get latest sensor pose (probably because tf is still initializing): %s", ex.what());
222 catch (tf2::TransformException& ex)
224 ROS_ERROR_DELAYED_THROTTLE_NAMED(10,
"image_buffer",
"[IMAGE_BUFFER] Could not get sensor pose: %s", ex.what());
225 ROS_WARN_NAMED(
"image_buffer",
"[IMAGE_BUFFER] Could not get sensor pose: %s", ex.what());
230 sensor_pose.
R = sensor_pose.
R *
geo::Matrix3(1, 0, 0, 0, -1, 0, 0, 0, -1);
252 ros::Rate r(frequency);
256 ROS_ERROR_DELAYED_THROTTLE_NAMED(5,
"image_buffer",
"[IMAGE_BUFFER] Could not get a pose for any image in the buffer");