如何读取rosbag中的标准消息?(C++)

#include 
#include 
#include 
#include 

#include 
#define foreach BOOST_FOREACH

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

std::vector 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)
{
    std_msgs::String::ConstPtr s = m.instantiate();
    if (s != NULL)
        std::cout << s->data << std::endl;

    std_msgs::Int32::ConstPtr i = m.instantiate();
    if (i != NULL)
        std::cout << i->data << std::endl;
}

bag.close();

 

你可能感兴趣的:(ROS)