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