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

Revision history [back]

Your first method it not isolating the message topics correctly which may explain the numbers of messages being twice as high as you expect.

The following lines only check if the message is an sensor_msgs::Image not which topic it is, so they will execute for both image topics:

sensor_msgs::Image::ConstPtr img0 = m.instantiate<sensor_msgs::Image>();
if(img0!=NULL)
{
    // ...
}

You want to use the rosbag::MessageInstance::getTopic() method to get the actual topic name for each message and check that instead as below.

if (m.getTopic() == "/cam0/image_raw" && m.isType<sensor_msgs::Image>())
{
    sensor_msgs::Image::ConstPtr img0 = m.instantiate<sensor_msgs::Image>();
    fprintf(fp0, "%.9lf\n", img0->header.stamp.toSec());
}

This should give you the correct number of messages.

Your second method works but message delivery in ROS is not guaranteed, so it's quite possible that some messages are dropped using this technique meaning your totals would not be correct.

Hope this fixes this for you

Your first method it is not isolating the message topics correctly which may explain the numbers of messages being twice as high as you expect.

The following lines only check if the message is an sensor_msgs::Image not which topic it is, so they will execute for both image topics:

sensor_msgs::Image::ConstPtr img0 = m.instantiate<sensor_msgs::Image>();
if(img0!=NULL)
{
    // ...
}

You want to use the rosbag::MessageInstance::getTopic() method to get the actual topic name for each message and check that instead as below.

if (m.getTopic() == "/cam0/image_raw" && m.isType<sensor_msgs::Image>())
{
    sensor_msgs::Image::ConstPtr img0 = m.instantiate<sensor_msgs::Image>();
    fprintf(fp0, "%.9lf\n", img0->header.stamp.toSec());
}

This should give you the correct number of messages.

Your second method works but message delivery in ROS is not guaranteed, so it's quite possible that some messages are dropped using this technique meaning your totals would not be correct.

Hope this fixes this for you