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

Revision history [back]

You're on the right track. rosbag api is definitely the way to do this, here's how to go about it. I've modified one of the code examples from the rosbag page so that it uses a stamped message so you can test test time of the message.

#include <rosbag/bag.h>
#include <rosbag/view.h>
#include <geometry_msgs/PoseStamped.h>

#include <boost/foreach.hpp>
#define foreach BOOST_FOREACH

rosbag::Bag bag;
bag.open("test.bag", rosbag::bagmode::Read);

std::vector<std::string> topics;
topics.push_back(std::string("chatter"));
topics.push_back(std::string("numbers"));

rosbag::View view(bag, rosbag::TopicQuery(topics));

foreach(rosbag::MessageInstance const m, view)
{
    geometry_msgs::PoseStamped::ConstPtr pose = m.instantiate<geometry_msgs::PoseStamped>();
    if (pose != NULL)
    {
        if (pose.header.stamp > startTime && pose.header.stamp < endTime)
            int a; // Add this message to your C++ array here.
    }
}

bag.close();

This code will loop through every message in the bag testing if it's a PoseStamped message, then if it is checking if it's time stamp is within a given range.

Hope this gets you started.

You're on the right track. rosbag api is definitely the way to do this, here's how to go about it. I've modified one of the code examples from the rosbag page so that it uses a stamped message so you can test test time of the message.

#include <rosbag/bag.h>
#include <rosbag/view.h>
#include <geometry_msgs/PoseStamped.h>

#include <boost/foreach.hpp>
#define foreach BOOST_FOREACH

rosbag::Bag bag;
bag.open("test.bag", rosbag::bagmode::Read);

std::vector<std::string> topics;
topics.push_back(std::string("chatter"));
topics.push_back(std::string("numbers"));

rosbag::View view(bag, rosbag::TopicQuery(topics));

std::vector<double> myArray;

foreach(rosbag::MessageInstance const m, view)
{
    geometry_msgs::PoseStamped::ConstPtr pose = m.instantiate<geometry_msgs::PoseStamped>();
    if (pose != NULL)
    {
        if (pose.header.stamp > startTime && pose.header.stamp < endTime)
            int a; myArray.push_back(pose.pose.position.x); // Add this message to your C++ array here.
    }
}

bag.close();

This code will loop through every message in the bag testing if it's a PoseStamped message, then if it is checking if it's time stamp is within a given range.

Hope this gets you started.