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

how does roslaunch $(find ...) actually work?

asked 2017-01-11 05:21:28 -0500

Short version of the question: When using installspace, where does $(find pkg) look for files? rospack find pkg returns the path to the share folder, but then I realized that we are able to do for instance $(find pkg)/scripts/test.py although test.py is installed in the lib folder. How can this work?

Long version of the question: I have the following case (very common in the ROS community):

Package A:

A
| - CMakeLists.txt
| - package.xml
| - launch
       | - test.launch
| - scripts
       | - test.py

CMakeLists.txt content:

# Regular Catkin CMakeList.txt
install(PROGRAMS
  scripts/test.py
  DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

install(DIRECTORY launch
  DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)

test.launch content:

<launch>
    <param name="my_param" command="$(find A)/scripts/test.py"/>
</launch>

test.py content is not meaningful.

After using installspace (or cross-compiling with bitbake using meta-ros repository) the file structure will look like:

$(ROS_DIR)
| - share
        | - A/launch/test.launch
| - lib
        | - A/test.py

I always thought that $(find pkg) worked the same as rospack find pkg but apparently not, as the second returns $(ROS_DIR)/share but the above launchfile is able to run the script in the lib folder. Therefore, how does $(find pkg) work, how does it resolve the corresponding path to use?

edit retag flag offensive close merge delete

Comments

Are you sure it is looking at the installed test.py file and not the one in your workspace? In your example $(ROS_DIR)/scripts/test.py doesn't exist but catkin_ws/A/scripts/test.py does. My guess would be that is what it is finding using ROS_PACKAGE_PATH or CMAKE_PREFIX_PATH.

Michael Johnson gravatar image Michael Johnson  ( 2017-01-11 06:22:39 -0500 )edit

I played about with this and I found that if you change the test.launch file to this:

<launch>
    <param name="value" value="$(find A)/scripts/test.py"/>
</launch>

the param is set to /catkin_ws/install/lib/A/test.py. Weird.

Michael Johnson gravatar image Michael Johnson  ( 2017-01-11 09:05:01 -0500 )edit

@Michael Johnson I didn't test it per se, but I am cross compiling, so that on the target machine I do not have a catkin workspace, evertyhing is on /opt/ros/indigo/... And yes, it is weird, convenient, but weird :)

Javier V. Gómez gravatar image Javier V. Gómez  ( 2017-01-11 10:06:41 -0500 )edit

As far as I could understand from rospack code, it builds a list of possible search paths. So the code support multiple locations to look for the files. Take a look: https://github.com/ros/rospack/blob/melodic-devel/src/rospack.cpp#L1206

lucascoelho gravatar image lucascoelho  ( 2019-09-02 09:18:27 -0500 )edit

2 Answers

Sort by » oldest newest most voted
1

answered 2019-08-08 04:56:41 -0500

ermanas gravatar image

updated 2019-09-02 06:52:44 -0500

As much as I understand, It works like roscd PackageName

So if you can find the folder with roscd, it means that you can find with

$(find PackageName) as well.

edit flag offensive delete link more
0

answered 2019-09-02 09:13:43 -0500

This looks a lot like another issue I asked about here in Q/A 299232. See also github xacro issue 190 for discussion/explanation.

edit flag offensive delete link more

Question Tools

3 followers

Stats

Asked: 2017-01-11 05:21:28 -0500

Seen: 13,242 times

Last updated: Sep 02 '19