@@ -300,7 +300,7 @@ void OBCameraNode::setupDevices() {
300300 RCLCPP_INFO_STREAM (logger_,
301301 " Software trigger period " << software_trigger_period_.count () << " ms" );
302302 software_trigger_timer_ = node_->create_wall_timer (software_trigger_period_, [this ]() {
303- if (software_trigger_enabled_) {
303+ if (!service_trigger_enabled_ and software_trigger_enabled_) {
304304 TRY_EXECUTE_BLOCK (device_->triggerCapture ());
305305 }
306306 });
@@ -1655,7 +1655,8 @@ void OBCameraNode::getParameters() {
16551655 setAndGetNodeParameter<int >(trigger2image_delay_us_, " trigger2image_delay_us" , 0 );
16561656 setAndGetNodeParameter<int >(trigger_out_delay_us_, " trigger_out_delay_us" , 0 );
16571657 setAndGetNodeParameter<bool >(trigger_out_enabled_, " trigger_out_enabled" , true );
1658- setAndGetNodeParameter<bool >(software_trigger_enabled_, " software_trigger_enabled" , true );
1658+ setAndGetNodeParameter<bool >(software_trigger_enabled_, " software_trigger_enabled" , false );
1659+ setAndGetNodeParameter<bool >(service_trigger_enabled_, " service_trigger_enabled" , false );
16591660 setAndGetNodeParameter<bool >(enable_ptp_config_, " enable_ptp_config" , false );
16601661 setAndGetNodeParameter<std::string>(cloud_frame_id_, " cloud_frame_id" , " " );
16611662 if (enable_colored_point_cloud_ || enable_d2c_viewer_) {
@@ -2660,7 +2661,7 @@ bool OBCameraNode::decodeColorFrameToBuffer(const std::shared_ptr<ob::Frame> &fr
26602661 if (enable_colored_point_cloud_ && depth_registration_cloud_pub_->get_subscription_count () > 0 ) {
26612662 has_subscriber = true ;
26622663 }
2663- if (!has_subscriber) {
2664+ if (!has_subscriber && !service_capture_started_ ) {
26642665 return false ;
26652666 }
26662667 if (metadata_publishers_.count (COLOR) &&
@@ -2753,7 +2754,7 @@ void OBCameraNode::onNewFrameCallback(const std::shared_ptr<ob::Frame> &frame,
27532754 has_subscriber =
27542755 has_subscriber || (metadata_publishers_.count (stream_index) &&
27552756 metadata_publishers_[stream_index]->get_subscription_count () > 0 );
2756- if (!has_subscriber) {
2757+ if (!has_subscriber && !service_capture_started_ ) {
27572758 return ;
27582759 }
27592760 std::shared_ptr<ob::VideoFrame> video_frame;
@@ -2835,9 +2836,6 @@ void OBCameraNode::onNewFrameCallback(const std::shared_ptr<ob::Frame> &frame,
28352836 publishMetadata (frame, stream_index, camera_info.header );
28362837 }
28372838 CHECK_NOTNULL (image_publishers_[stream_index]);
2838- if (image_publishers_[stream_index]->get_subscription_count () == 0 ) {
2839- return ;
2840- }
28412839 auto &image = images_[stream_index];
28422840 if (image.empty () || image.cols != width || image.rows != height) {
28432841 image.create (height, width, image_format_[stream_index]);
@@ -2848,7 +2846,7 @@ void OBCameraNode::onNewFrameCallback(const std::shared_ptr<ob::Frame> &frame,
28482846 }
28492847 if (frame->getType () == OB_FRAME_COLOR && frame->format () != OB_FORMAT_Y8 &&
28502848 frame->format () != OB_FORMAT_Y16 && frame->format () != OB_FORMAT_BGRA &&
2851- frame->format () != OB_FORMAT_RGBA && image_publishers_[COLOR]->get_subscription_count () > 0 ) {
2849+ frame->format () != OB_FORMAT_RGBA && ( image_publishers_[COLOR]->get_subscription_count () > 0 || service_capture_started_) ) {
28522850 memcpy (image.data , rgb_buffer_, video_frame->getWidth () * video_frame->getHeight () * 3 );
28532851 } else {
28542852 memcpy (image.data , video_frame->getData (), video_frame->getDataSize ());
@@ -2868,10 +2866,32 @@ void OBCameraNode::onNewFrameCallback(const std::shared_ptr<ob::Frame> &frame,
28682866 image_msg->step = width * unit_step_size_[stream_index];
28692867 image_msg->header .frame_id = frame_id;
28702868 CHECK (image_publishers_.count (stream_index) > 0 );
2871- saveImageToFile (stream_index, image, *image_msg);
2872- image_publishers_[stream_index]->publish (std::move (image_msg));
2873- if (stream_index == COLOR && enable_color_undistortion_ &&
2874- color_undistortion_publisher_->get_subscription_count () > 0 ) {
2869+
2870+ if (image_publishers_[stream_index]->get_subscription_count () > 0 ) {
2871+ // saveImageToFile(stream_index, image, *image_msg);
2872+ image_publishers_[stream_index]->publish (std::move (image_msg));
2873+ }
2874+
2875+ if (service_trigger_enabled_ and service_capture_started_) {
2876+ std::unique_lock<std::mutex> lock (service_capture_lock_);
2877+ if (stream_index == COLOR) {
2878+ if (image_msg) {
2879+ number_of_rgb_frames_captured_++;
2880+ color_image_ = std::move (image_msg);
2881+ color_image_camera_info_ = camera_info;
2882+ }
2883+ }
2884+ else if (stream_index == DEPTH) {
2885+ if (image_msg) {
2886+ number_of_depth_frames_captured_++;
2887+ depth_image_ = std::move (image_msg);
2888+ depth_image_camera_info_ = camera_info;
2889+ }
2890+ }
2891+ service_capture_cv_.notify_all ();
2892+ }
2893+
2894+ if (stream_index == COLOR && enable_color_undistortion_) {
28752895 auto undistorted_image = undistortImage (image, intrinsic, distortion);
28762896 sensor_msgs::msg::Image::UniquePtr undistorted_image_msg (new sensor_msgs::msg::Image ());
28772897 cv_bridge::CvImage (std_msgs::msg::Header (), encoding_[stream_index], undistorted_image)
@@ -2881,7 +2901,9 @@ void OBCameraNode::onNewFrameCallback(const std::shared_ptr<ob::Frame> &frame,
28812901 undistorted_image_msg->is_bigendian = false ;
28822902 undistorted_image_msg->step = width * unit_step_size_[stream_index];
28832903 undistorted_image_msg->header .frame_id = frame_id;
2884- color_undistortion_publisher_->publish (std::move (undistorted_image_msg));
2904+ if (color_undistortion_publisher_->get_subscription_count () > 0 ) {
2905+ color_undistortion_publisher_->publish (std::move (undistorted_image_msg));
2906+ }
28852907 }
28862908}
28872909
0 commit comments