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

segfault when reading rosbag

asked 2016-02-18 12:06:01 -0600

mark_vision gravatar image

Hi all, I'm trying to parse a rosbag file. According to the guide here, I wrote something like this:

rosbag::Bag bag;
std::vector<std::string> topics;
std::cout << "Opening " << filename_ << std::endl;
bag.open(filename_.c_str(), rosbag::bagmode::Read);
std::cout << "Mode: " << bag.getMode() << std::endl;

topics.push_back(std::string("/Imu"));
topics.push_back(std::string("/joint_states"));
rosbag::View view(bag, rosbag::TopicQuery(topics));
foreach(rosbag::MessageInstance const m, view) {
    std::cout << "Found message of type "  << m.getDataType() << std::endl;
    if(m.getDataType().compare("sensor_msgs/Imu") == 0) {
        sensor_msgs::ImuConstPtr s = m.instantiate<sensor_msgs::Imu>();

        cout << "S = " << s << std::endl;
        double ax = s->linear_acceleration.x;
}

The address printed by S is not NULL, but when I reach the last line to get the data, I get a SEGFAULT.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-02-25 12:51:54 -0600

mark_vision gravatar image

The issue has been solved by de-referentiating the pointer and using the local variable for data usage:

sensor_msgs::ImuConstPtr s = m.instantiate<sensor_msgs::Imu>();
sensor_msgs::Imu imu = (*s);
double ax = imu.linear_acceleration.x;
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-02-18 12:06:01 -0600

Seen: 539 times

Last updated: Feb 25 '16