ROS2 python launch file always access underlay /opt/ros/foxy/share

Hey ROS Community,

i created a workspace and cloned the ros-planning/navigation2 github into my workspace. (I also have the nav2 in my underlay /opt/ros/foxy/share) Next i created a python launch file to run the navigation stack and other stuff. However, the python launch file always access my underlay nav2_params.yaml file in /opt/ros/foxy/share instead of my nav2_params.yaml in my workspace. I renamed the folder in my workspace from nav2_bringup (in /opt/ros/foxy) to robot_nav2_bringup (my src workspace)

My code:

nav2_launch_file_dir = os.path.join(get_package_share_directory('robot_nav2_bringup'), 'launch')

    IncludeLaunchDescription(
                PythonLaunchDescriptionSource([nav2_launch_file_dir, '/bringup_launch.py']),
                launch_arguments={
                    'map': map_dir,
                    'use_sim_time': use_sim_time}.items(),

Why the launch file always access the underlay /opt/ros/foxy/share? Maybe because of get_package_share_directory? What i have to do instead?

Thank you so much for you help :slight_smile: ),

Hello @trannamtruong98 ,

The code you show looks correct, so I don’t think the error comes from it. However, there could be many different reasons why this could happen.

  • Are you correctly sourcing your workspace so that it can be detected by the ROS2 system?
  • Have you correctly renamed the package? Or did you just rename the folder name?
  • And many others

Because you are in your local environment, it’s very hard for us to be more precise on this. My suggestion would be to remove the nav2 packages you have in /opt/ros... and leave only the packages in your workspace. This will allow you to better debug what’s going on.

1 Like

Hey Alberto,

first thank you so much for you answer. I really appreciate you help :slight_smile:
I can’t delete the underlay /opt/ros because i still need this.
I sourcing both the underlay /opt/ros and my workspace:
alias foxy2="source ~/robot_ws/install/setup.bash && source /opt/ros/foxy/setup.bash && source /usr/share/colcon_argcomplete/hook/colcon-argcomplete.bash; echo 'Foxy2 is Active'"

I’m confused because i named the folder robot_nav2_bringup of ros-planning/navigation2 in my src workspace but it still access the /opt/ros/foxy/share. It access the nav2_bringup folder in /opt/ros with the nav2_params.yaml file.

Weird :confused:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.