ROS2 how to make a node read files
hi, i've made a ros2 node that outputs a msg to another node. the problem comes when i make that node file import a python script to run OpenCV with Yolo. i can import the python file all good but when the script comes to
net = cv2.dnn.readNet("yolov3_training_last.weights", "yolov3_testing.cfg")
the script stops because it cannot map to the yolov3_training_last.weight and yolov3_testing.cfg. Package name: yeti error: Failed to parse NetParameter File: /home/user/dev_ws/srs/yeti/yetiyolov3_testing.
for some reason it wont give a / for last folder into the file it wants, as the folder structure is yeti/yeti/yolov3 files. How does ros2 eloquent find files? how can i get a ros2 node import a python script that uses files in the folder i use to build the package?
When you build a ROS2 package using
colcon build
aninstall/
directory will be generated with your package and its files. Python nodes, YAML parameter files, etc. are copy/pasted intoinstall/
during the build process. If you're trying to reference files relative to the node's python file then all of those paths will be messed-up after the build process.Assuming you're running Ubuntu or something similar you can find the copies of those files in the
install/
directory by running:find ./install/ -type d -name *.py
You should get something like
install/<pkg_name>/lib/python3.8/site-packages/<pkg_name>/your_ros2_node.py
Miscellaneous files won't be copied during build process automatically, unless you add them to "data_files=[]" in the setup.py file. You can read about this here:
https://roboticsbackend.com/create-a-...
As for linking to files in the src folder, it seems that it's a bad idea, see William's comment ( Jun 13 '18 ) here:
https://answers.ros.org/question/2939...
There is however a way you could override the build to read all files from the src folder instead from the install folder like this:
colcon build --symlink-install --packages-select your-package-name
see https://docs.ros.org/en/foxy/Tutorial...
But this is probably intended just for developing purpose.