0
$\begingroup$

Rosanswers logo

I am trying to build 2 new nodes, based on the minimal_publisher and minimal_subscriber examples provided by the ros2_ws overlay workspace. I have copied and pasted my code from the examples, with the intention to change them in the near future.

I then changed the names of the source files, and the name of the package, among other names. To ensure a successful build, I made several corresponding changes to the CMakeLists.txt and package.xml of each package as well.

Both packages built successfully. However, the only way I can run them is if I locate the binary files in the install directory of the ros2_ws workspace and run them from there.

If I run ros2 pkg list or ros2 pkg executables, none of my packages show up there. Predictably, when I run ros2 run publisht tester_publisht (publisht is the name of my pkg and tester_publisht is the name of the executable) , it just shows Package 'publisht' not found.

Why is it that ros2 pkg cannot find my package?

My publisht package in the install directory of ros2_ws:

publisht
├── lib
│   └── publisht
│       └── tester_publisht
└── share
    ├── ament_index
    │   └── resource_index
    │       ├── package_run_dependencies
    │       │   └── publisht
    │       ├── packages
    │       │   └── publisht
    │       └── parent_prefix_path
    │           └── publisht
    ├── colcon-core
    │   └── packages
    │       └── publisht
    └── publisht
        ├── cmake
        │   ├── publishtConfig.cmake
        │   └── publishtConfig-version.cmake
        ├── environment
        │   ├── ament_prefix_path.sh -> /home/user/ros2_ws/src/ament/ament_cmake/ament_cmake_core/cmake/environment_hooks/environment/ament_prefix_path.sh
        │   └── path.sh -> /home/user/ros2_ws/src/ament/ament_cmake/ament_cmake_core/cmake/environment_hooks/environment/path.sh
        ├── hook
        │   ├── cmake_prefix_path.ps1
        │   └── cmake_prefix_path.sh
        ├── local_setup.bash
        ├── local_setup.sh
        ├── local_setup.zsh
        ├── package.bash
        ├── package.ps1
        ├── package.sh
        ├── package.xml
        └── package.zsh

My tester directory in ros2_ws/src, which contains the source code for the 2 nodes I intend to make, publisht and subscribet:

tester 
├── publisht
│   ├── CMakeLists.txt
│   ├── package.xml
│   ├── publisht.cpp
│   └── README.md
├── README.md
└── subscribet
    ├── CMakeLists.txt
    ├── package.xml
    ├── README.md
    └── subscribet.cpp

My CMakeLists.txt for publisht:

cmake_minimum_required(VERSION 3.5) 
project(publisht)

# Default to C++14
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(tester_publisht publisht.cpp)
ament_target_dependencies(tester_publisht rclcpp std_msgs)

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

ament_package()

And my package.xml for publisht:

<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="2">
  <name>publisht</name>
  <version>0.6.3</version>
  <description>Ready to publish to topics from selected nodes</description>
  <maintainer email="[email protected]">MAINTAINER</maintainer>
  <license>Apache License 2.0</license>
  <author>AUTHOR</author>

  <buildtool_depend>ament_cmake</buildtool_depend>

  <build_depend>rclcpp</build_depend>
  <build_depend>std_msgs</build_depend>

  <exec_depend>rclcpp</exec_depend>
  <exec_depend>std_msgs</exec_depend>

  <export>
    <build_type>ament_cmake</build_type>
  </export>
</package>

Originally posted by wan_da on ROS Answers with karma: 57 on 2019-06-10

Post score: 1


Original comments

Comment by wan_da on 2019-06-10:
Yes, it worked. My bad; I thought that since I sourced the setup.bash in my .bashrc I didn't need to source it again. Apparently I need to source it again after I built publisht.

Thank you very much.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Have you sourced the install/setup.bash file in the workspace where you built publish?


Originally posted by david.hodo with karma: 395 on 2019-06-10

This answer was ACCEPTED on the original site

Post score: 2

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.