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

Revision history [back]

click to hide/show revision 1
initial version

I have solved the problem : the cpp file given on ros tutorial is not ready for direct usage (f). We need to include it in int main() and include a few more libraries like

include <std_msgs string.h="">

include <std_msgs int32.h="">

and remove ASSERT_EQ as it will further give error.

rosplay.cpp

include <ros ros.h="">

include <rosbag view.h="">

include <gtest gtest.h="">

include <std_msgs string.h="">

include <std_msgs int32.h="">

include <boost foreach.hpp="">

define foreach BOOST_FOREACH

int main (int argc, char** argv) { ros::init (argc, argv, "bag_it"); rosbag::Bag bag; bag.open("~/bagfiles/2016-12-20-18-18-30.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)
{
    std_msgs::String::ConstPtr s = m.instantiate<std_msgs::String>();
    if (s != NULL)
        std::cout << s->data << std::endl;

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

bag.close();
return (0);

}

I have solved the problem : the cpp file given on ros tutorial is not ready for direct usage (f). We need to include it in int main() and include a few more libraries like

include <std_msgs string.h="">

include <std_msgs int32.h="">

and remove ASSERT_EQ as it will further give error.

rosplay.cpp

include <ros ros.h="">

include <rosbag view.h="">

include <gtest gtest.h="">

include <std_msgs string.h="">

include <std_msgs int32.h="">

include <boost foreach.hpp="">

define
#include <ros/ros.h>
#include <rosbag/view.h>

#include <gtest/gtest.h>
#include <std_msgs/String.h>
#include <std_msgs/Int32.h>
#include <boost/foreach.hpp>

#define foreach BOOST_FOREACH

BOOST_FOREACH int main (int argc, char** argv) { ros::init (argc, argv, "bag_it"); rosbag::Bag bag; bag.open("~/bagfiles/2016-12-20-18-18-30.bag", rosbag::bagmode::Read);

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

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

 bag.close();
 return (0);
}

}