ROS2 image publish rclpy taking 25ms

asked 2020-07-29 15:31:26 -0500

Malz gravatar image

updated 2020-07-29 22:09:00 -0500

Hi, I am having three nodes in my ROS2 Foxy. Firs node is is realsense Cam wich publishes the RGB Image(1280x720x3) and Depth Image(1280x720x1) using cvbridge and std_msgs/Image interface. This node is written in CPP Second node is inference_node which detects objects and classifies them then publishes the bbox and RGB data to other node. This node is written in python. Third node receives the bbox and RGB data from inference node. This is written in Python

The problem is that publishing RGB and Depth imagein C++ happens very quick and the publishing on thread works fine, However in inference node publishing of data takes around 40ms while my frame rate is 30 fps this is not acceptable.

The problems i observed is that threads are not running parallel in python if i start two threads one for publishing rgb data and another for depth data then they are executing sequentially and take 25ms + 15ms = 40ms. Is there a better way to send data in parallel as threads in python are running sequentially and publishing taking 25ms for rgb data alone. ? The following are my codes.

publisher_color = g_node.create_publisher(Image, api.ModelRunner.Publisher.RGB_RAW, g_queue_size)
publisher_depth = g_node.create_publisher(Image, api.ModelRunner.Publisher.DEPTH_RAW, g_queue_size)
while rclpy.ok():
     start_time = time.time() # Get current time
     thread1 = threading.Thread(target=publisher_depth.publish(depth_image_raw), args=(1,), daemon=True)
     thread1.start()
     thread2 = threading.Thread(target=publisher_color.publish(rgb_image_raw), args=(1,), daemon=True)
     thread2.start()

    thread1.join()
    thread2.join()
    end_time = time.time() # End time
    total_time = end_time-start_time # 40ms

I have also tried using threadpool but no success

executor = tp.ThreadPoolExecutor(max_workers=6)
while rclpy.ok():
    start_time = time.time() # Get current time
    executor.submit(publisher_depth.publish(depth_image_raw))
    executor.submit(publisher_color.publish(rgb_image_raw))
    end_time = time.time() # End time
    total_time = end_time-start_time # 40ms
edit retag flag offensive close merge delete