Skip to content
This repository was archived by the owner on Jul 26, 2024. It is now read-only.

Commit 04b05d8

Browse files
authored
Merge pull request #205 from amelhassan/foxy-devel
Fixed node not shutting down, if sensor stream breaks (ROS2)
2 parents a0a4d5f + b09c432 commit 04b05d8

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/k4a_ros_device.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -874,12 +874,15 @@ void K4AROSDevice::framePublisherThread()
874874
calibration_data_.getRgbCameraInfo(depth_rect_camera_info);
875875
calibration_data_.getDepthCameraInfo(ir_raw_camera_info);
876876

877+
const std::chrono::milliseconds firstFrameWaitTime = std::chrono::milliseconds(4 * 1000);
878+
const std::chrono::milliseconds regularFrameWaitTime = std::chrono::milliseconds(1000 * 5 / params_.fps);
879+
std::chrono::milliseconds waitTime = firstFrameWaitTime;
880+
877881
while (running_ && rclcpp::ok())
878882
{
879883
if (k4a_device_)
880884
{
881-
// TODO: consider appropriate capture timeout based on camera framerate
882-
if (!k4a_device_.get_capture(&capture, std::chrono::milliseconds(K4A_WAIT_INFINITE)))
885+
if (!k4a_device_.get_capture(&capture, waitTime))
883886
{
884887
RCLCPP_FATAL(this->get_logger(),"Failed to poll cameras: node cannot continue.");
885888
rclcpp::shutdown();
@@ -900,6 +903,7 @@ void K4AROSDevice::framePublisherThread()
900903
capture.get_color_image().get_system_timestamp());
901904
}
902905
}
906+
waitTime = regularFrameWaitTime;
903907
}
904908
else if (k4a_playback_handle_)
905909
{

0 commit comments

Comments
 (0)