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

opening data file or image in specific folder in package

asked 2015-02-10 13:18:52 -0500

Ralff gravatar image

Is there a way to access a specific folder to open a data file or image in an ROS package? I suppose I could find the environmental variable HOME then write the full path by adding the strings, but it seems like there would be a more simple way.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2015-02-10 21:48:10 -0500

dsolomon gravatar image

The more portable way to do this is to use getPath. This gets the addresyo of the specified package, then you can drill down to the specific directory. Note that this requires that the package is findable on the ROS_PACKAGE_PATH.

edit flag offensive delete link more


Note that apparently the roslib Python library is deprecated (from roslib.packages is deprecated, what's its successor?).

gvdhoorn gravatar image gvdhoorn  ( 2015-02-11 00:34:03 -0500 )edit

rospkg was the 2nd generation, and catkin_pkg is the catkin aware library

tfoote gravatar image tfoote  ( 2015-02-11 20:36:48 -0500 )edit

answered 2019-09-22 14:08:35 -0500

nbro gravatar image

Here's an example in Python

from rospkg import RosPack

def find_abs_pkg_path(pkg_name):
    """Returns the absolute path of the package with name pkg_name."""

    # Get an instance of RosPack with the default search paths
    ros_pack = RosPack()
    return ros_pack.get_path(pkg_name)

if __name__ == '__main__':
    PKG_PATH = find_abs_pkg_path("my_package")
    print "path of ROS package my_package", PKG_PATH
edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-02-10 13:18:52 -0500

Seen: 587 times

Last updated: Sep 22 '19