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

where to download extra files needed at runtime?

asked 2013-12-12 06:34:54 -0600

brice rebsamen gravatar image

updated 2013-12-12 07:20:48 -0600

With rosbuild, I used to download data when building and place them in the src folder. I could them find them at runtime with ros::package::getPath().

This is usually data that is too large to be hosted in the repository, like large binary configuration files. They are needed by some of our nodes, and they usually load them when they start. As such they must be accessible at run time.

Now in catkin, I am wondering where to download them and how to retrieve them at runtime. I created a cmake function based on download_checkmd5.py that creates a new target (download_extra_data). Each package CMakeLists can declare some data to be downloaded, which happens when I make that target. What's the best strategy?

I can download them to the source folder and retrieve them with ros::package::getPath(), but that goes against the principle of not touching the source folder. Also, this would probably not work if I were to distribute my package in binary form (as the ros packages are), so it does not seem like a good solution.

I can download them to the build folder, but then how to retrieve them at runtime?

I believe the best would be to download them to the devel space, right? How can I do that? Then how to retrieve them at runtime?

For the moment, as a temporary solution, I am downloading to a path specified by an environment variable, but I am looking for a cleaner solution.

edit retag flag offensive close merge delete

Comments

My question before answering would be what kind of data are you downloading during the build?

Dirk Thomas gravatar image Dirk Thomas  ( 2013-12-12 06:42:28 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
2

answered 2014-01-28 12:05:23 -0600

brice rebsamen gravatar image

Thanks to Dirk Thomas' answer, I managed to get a solution. Here it is for reference:

1- I download the file to ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_SHARE_DESTINATION}

2- in order to find it from my c++ code, I wrote a little helper: https://gist.github.com/bricerebsamen/8679151

edit flag offensive delete link more
4

answered 2013-12-12 07:41:42 -0600

Dirk Thomas gravatar image

When you download the file you can specify any location where you want it to be stored. E.g. when using catkin_download_test_data you could pass ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_SHARE_DESTINATION} as the DESTINATION in order to place the downloaded file in the devel space under share/YOUR-PKG-NAME.

(Your CMake function to register new downloads should enable to specify a user defined target name for each download in order to be able to declare dependencies between targets.)

To find the resources in a scenario with a devel and source space you can't use the ros::package API. It does not know about the new workspace layout. Instead you have to options:

  • you can use catkin_find (as a command line tool, which has various options to tailor your search criteria) or the Python API from catkin.find_in_workspaces to dynamically resolve the location of the resources

  • or you could pass the known location from within CMake to your code via a configuration file, embed the location into your code (using configure_file) or an environment variable (as you did it before).

(Please consider that it might be considered bad habit if a user checks out your package into a workspace but is then unable to build the workspace without further internet connectivity.)

edit flag offensive delete link more

Comments

No c++ API for catkin_find... could it be used in launch files?

brice rebsamen gravatar image brice rebsamen  ( 2013-12-12 07:58:17 -0600 )edit

In launch files the `$find` logic already uses catkin_find. So you can find resources in source as well as devel space. Just make sure that the relative path within the packages share folder is the same in all spaces.

Dirk Thomas gravatar image Dirk Thomas  ( 2013-12-12 09:16:13 -0600 )edit

Sorry but I don't understand your last comment. catkin_find returns several paths. roslaunch $find returns only one (devel path in my case).

brice rebsamen gravatar image brice rebsamen  ( 2013-12-18 10:58:02 -0600 )edit

`catkin_find` has several options to narrow down the search results. Depending on how it is used in roslaunch different options are passed to `catkin_find` to only find specific resources. Please see `catkin_find --help` for a list of available options.

Dirk Thomas gravatar image Dirk Thomas  ( 2013-12-18 11:02:01 -0600 )edit

I could not find any doc for roslaunch $find. Could you elaborate on "Depending on how it is used in roslaunch"?

brice rebsamen gravatar image brice rebsamen  ( 2013-12-18 11:11:29 -0600 )edit
1

You can use $find to find an executable (in a node tag) as well as find additional resources which are only used as arguments (e.g. a param value). Depending on where in a launch file you use $find "catkin_find" is invoked with different arguments.

Dirk Thomas gravatar image Dirk Thomas  ( 2013-12-18 11:16:44 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2013-12-12 06:34:54 -0600

Seen: 1,291 times

Last updated: Jan 28 '14