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

Ros2 Custom message tutorial: No such file or directory

asked 2021-01-25 17:07:56 -0500

nm456 gravatar image

I am trying to follow the ros2 custom message tutorial here:, but I'm having problems compiling the example, this is on Ros2 Foxy on ubuntu 20.0.4

I'm using the custom message file Pulsecommand.msg:

int64 Pulse
int8 Heading

I have 2 packages, 1 called nmb_motor_llc, in which I have a subscriber that I'd like to recieve this custom message, as well as nmb_interfaces, which contains the custom message types.

Here is the code for the subscriber (it is identical to the tutorial other than the line
#include "nmb_interfaces/msg/Pulsecommand.hpp"
which gives me the error "fatal error: nmb_interfaces/msg/Pulsecommand.hpp: No such file or directory"

#include <functional>
#include <memory>

#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"
#include "nmb_interfaces/msg/Pulsecommand.hpp"

using std::placeholders::_1;

class MinimalSubscriber : public rclcpp::Node
{
public:
  MinimalSubscriber()
  : Node("minimal_subscriber")
  {
    subscription_ = this->create_subscription<std_msgs::msg::String>(
      "topic", 10, std::bind(&MinimalSubscriber::topic_callback, this, _1));
  }

private:
  void topic_callback(const std_msgs::msg::String::SharedPtr msg) const
  {
    RCLCPP_INFO(this->get_logger(), "I heard: '%s'", msg->data.c_str());
  }
  rclcpp::Subscription<std_msgs::msg::String>::SharedPtr subscription_;
};

int main(int argc, char * argv[])
{
  rclcpp::init(argc, argv);
  rclcpp::spin(std::make_shared<MinimalSubscriber>());
  rclcpp::shutdown();
  return 0;
}

Below is the CMakeList and package.xml for the nmb_interfaces package:

CMakelist.txt:

cmake_minimum_required(VERSION 3.5)
project(nmb_interfaces)

# Default to C99
if(NOT CMAKE_C_STANDARD)
  set(CMAKE_C_STANDARD 99)
    endif()

    # 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 dependencies
find_package(ament_cmake REQUIRED)
find_package(rosidl_default_generators REQUIRED)

rosidl_generate_interfaces(${PROJECT_NAME}
    "msg/Pulsecommand.msg"
  ) 
# uncomment the following section in order to fill in
# further dependencies manually.

# find_package(<dependency> REQUIRED)

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  # the following line skips the linter which checks for copyrights
  # uncomment the line when a copyright and license is not present in all source files
  #set(ament_cmake_copyright_FOUND TRUE)
  # the following line skips cpplint (only works in a git repo)
  # uncomment the line when this package is not in a git repo
  #set(ament_cmake_cpplint_FOUND TRUE)



 ament_lint_auto_find_test_dependencies()
endif()

ament_package()

and Package.xml:

<?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>nmb_interfaces</name>
  <version>0.0.0</version>
      <description>TODO: Package description</description>
      <maintainer email="ubuntu@todo.todo">ubuntu</maintainer>
      <license>TODO: License declaration</license>

      <buildtool_depend>ament_cmake</buildtool_depend>

      <test_depend>ament_lint_auto</test_depend>

      <test_depend>ament_lint_common</test_depend>

      <build_depend>rosidl_default_generators</build_depend>
      <exec_depend>rosidl_default_runtime</exec_depend>
      <member_of_group>rosidl_interface_packages</member_of_group>

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

Here is the CMakelists.txt and package.xml for nmb_motor_llc:

cmake_minimum_required(VERSION 3.5)
project(nmb_motor_llc)

# Default to C99
if(NOT CMAKE_C_STANDARD)
  set(CMAKE_C_STANDARD 99)
endif()

# 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 dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(nmb_interfaces REQUIRED)

find_package(std_msgs REQUIRED)


add_executable(pulse_listener src/pulse_listener.cpp)
ament_target_dependencies(pulse_listener rclcpp std_msgs nmb_interfaces)

# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)

install(TARGETS
    pulse_listener
    DESTINATION lib ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
3

answered 2021-01-26 14:52:16 -0500

ryan.delgizzi gravatar image

The line: #include "nmb_interfaces/msg/Pulsecommand.hpp" should probably be #include "nmb_interfaces/msg/pulsecommand.hpp"

The files generated from message generation are snake case.

edit flag offensive delete link more

Comments

This solved my problem! I spent two days debugging this. The docs should really state that the header filenames ARE NOT "cased" as your interface files.

cap10 gravatar image cap10  ( 2021-04-11 21:15:52 -0500 )edit
1

This solved my problem as well. In my case I had the equivalent of "msg/PulseCommand.msg". Note the capital "C" in command. For that case you would need #include "nmb_interfaces/msg/pulse_command.hpp". Note the addition of the underscore.

blbeggs gravatar image blbeggs  ( 2022-09-17 20:12:26 -0500 )edit

I was getting No such file or directory #include "geometry_msgs/msg/detail/point__struct.h" which was solved by adding DEPENDENCIES builtin_interfaces geometry_msgs to rosidl_generate_interfaces in my custom message package CMakeLists.txt

chives_onion gravatar image chives_onion  ( 2023-05-26 09:19:43 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2021-01-25 17:07:56 -0500

Seen: 6,206 times

Last updated: Jan 26 '21