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

ApproximateTime Policy of message filter doesn't filter right [closed]

asked 2013-01-08 07:52:04 -0600

dinamex gravatar image

updated 2014-01-28 17:14:45 -0600

ngrennan gravatar image

Hi all,

I would like to synchronize some of my sensordata (kinect and a webcam) in the mater of time. My webcam seems to put everything in a internal memory before transmitting it. Because of that I have a time difference of about 1 sec to the actual recorded scene. I tried to adjust the time-stamp in the header of webcam message before publishing and then use the message filter package to synchronize them as good as possible to my kinect images (openni_launch).

Here is my function which grabs an image from the webcam, fills in the header and publishes the data. (its the source code of the usb_cam with some minor tweaks)

bool take_and_send_image(){

         usb_cam_camera_grab_image(camera_image_);
         fillImage(img_, "rgb8", camera_image_->height, camera_image_->width, 3 *camera_image_->width, camera_image_->image);


         img_.header.stamp = ros::Time::now();
         ROS_INFO("Time now = %i.%i",img_.header.stamp.sec, img_.header.stamp.nsec );

         ros::Duration lag(5.0);
         ros::Time header_time = ros::Time::now()-lag;
         img_.header.stamp = header_time;
         info_.header.stamp = img_.header.stamp;

         ROS_INFO("Time lag = %i.%i",img_.header.stamp.sec, img_.header.stamp.nsec );


         image_pub_.publish(img_, info_);

            return true;


}

the output of this code indicates that the minus operation does the right thing.

[ INFO] [1357672295.986516662]: Time now = 1357672295.986394591
[ INFO] [1357672295.986791322]: Time lag = 1357672290.986699769

This is the subscriber which is pretty much the same as in the tutorial for the message filter. subscribing and calling the callback everytime two messages have the approximate same time.

void sync_callback(const ImageConstPtr&  webcam_image,const ImageConstPtr&  rgb_image){

     // save both images to disk



     ROS_INFO("syncro callback");
     ROS_INFO("Kinect Timestamp= %i.%i",rgb_image->header.stamp.sec,rgb_image->header.stamp.nsec);
     ROS_INFO("Webcam Timestamp= %i.%i",webcam_image->header.stamp.sec,webcam_image->header.stamp.nsec);

}



int main(int argc, char **argv){

      ros::init(argc, argv, "listener");
      ros::NodeHandle nh;
      image_transport::ImageTransport it(nh);

      image_transport::SubscriberFilter webcam_sub (it, "/panda_cam/image_raw", 20);
      image_transport::SubscriberFilter rgb_sub (it, "/camera/rgb/image", 20);
      Synchronizer<MySyncPolicy> sync(MySyncPolicy(1000), webcam_sub, rgb_sub);

      ROS_INFO("Ready to recieve messages");
      sync.registerCallback(boost::bind(&sync_callback, _1, _2));

      ros::spin();
      return 0;
}

The output of the time is indeed indicating that the message are 5 seconds behind the actual time.

[ INFO] [1357672295.859623746]: Kinect Timestamp= 1357672290.292021533
[ INFO] [1357672295.859715299]: Webcam Timestamp= 1357672290.301270495

But by observing the images (of a stopwatch) there is now real difference even when I ad 10 or more seconds to it. The Kinect header is still the original and pretty much on the original time and can be seen as my reference.

Would be great if someone could point me to the failure.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Procópio
close date 2017-06-06 05:46:11.512519

2 Answers

Sort by » oldest newest most voted
1

answered 2013-01-09 07:53:10 -0600

dinamex gravatar image

updated 2013-01-09 07:53:27 -0600

I answered the question on my own. I made the mistake to aspect that the synchronization takes the actual time into account, which is not the case. Therefore both images (kinect and webcam) are now behind the time of the stopwatch with respect to my "trigger". By adding a third message as trigger to the synchronization the packages works as expected.

edit flag offensive delete link more
0

answered 2013-01-08 15:22:33 -0600

dejanpan gravatar image

dinamex I just ran the test using usb_cam package (configured to output 1920x1080 images) and Logitech C920 HD Pro Webcam and I am pretty sure that there is no delay in images coming out of the driver. Also the driver handles 30fps without a problem. I run the test by viewing the images in image_view: rosrun image_view image_view image:=/usb_cam/image_raw.

Are you running all your processes on 1 computer or multiple ones? If the latter, are the computers time synchronized? D.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-01-08 07:52:04 -0600

Seen: 1,849 times

Last updated: Jan 09 '13