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

How to choose a fixed location for created bag files ?

asked 2016-11-14 11:35:12 -0600

ce_guy gravatar image

Hey guys,

I am creating a rqt plugin at the moment in Python and I am working with bag files. In the rqt plugin I create new bag files with rosbag.Bag("file_name", "w") and close them later.

Everything works fine but my bag files are always saved in the folder from where I started rqt in console.

Is it possible to choose a fixed folder for this?

I tried to find an answer in older questions but couldn't so I apologize if the question was already asked.

Thank you very much in advance!

Best regards

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-11-14 13:01:34 -0600

updated 2016-11-14 13:02:18 -0600

For sure the best way to do this is to specify full file paths for the bag file names. Here are a couple of thoughts that would go along with implementing this:

  • The first question is what directory to place the bag files in? This depends a bit on exactly what you are doing, but likely the default behavior would be to write the bag files to a particular ROS package directory or some pre-defined directory. If using a ROS package directory, you could use rospkg, if using a predefined directory, you'd likely want to use os.path.expanduser("~") to get the user's home directory (see example below).
  • Secondly, how can the user specify a different directory? You could allow the user to use Qt interfaces to specify the directory, or the user could pass a command line argument or set a ROS private parameter to overwrite the default directory.


import rospkg
import os
fname = "file_name.bag"

# first method
rospack = rospkg.RosPack()
pkgpath = rospack.get_path('my_package')
fullpath = os.path.join(pkgpath, fname)

# second method
pkgpath = os.path.expanduser("~")
fullpath = os.path.join(pkgpath, fname)
edit flag offensive delete link more


Thank you very much for the quick answer. I'll try this!

ce_guy gravatar image ce_guy  ( 2016-11-15 01:44:48 -0600 )edit

It works perfectly. :-) thank you very much

ce_guy gravatar image ce_guy  ( 2016-11-15 03:37:45 -0600 )edit

Question Tools

1 follower


Asked: 2016-11-14 11:35:12 -0600

Seen: 642 times

Last updated: Nov 14 '16