Refer to current package's root name
What's the best way to refer to the name of the package's root folder?
For example, if I had a package named X
and I wanted to read files from, e.g., the bag
subfolder (i.e. X/bag
) from either inside a script under scripts
(i.e. X/scripts/read_file_from_bag_subfolder.py
) or from a module under src
(e.g. src/X/read_file_from_bag_subfolder.py
), what would be the best way to do it?
I know I can use rospack
as I explained here http://wiki.ros.org/Packages , but that requires you to manually specify the name of the current package, but if it changes, then you would also need to change that code, so maybe a relative way of doing it would be better, even though this may also cause problems if you decide to move your code to another subfolder.