Ask Your Question
2

Unable to open rosbag files in C++

asked 2015-12-06 13:12:47 -0500

jll gravatar image

updated 2015-12-09 10:08:42 -0500

Hello,

I am trying to write a node to edit the timestamps in a bag file, using C++. The code I have written is attached below. I have tried to follow the template given in the rosbag C++ API, but I am unable to open any of the bag files I have, even though they run perfectly well when I play them back using rosbag play. Specifically, I am seeing the error message

terminate called after throwing an instance of 'rosbag::BagIOException'
  what():  Error opening file: ~/catkin_ws/src/publish_text/launch/filtered.bag

I am not quite sure why exactly this is happening. Would greatly appreciate it if anyone had any suggestions!

Thanks. (Code from the main function of my code enclosed below)

ros::init(argc, argv, "postprocessing");

ros::NodeHandle nh("~");

std::string instr, outstr;

rosbag::Bag inbag, outbag;

if (nh.getParam("input_path", instr)) {
  inbag.open(instr, rosbag::bagmode::Read);
} else {
  ROS_ERROR("No input path provided, terminating\n");
  exit(1);
}

if (!nh.getParam("output_path", outstr)) {
  outbag.open(outstr, rosbag::bagmode::Write);
} else {
  ROS_ERROR("No output path provided, terminating\n");
  exit(1);
}

UPDATE: I was able to resolve the issue by replacing the path with an absolute path from the root directory.

edit retag flag offensive close merge delete

Comments

Does rosbag::Bag API support relative paths like this: rosbag::Bag::open("./name_of_bagfile") ? I'm using ROS Groovy default install

2ROS0 gravatar image 2ROS0  ( 2016-08-02 11:27:16 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-12-07 02:05:39 -0500

gvdhoorn gravatar image
terminate called after throwing an instance of 'rosbag::BagIOException'
  what():  Error opening file: ~/catkin_ws/src/publish_text/launch/filtered.bag

Most likely you are expecting the C++ runtime to resolve/replace the ~ with the path to the users home directory. Afaik that behaviour is implemented by the shell (ie: bash), it's not something that works everywhere.

Can you try to provide an absolute (or even relative) path to rosbag::Bag::open(..)?

edit flag offensive delete link more

Comments

I have the same problem when adding a relative path (absolute path works fine) as such: rosbag::Bag::open("./name_of_bagfile.bag")

2ROS0 gravatar image 2ROS0  ( 2016-08-02 11:25:37 -0500 )edit

Did you managed to use the relative path ? I have exactly the same problem, absolute path is working fine but the relative one doesn't. I am using kinetic version.

antoineniotna gravatar image antoineniotna  ( 2019-05-06 05:02:49 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-12-06 13:12:47 -0500

Seen: 2,579 times

Last updated: Dec 09 '15