I’m in section 4 of the rosject for ROS2 Navigation. I have successfully recorded coordinate information about different points around the map to a file called spots.yaml.
After submitting this command:
ros2 run project_path_planning move_to_spot --ros-args --params-file spots.yaml -p spot_name:=corner1
I get this error:
user:~/ros2_ws$ ros2 run project_path_planning move_to_spot --ros-args --params-file spots.yaml -p spot_name:=corner1[ERROR] [1713052429.485647395] [rcl]: Failed to parse global arguments
Traceback (most recent call last):
File "/home/user/ros2_ws/install/project_path_planning/lib/project_path_planning/move_to_spot", line 33, in <module>
sys.exit(load_entry_point('project-path-planning==0.0.0', 'console_scripts', 'move_to_spot')())
File "/home/user/ros2_ws/install/project_path_planning/lib/python3.10/site-packages/project_path_planning/move_to_spot.py", line 53, inmain
rclpy.init(args=None)
File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/__init__.py", line 89, in init
return context.init(args, domain_id=domain_id)
File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/context.py", line 72, in init
self.__context = _rclpy.Context(
rclpy._rclpy_pybind11.RCLError: failed to initialize rcl: Couldn't parse params file: '--params-file spots.yaml'. Error: Error opening YAML file, at ./src/parser.c:270, at ./src/rcl/arguments.c:406
[ros2run]: Process exited with failure 1
I need some help understanding what this error is trying to tell me and how I can go about fixing it.
As constructsim.com has taught me, I run this command every time I build a package (and also in every terminal)
source ~/ros2_ws/install/setup.bash
This was something I considered as well. I made sure the file had full permissions.
user:~/ros2_ws/src/project_path_planning/config$ ls -l
total 24
-rw-r--r-- 1 user user 1294 Mar 29 23:47 behavior.xml
-rw-r--r-- 1 user user 2096 Mar 29 23:50 bt_navigator.yaml
-rw-r--r-- 1 user user 1951 Mar 29 23:47 controller.yaml
-rw-r--r-- 1 user user 262 Mar 30 00:51 planner_server.yaml
-rw-r--r-- 1 user user 570 Mar 29 23:47 recovery.yaml
-rwxrwxrwx 1 user user 351 Apr 14 00:08 spots.yaml
user:~/ros2_ws$ source ~/ros2_ws/install/setup.bash
user:~/ros2_ws$ python3 -c 'import yaml; print(yaml.safe_load(open("spots.yaml")))'
Traceback (most recent call last):
File "<string>", line 1, in <module>
FileNotFoundError: [Errno 2] No such file or directory: 'spots.yaml'
user:~/ros2_ws$ python3 -c 'import yaml; print(yaml.safe_load(open("~/ros2_ws/src/project_path_planning/config/spots.yaml")))'
Traceback (most recent call last):
File "<string>", line 1, in <module>
FileNotFoundError: [Errno 2] No such file or directory: '~/ros2_ws/src/project_path_planning/config/spots.yaml'
user:~/ros2_ws$
How does your command know where to look for “spots.yaml”? I thought that the file path might be missing from your command so I tried it with the direct file path to “spots.yaml” but still got the same error. I don’t understand the error this command produced. The file exists and I think its in the right directory.
ros2 run project_path_planning move_to_spot --ros-args --params-file /home/user/ros2_ws/project_path_planning/config/spots.yaml -p spot_name:=corner1
and it works.
What this tells me is that my spots.yaml file is not in the default place that this command line is looking for. Where is the default location for this parameter file?
When a compiled ROS2 package is launched or run, it will look for all its dependent files in the install directory.
So the file path should actually be:
It is strange to me that your package is looking for the spots.yaml file in the following path:
This is of course conditioned on the setup.py (for Python package) or the CMakeLists.txt file (for C++ package).
You should have included the config folder path in the setup.py or CMakeLists.txt file to be installed when the package is built.
You will have something similar to the following lines:
If using setup.py:
Do you have any other suggestions? A solution to this question is not critical as I have found a way around the problem. If the topic/post needs to be closed, I understand.
I am not exactly sure why your run command requires the path to the spots.yaml file specified in a different (unconventional) way. It is still strange to me.
What was the output that you got when you executed the command above with the path I referenced? This following command should work after proper compilation.
ros2 run project_path_planning move_to_spot --ros-args --params-file /home/user/ros2_ws/install/project_path_planning/share/project_path_planning/config/spots.yaml -p spot_name:=corner1
Perhaps you can try compiling from scratch by removing build, install and log folders and that could fix your issue.
Your command successfully called the action server. I wasn’t fast enough to copy the output before the feedback from the server filled the terminal window.
Deleting the install and build folders did not fix the problem.
I’ll continue to use:
ros2 run project_path_planning move_to_spot --ros-args --params-file /home/user/ros2_ws/src/project_path_planning/config/spots.yaml -p spot_name:=corner1