Ask Your Question
6

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

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

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 imageMichael Johnson ( 2017-01-11 06:22:39 -0600 )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 imageMichael Johnson ( 2017-01-11 09:05:01 -0600 )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 imageJavier V. Gómez ( 2017-01-11 10:06:41 -0600 )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 imagelucascoelho ( 2019-09-02 09:18:27 -0600 )edit

2 Answers

Sort by » oldest newest most voted
0

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

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
0

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

ermanas gravatar image

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

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

3 followers

Stats

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

Seen: 2,577 times

Last updated: Sep 02