Error : Package 'topic_publisher_pkg' not found

Hi,

I am stuck at the end of Exercise 3.1 Topic Publishers.

I created a new package,
then created the cpp file in the corresponding folder,
then created a launch file in a launch folder (in the package folder) (I am not so sure where this file is supposed to be…).
image

I compiled the package and it seemed to work :

user:~/ros2_ws$ colcon build --packages-select topic_publisher_pkg
Starting >>> topic_publisher_pkg
Finished <<< topic_publisher_pkg [17.3s]

But, when I try to launch the programm I get this error :

user:~/ros2_ws$ ros2 launch topic_publisher_pkg simple_topic_publisher.launch.py
Package ‘topic_publisher_pkg’ not found: “package ‘topic_publisher_pkg’ not found, searching: [‘/home/simulations/ros2_sims_ws/install/move_robot_as’, ‘/home/simulations/ros2_sims_ws/install/t3_action_msg’, ‘/home/simulations/ros2_sims_ws/install/services_pkg’, ‘/home/simulations/ros2_sims_ws/install/parameter_tests’, ‘/home/simulations/ros2_sims_ws/install/neo_simulation2’, ‘/home/simulations/ros2_sims_ws/install/aws_robomaker_small_warehouse_world’, ‘/opt/ros/humble’]”

Can you please help me with this issue ?

Thanks for the feedback.

Vincent

Hi,

Can you paste the Cmakelist.txt contents?
Did you source after compiling?
Does the double tab autocomplete the package?

Hello duckfrost2,
Thanks for your help.

Below is the Cmakelist.txt
I dit source after compiling.
I don’t get your last question… :sweat_smile:

cmake_minimum_required(VERSION 3.8)
project(topic_publisher_pkg)

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

find dependencies

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

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)

the following line skips the linter which checks for copyrights

comment the line when a copyright and license is added to all source files

set(ament_cmake_copyright_FOUND TRUE)

the following line skips cpplint (only works in a git repo)

comment the line when this package is in a git repo and when

a copyright and license is added to all source files

set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()
add_executable(simple_publisher_node src/simple_topic_publisher.cpp)
ament_target_dependencies(simple_publisher_node rclcpp std_msgs)

install(TARGETS
simple_publisher_node
DESTINATION lib/${PROJECT_NAME}
)

Install launch files.

install(DIRECTORY
launch
DESTINATION share/${PROJECT_NAME}/
)
ament_package()

Hi @vincent.begoc,

Regarding the double tab referred by @duckfrost2, this pertains to an action in your Command Line Interface (CLI) from which once you are to input a package that you are unsure of, ROS2 has this feature or functionality that allows for the autocompletion of file names within a specific directory. So in this case, if you are able to see your package “pop-up” into the CLI after performing a double tab, I believe this impilies that your package is available and has been detected by your system.

Regards,
Christian

Greetings once again, @vincent.begoc!

I noticed that your package is inside the workspace folder itself, ros2_ws. I believe this should be created within the /src folder instead.

Please do try navigating to your /src folder and then run the syntax “ros2 pkg create topic_publisher_pkg --build-type dependency_1 dependency_2 dependency_n”

Hope this helps!

Kind regards,
Christian

Thanks CCAnabeza,
I did the correction you suggested (after suppressing the /ros2_ws/build/ folder and the topic_publisher_pkg folder) and it works now.
Many thanks for your help !
Vincent

1 Like

All the best, @vincent.begoc!

Glad I could help.

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