Skip to content

Commit 96a409b

Browse files
committed
(image_buffer) fix waitForRecentImage
1 parent 7926ecb commit 96a409b

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

ed_sensor_integration/src/kinect/image_buffer.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,34 +43,36 @@ bool ImageBuffer::waitForRecentImage(rgbd::ImageConstPtr& image, geo::Pose3D& se
4343
{
4444
if (!kinect_client_)
4545
{
46-
ROS_ERROR("[IMAGE_BUFFER] No RGBD client");
46+
ROS_ERROR_NAMED("image_buffer", "[IMAGE_BUFFER] No RGBD client");
4747
return false;
4848
}
4949

5050
// - - - - - - - - - - - - - - - - - -
5151
// Wait until we get a new image
5252

5353
ros::Time t_start = ros::Time::now();
54+
ros::Time t_end = t_start + ros::Duration(timeout_sec);
5455

5556
rgbd::ImageConstPtr rgbd_image;
56-
while(ros::ok())
57+
do
5758
{
58-
if (ros::Time::now() - t_start > ros::Duration(timeout_sec))
59-
return false;
60-
6159
rgbd_image = kinect_client_->nextImage();
6260

6361
if (rgbd_image)
6462
break;
63+
else if (ros::Time::now() > t_end)
64+
return false;
6565
else
6666
ros::Duration(0.1).sleep();
6767
}
68+
while(ros::ok()); // Give it minimal one go
69+
6870

6971
// - - - - - - - - - - - - - - - - - -
7072
// Wait until we have a tf
71-
72-
if (!tf_listener_->waitForTransform(root_frame_, rgbd_image->getFrameId(), ros::Time(rgbd_image->getTimestamp()), ros::Duration(timeout_sec)))
73-
return false;
73+
if (!tf_listener_->canTransform(root_frame_, rgbd_image->getFrameId(), ros::Time(rgbd_image->getTimestamp()))) // Get the TF when it is available now
74+
if (!tf_listener_->waitForTransform(root_frame_, rgbd_image->getFrameId(), ros::Time(rgbd_image->getTimestamp()), t_end - ros::Time::now()))
75+
return false;
7476

7577
// - - - - - - - - - - - - - - - - - -
7678
// Calculate tf
@@ -83,7 +85,7 @@ bool ImageBuffer::waitForRecentImage(rgbd::ImageConstPtr& image, geo::Pose3D& se
8385
}
8486
catch(tf::TransformException& ex)
8587
{
86-
ROS_ERROR("[IMAGE_BUFFER] Could not get sensor pose: %s", ex.what());
88+
ROS_ERROR_NAMED("image_buffer", "[IMAGE_BUFFER] Could not get sensor pose: %s", ex.what());
8789
return false;
8890
}
8991

0 commit comments

Comments
 (0)