how does roslaunch $(find ...) actually work?
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?
Asked by Javier V. Gómez on 2017-01-11 06:21:28 UTC
Answers
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.
Asked by ermanas on 2019-08-08 04:56:41 UTC
Comments
This looks a lot like another issue I asked about here in Q/A 299232. See also github xacro issue 190 for discussion/explanation.
Asked by Stefan Kohlbrecher on 2019-09-02 09:13:43 UTC
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 butcatkin_ws/A/scripts/test.py
does. My guess would be that is what it is finding usingROS_PACKAGE_PATH
orCMAKE_PREFIX_PATH
.Asked by Michael Johnson on 2017-01-11 07:22:39 UTC
I played about with this and I found that if you change the test.launch file to this:
the param is set to
/catkin_ws/install/lib/A/test.py
. Weird.Asked by Michael Johnson on 2017-01-11 10:05:01 UTC
@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 :)Asked by Javier V. Gómez on 2017-01-11 11:06:41 UTC
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
Asked by lucascoelho on 2019-09-02 09:18:27 UTC