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

ROS2 Only able to run built packages from install/

asked 2021-04-29 14:18:30 -0600

rover_challenger gravatar image

updated 2021-04-29 16:59:27 -0600

jayess gravatar image

Hello All,

I am new to ROS2 ( on ubuntu 20.04). I was following the tutorial and was able to spool up a pub/sub. However, when I open a new terminal (made sure to source /opt/foxy/setup.bash - put it in my bashrc) I am unable to run my packages. They do not show up. when I check the number of packages available in the terminal I ran colcon build by doing ros2 run <tab> it says would you like to show all 273 packages. When I open another terminal and try it again it says would you like to show all 253 packages.

I am only able to run my packages in other terminals when I go to my workspace/install/<package name=""> then execute the binary. How do I get ROS2 to be able to run these packages without CD to this folder every time then execute the binary. In ROS1 I never had this issue.

Also I've tried many times to run . install/setup.bash from my workspace directory but I keep getting that either the local_setup.bash does not exist so - I then proceeded to copy the local_setup.bash to where it is needed. afterwards I then copied _local_setup_util_sh.py as well. but I keep getting the error saying no such file or directory

/usr/bin/python3: can't open file '/home/niiquaye/ros2_foxy_training/install/rviz_ogre_vendor/_local_setup_util_sh.py': [Errno 2] No such file or directory

Here is my Cmakelist - sorry for the format I am not sure how to use the properly as it just puts all my code one line

cmake_minimum_required(VERSION 3.5)              
project(first_package)   

if(NOT CMAKE_C_STANDARD)   
  set(CMAKE_C_STANDARD 99)   
endif()   

if(NOT CMAKE_CXX_STANDARD)   
  set(CMAKE_CXX_STANDARD 14)   
endif()   

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")   
  add_compile_options(-Wall -Wextra -Wpedantic)   
endif()   

find_package(ament_cmake REQUIRED)   
find_package(rclcpp REQUIRED)   
find_package(std_msgs REQUIRED)   

add_executable(talker src/publisher_member_function.cpp)   
ament_target_dependencies(talker rclcpp std_msgs)   

add_executable(listener src/subscriber_member_function.cpp)   
ament_target_dependencies(listener rclcpp std_msgs)   

install(TARGETS   
  talker   
  listener   
  DESTINATION lib/${PROJECT_NAME})   

ament_package()
edit retag flag offensive close merge delete

Comments

1

@rover_challenger FYI you can use the preformatted text (1010101) button to format code/terminal output and this will preserve formatting and add syntax highlighting making the text easier to read. Using HTML elements (such as <code>) doesn't really render will on this site and makes the text wrapped in these elements difficult to read

jayess gravatar image jayess  ( 2021-04-29 17:01:31 -0600 )edit

I'll admit I don't know enough about CMake/Colcon/Ament to know for sure if this is anything important, but I've noticed that the CMakeLists.txt files in my packages install targets to share/${PROJECT_NAME} instead of lib/${PROJECT_NAME}. Could be worth trying to quickly change that line, rebuild, and see if you can properly source your packages?

shonigmann gravatar image shonigmann  ( 2021-04-30 12:50:40 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-05-08 17:26:41 -0600

Spectre gravatar image

This might be of some help: ROS2 Foxy, Creating a Workspace, 'Overlay'

You might try removing all of the build artifacts and rebuilding.

  1. Open a new terminal.
  2. Navigate to your workspace: cd ~/ros2_ws
  3. Remove everything except for the source code (src/): rm -rf ./build/ ./install/ ./log/
  4. Source the ROS2 setup.bash: source /opt/ros/foxy/setup.bash # In Bash, "source" is the same as '.' which corresponds to the "SH" shell (its predecessor)
  5. Use Colcon to rebuild the project: colcon build
  6. You should now have fresh directories in your workspace. Running ls should show... build/ install/ log/ src/.
  7. Source your project's specific Setup.bash file: source ./install/setup.bash. For information on this see my link above.
  8. You should now be able to run a module or launch file. ros2 run my_pkg node_in_pkg

Be sure to run that project-specific setup.bash!

When you source the base setup script (source /opt/ros/foxy/setup.bash) your current terminal session only knows about the pre-installed ROS2 packages and such located in /opt/ros/foxy/<blah>.

You need to make it aware of your package for you to be able to make use of it. That is done by sourcing your own setup script (source ros2_ws/install/setup.bash).

edit flag offensive delete link more

Question Tools

3 followers

Stats

Asked: 2021-04-29 14:18:30 -0600

Seen: 3,045 times

Last updated: May 08 '21