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

Why am I getting a nullptr from my bag file?

asked 2017-03-31 12:21:29 -0600

cpagravel gravatar image

I am playing back a bagfile and I get a nullptr when I should be getting actual data.

Below is a screenshot of the bagfile being viewed from RQT. There is only one message called "decomposition/sectors" and I am certain that it should have data. Yet, when I am playing back the bag file in C++ code for a unit test, I get a nullptr for this particular item. Why am I getting this? The other messages will be properly read and instantiated, but not this one.

image description

Here is a snippet of code which shows how I am reading this:

  void CoverageReporterTester::SendMessage(const rosbag::MessageInstance& bag_msg)
  {
    if (topic_name == avidbots_topics::decomposition_sectors)
    {
      message_stack::sector_array msg1 = *bag_msg.instantiate<message_stack::sector_array>();
      SendMessage(topic_name, msg1);
    }
  }

  /* Read bag file */
  rosbag::Bag bag_file;
  std::string bag_dir = ros::package::getPath("coverage_reporter") +
                          "/test/data/bag_files/coverage_reporter.bag";

  bag_file.open(bag_dir, rosbag::bagmode::Read);

  /* List of topics we are interested in */
  std::vector<std::string> topics;
  topics.push_back(topics::decomposition_sectors);

  topics.push_back(avidbots_topics::static_3d_costmap_topic);

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

  /* Loop through each message in the bag file which is associated with one of our topics listed above */
  foreach(rosbag::MessageInstance const bag_msg, view)
  {
    coverage_reporter.SendMessage(bag_msg);
  }
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-03-31 12:30:07 -0600

cpagravel gravatar image

I found the answer, the message description had changed since the bagfile was created. If there are any other reasons, please feel free to leave additional answers so others can use this as a reference.

edit flag offensive delete link more

Comments

Yep; instantiate returns a null pointer if it can't convert the stored message into the type you've given. This can happen if the message definition has changed, or if your code uses the wrong message type.

ahendrix gravatar image ahendrix  ( 2017-03-31 13:04:55 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-03-31 12:21:29 -0600

Seen: 576 times

Last updated: Mar 31 '17