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?
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
.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.@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 :)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