ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Image transport get long delay

asked 2018-06-27 04:49:03 -0500

forever3000 gravatar image

updated 2018-06-28 01:06:43 -0500

William gravatar image

I'm using ROS kinetic (Ubuntu 16.04) as following link : http://wiki.ros.org/kinetic/Installat... , 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,

edit retag flag offensive close merge delete

Comments

Which version of ROS 2 are you using, what OS are you on, and how did you install it?

William gravatar image William  ( 2018-06-27 19:30:19 -0500 )edit

Please add that information to your original question, thanks!

William gravatar image William  ( 2018-06-27 19:31:05 -0500 )edit

Hi William,

I'm using ROS kinetic (Ubuntu 16.04) as following link : http://wiki.ros.org/kinetic/Installat... I installed ROS-Base: (Bare Bones) and image-transport package seperately.

Thanks and Best Regards,

forever3000 gravatar image forever3000  ( 2018-06-27 19:34:09 -0500 )edit

Ok, so ROS Kinetic is ROS 1, so I retagged your question.

William gravatar image William  ( 2018-06-28 01:07:31 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2018-06-27 10:09:57 -0500

VictorLamoine gravatar image

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.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-06-27 04:49:03 -0500

Seen: 710 times

Last updated: Jun 28 '18