0
$\begingroup$

I am building a package and receive the correct output that you would expect for a package:

Starting >>> controllers Finished <<< controllers [7.45s] Summary: 1 package finished [7.69s] 

I open a new terminal, source my ROS 2 installation (/opt/ros/humble/setup.bash), source my package (install/setup.bash), and I try to run the only node that is in the package (pi_node) with the following command:

ros2 run controllers pi_node 

But I receive the following error:

Package 'controllers' not found 

Also, autocomplete is not working. I have been deleting my workspace and retrying, but there is nothing that solves the issue, and I don't know what else could be failing. My CMakeLists.txt looks like this:

cmake_minimum_required(VERSION 3.8) project(controllers) find_package(Eigen3 3.4 REQUIRED NO_MODULE) find_package(ament_cmake REQUIRED) find_package(rclcpp REQUIRED) find_package(geometry_msgs REQUIRED) find_package(turtlesim REQUIRED) include_directories(include) if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-Wall -Wextra -Wpedantic) endif() add_executable(pi_node src/pi_node.cpp include/control/controller.hpp include/control/pi_controller.hpp) ament_target_dependencies(pi_node rclcpp turtlesim geometry_msgs) target_link_libraries(pi_node Eigen3::Eigen) install(TARGETS pi_node DESTINATION lib/${PROJECT_NAME}) ament_package() 

The content of my package.xml file is:

<?xml version="1.0"?> <?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?> <package format="3"> <name>controllers</name> <version>0.0.0</version> <description>TODO: Package description</description> <maintainer email="[email protected]">pablo</maintainer> <license>TODO: License declaration</license> <depend>rclcpp</depend> <depend>std_msgs</depend> <depend>geometry_msgs</depend> <depend>turtlesim</depend> <export> <build_type>cmake</build_type> </export> </package> 
$\endgroup$
7
  • $\begingroup$ is your package listed when using the command ros2 pkg list | grep controllers ? $\endgroup$ Commented May 9, 2024 at 11:00
  • $\begingroup$ @JakubIvan Nope $\endgroup$ Commented May 9, 2024 at 15:40
  • 1
    $\begingroup$ Please post your package.xml since e.g. ros2 run queries the ament index to find packages. $\endgroup$ Commented May 17, 2024 at 16:07
  • $\begingroup$ The best way to get help on this is to create a MCVE stackoverflow.com/help/mcve so that everything is available for people to help you with. $\endgroup$ Commented May 17, 2024 at 19:00
  • 3
    $\begingroup$ Since you're creating a “ament CMake” package the build type should be <build_type>ament_cmake</build_type>. More information about ament (and other build types) and its functionality can be found in the design article - Integrate arbitrary build systems. ament_cmake automatically writes to the ament resource index at build time and thus provides efficient access to information like the available packages, messages, etc at runtime. $\endgroup$ Commented May 17, 2024 at 22:25

4 Answers 4

1
$\begingroup$

Since you want to create a “ament CMake” package (use of ament_cmake with ament_package() in CMakeLists.txt) you also need to set ament_cmake for build_type in the export section of the package.xml because defining cmake indicates a plain CMake package without all the automatic ament magic (it calls e.g. ament_index_register_resource for you).
More information about ament (and other build types) and its functionality can be found in the design article - Integrate arbitrary build systems. ament_cmake automatically writes to the ament resource index at build time and thus provides efficient access to information like the available packages, messages, etc at runtime.

Added my initial answer from above as requested so that this question can be marked as answered.

$\endgroup$
1
$\begingroup$

Solution from Bi0T1N's comment solved the problem. Build type was lacking in the package.xml.

$\endgroup$
0
$\begingroup$

Can you try excluding headers in add_executable?

add_executable(pi_node src/pi_node.cpp) 
$\endgroup$
1
  • $\begingroup$ The issue is not related to the compilation, since the compilation is successful. $\endgroup$ Commented May 24, 2024 at 6:47
0
$\begingroup$

Can you try sourcing the workspace once build is done and run the executable.

source install/setup.bash

$\endgroup$
1
  • $\begingroup$ Please re-read the post. There I indicate that I have sourced the workspace. $\endgroup$ Commented May 24, 2024 at 6:46

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.