How to load a file contained in a package
Let's say I have a file with stored information. I don't want to put the absolute path, neither do I want to roscd mypackage before executing my node so that the file can be found. Is there an elegant way of doing that on both Python and C++?
If it is not possible, how can I then solve the problem when using roslaunch, because then the file is not found anymore even when change my directory to the packages directory before launching.
Excellent question! I usually set the project source dir as define in CMakeLists.txt ( set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DLOCATION=${PROJECT_SOURCE_DIR}) ) and then use this define (LOCATION) in my code to locate the files. --> Works but what would be the proper way to do that??
is {PROJECT_SOURCE_DIR} a general flag recognized by CMake or do you replace it by the global path? In case of the latter option this doesn't fully solve the problem.