Image transport get long delay
I'm using ROS kinetic (Ubuntu 16.04) as following link : http://wiki.ros.org/kinetic/Installation/Ubuntu, installed ROS-Base: (Bare Bones) and image-transport package seperately.
I'm trying to publish raw image (1280 * 720 * 2 bytes) to the other node by using image_transport with roscpp and subscriber need to wait about 10 - 15ms to receive image from publisher.
Publisher:
image_transport::ImageTransport it(nh_);
pub = it.advertise("image_raw", 1);
sensor_msgs::Image msg;
msg.header.seq = count;
msg.header.frame_id = "camera";
msg.header.stamp.sec = ros::Time::now().sec;
msg.header.stamp.nsec = ros::Time::now().nsec;
msg.height = 720;
msg.width = 1280;
msg.data.resize(1280*720*2);
memcpy(msg.data.data(), image_ptr_0, 1280*720*2);
pub.publish(msg);
Subscriber
image_transport::ImageTransport it(nh_);
image_transport::Subscriber sub = it.subscribe("/camera_pkg_node/image_raw", 1, ImageCallback);
void ImageCallback (const sensor_msgs::ImageConstPtr& msg)
{
printf ("Receive Image Start Time at %ds:%dms \r\n", msg->header.stamp.sec, msg->header.stamp.nsec/1000000);
printf ("Receive Image Recv Time at %ds:%dms \r\n", ros::Time::now().sec, ros::Time::now().nsec/1000000);
}
Console
Receive Image Start Time at 1530091465s:977ms
Receive Image Recv Time at 1530091465s:989ms
Receive Image Start Time at 1530091466s:7ms
Receive Image Recv Time at 1530091466s:18ms
Is there any way to reduce latency between publisher and subscriber.
Thanks and Best Regards, Vu Nguyen
Edit (made by @William):
Hi VictorLamoine,
Thank for you reply. Actually I want to measure the delay of Publishing/Subscribing. I tried to measure time for resizing and copying image as well as Publishing/Subscribing, this is the result
Time stamp before resizing and copying : 1530144835s:805ms
Time stamp after resizing and copying : 1530144835s:806ms
Time stamp after receive at Subscriber : 1530144835s:817ms
As we can see, resizing and copy take only 1ms but Publishing/Subscribing need more than 10ms. I'm wondering there is any way to reduce this latency.
Updated:
Even though I tried with small data (about 10 -20 bytes) with normal publish/subscribe it took 1-2 ms, I think it was acceptable but sometime it took 5-6ms or 7-8ms.
Thanks and Best Regards,
Asked by forever3000 on 2018-06-27 04:49:03 UTC
Answers
What you are measuring is the delay of:
- msgs.data.resize
- memcpy
- Publishing / subscribing
I think the memcpy operation cannot be ignored in terms of timing. You set the header stamp then resize the image and do the memory copy these operations take quite a lot of time!
msg.height = 720;
msg.width = 1280;
msg.data.resize(1280*720*2);
memcpy(msg.data.data(), image_ptr_0, 1280*720*2);
msg.header.stamp.sec = ros::Time::now().sec;
msg.header.stamp.nsec = ros::Time::now().nsec;
What happens to the delay if you set the time-stamp at the end like above?
I suggest measuring the time the image resizing and copy takes.
Asked by VictorLamoine on 2018-06-27 10:09:57 UTC
Comments
Which version of ROS 2 are you using, what OS are you on, and how did you install it?
Asked by William on 2018-06-27 19:30:19 UTC
Please add that information to your original question, thanks!
Asked by William on 2018-06-27 19:31:05 UTC
Hi William,
I'm using ROS kinetic (Ubuntu 16.04) as following link : http://wiki.ros.org/kinetic/Installation/Ubuntu I installed ROS-Base: (Bare Bones) and image-transport package seperately.
Thanks and Best Regards,
Asked by forever3000 on 2018-06-27 19:34:09 UTC
Ok, so ROS Kinetic is ROS 1, so I retagged your question.
Asked by William on 2018-06-28 01:07:31 UTC