ROS2 Only able to run built packages from install/
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
I am only able to run my packages in other terminals when I go to my workspace/install/
Also I've tried many times to run . install/setup.bash from my workspace directory but I keep getting that either the localsetup.bash does not exist so - I then proceeded to copy the localsetup.bash to where it is needed. afterwards I then copied localsetuputilsh.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()
Asked by rover_challenger on 2021-04-29 14:18:30 UTC
Answers
This might be of some help: ROS2 Foxy, Creating a Workspace, 'Overlay'
You might try removing all of the build artifacts and rebuilding.
- Open a new terminal.
- Navigate to your workspace:
cd ~/ros2_ws
- Remove everything except for the source code (src/):
rm -rf ./build/ ./install/ ./log/
- 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)
- Use Colcon to rebuild the project:
colcon build
- You should now have fresh directories in your workspace. Running
ls
should show...build/ install/ log/ src/
. - Source your project's specific Setup.bash file:
source ./install/setup.bash
. For information on this see my link above. - 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
).
Asked by Spectre on 2021-05-08 17:26:41 UTC
Comments
@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 readAsked by jayess on 2021-04-29 17:01:31 UTC
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 toshare/${PROJECT_NAME}
instead oflib/${PROJECT_NAME}
. Could be worth trying to quickly change that line, rebuild, and see if you can properly source your packages?Asked by shonigmann on 2021-04-30 12:50:40 UTC