ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Roslaunch: file not found error for logging

asked 2022-06-15 16:49:17 -0500

Mix_MicDev gravatar image

Hi, I am working on a project, and I want to start the different nodes using a launch file. In the latter I start one Python node and the other is an rqt plugin that I created:

<launch>
    <node name="PiMaster_node" pkg="airplane_master" type="PiMaster.py" output="screen"/>
    <node name="airplane_master" pkg="airplane_master" type="airplane_master"/>
</launch>

My problem is that when I run the two scripts separately using rosrun, everything works perfectly, but when I use roslaunch to start my .launch file I get this error:

Traceback (most recent call last):
  File "/home/micdev/catkin_ws/devel/lib/airplane_master/PiMaster.py", line 15, in <module>
    exec(compile(fh.read(), python_script, 'exec'), context)
  File "/home/micdev/catkin_ws/src/airplane_master/scripts/PiMaster.py", line 21, in <module>
    logging.basicConfig(filename='src/airplane_master/src/airplane_master/Master.log', level=logging.ERROR,
  File "/usr/lib/python3.8/logging/__init__.py", line 1988, in basicConfig
    h = FileHandler(filename, mode)
  File "/usr/lib/python3.8/logging/__init__.py", line 1147, in __init__
    StreamHandler.__init__(self, self._open())
  File "/usr/lib/python3.8/logging/__init__.py", line 1176, in _open
    return open(self.baseFilename, self.mode, encoding=self.encoding)
FileNotFoundError: [Errno 2] No such file or directory: '/home/micdev/.ros/src/airplane_master/src/airplane_master/Master.log'

Basically it says that it couldn't find a Log file (that actually exists): I use the logging module in Python to log some infos in Master.log file... Maybe it is interacting with the ROS logger? If this is the case why doesn't it happen when I run the python file using rosrun? Can someone help me, I'm stuck :(

Thanks in advance!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-06-16 01:56:31 -0500

gvdhoorn gravatar image

updated 2022-06-16 01:56:56 -0500

FileNotFoundError: [Errno 2] No such file or directory: '/home/micdev/.ros/src/airplane_master/src/airplane_master/Master.log'

Note how the path is /home/micdev/.ros/....

Is that where your log file is located?

Please note that when starting nodes using roslaunch, their working directory is set to $ROS_HOME, which in many cases is set to $HOME/.ros. In your case probably /home/micdev/.ros.

See #q235337, #q271442 and the linked Q&As there for more information.

Summarising: make sure you use absolute paths, not relative paths, or your scripts won't be able to find files they need.

edit flag offensive delete link more

Comments

Thank you for your answer! I am now using absolute paths like you said, and it's working. Here's how I'm finding the path of the file inside the Python code:

file_name = os.path.join(rospkg.RosPack().get_path('package_name'), 'file_directory', 'file_name')

Just to make sure, that's what you meant by "absolute paths" right?

Mix_MicDev gravatar image Mix_MicDev  ( 2022-06-16 16:11:37 -0500 )edit

I would personally probably use a param as a child of the node and use substitution args to have roslaunch construct the path for me. Your node would then just have to read the parameter from the parameter server.

gvdhoorn gravatar image gvdhoorn  ( 2022-06-17 09:31:16 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2022-06-15 16:49:17 -0500

Seen: 500 times

Last updated: Jun 16 '22