How to create custom directory

asked 2023-07-03 13:47:24 -0600

klaudiusz.s1405 gravatar image

updated 2023-07-04 06:14:59 -0600

Mike Scheutzow gravatar image

Hello, I want to create custom directory with images to process (get contours and then draw them with turtlesim). My current folder structure is (inside src folder):

contour_drawing    
--| contour_drawing     
----| init.py      
----| contour_drawing.py      
--| img        
----| img1.png       
--| launch       
----| contour_drawing_launch.py      
--| resource      
----| *default structure*      
--| test      
----| *default structure*       
--| package.xml      
--| setup.cfg      
--| setup.py

Right now I am using absolute paths, but I don't like that method. I would like to use relative paths, but nothing I tried is working. How can I get path to img1.png? I'm using ROS2 Humble, Python 3.11 and Ubuntu 22.04 VM

edit retag flag offensive close merge delete

Comments

Have you tried looking to launch files capabilities? I have almost no experience working with them, but it would seem that somehow you might be able to get the location context for your workspace: Tutorial: ROS2 launch files – All you need to know

magladko gravatar image magladko  ( 2023-07-04 14:50:55 -0600 )edit

I'm using launch file, it has nothing to do with path to static file

klaudiusz.s1405 gravatar image klaudiusz.s1405  ( 2023-07-05 09:44:30 -0600 )edit

What I meant is that you can get e.g. pwd running os.getcwd() command in python launch file and pass it as an argument to the node or something like that. That probably may be not the cleanest approach, but it would seem like it should work.

For me the os.getcwd() call returned the workspace directory.

magladko gravatar image magladko  ( 2023-07-06 08:20:17 -0600 )edit

Ok that's weird approach, it's something but still looking for an answer. Thank you for your answer tho.

klaudiusz.s1405 gravatar image klaudiusz.s1405  ( 2023-07-06 11:12:49 -0600 )edit