0
$\begingroup$

Rosanswers logo

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


Originally posted by ce_guy on ROS Answers with karma: 77 on 2016-11-14

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.

Example:

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)

Originally posted by jarvisschultz with karma: 9031 on 2016-11-14

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by ce_guy on 2016-11-15:
Thank you very much for the quick answer. I'll try this!

Comment by ce_guy on 2016-11-15:
It works perfectly. :-) thank you very much

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.