[ROS Q&A] 163 – Custom message fails to build: No such file or directory

[ROS Q&A] 163 – Custom message fails to build: No such file or directory

Learn how to solve a common error “No such file or directory” when compiling a package that contains a custom message. This post answered the following question on ROS Answers:  https://answers.ros.org/question/306884/custom-message-fails-to-build-no-such-file-or-directory/.


Related Resources


Step 1: Get your development environment ready

Either of the following will do:

  1. Use the ROS Development Studio (ROSDS), an online platform for developing for ROS within a PC browser. Easy-peasy. I’m using this option for this post
    1. Once you log in, click on the New ROSject button to create a project that will host your code. Then Click on Open ROSject to launch the development/simulation environment.
    2. To open a “terminal” on ROSDSpick the Shell app from the Tools menu.
    3. You can find the IDE app on the Tools menu.
  2. You have ROS installed on a local PC. Okay, skip to Step 2.

Next step!

Step 2: Create a package as specified in the question to reproduce the problem

1. If you are working on ROSDS, please create a ROSject first, as indicated above.

2. Open a terminal and create a package:

user:~$ cd catkin_ws/src
user:~/catkin_ws/src$ catkin_create_pkg custom_msg rospy roscpp
Created file custom_msg/CMakeLists.txt
Created file custom_msg/package.xml
Created folder custom_msg/include/custom_msg
Created folder custom_msg/src
Successfully created files in /home/user/catkin_ws/src/custom_msg. Please adjust the values in package.xml.

3. Create a custom message

user:~/catkin_ws/src$ cd custom_msg/
user:~/catkin_ws/src/custom_msg$ mkdir -p msg
user:~/catkin_ws/src/custom_msg$ cd msg
user:~/catkin_ws/src/custom_msg/msg$ touch my_msg.msg
user:~/catkin_ws/src/custom_msg/msg$

4. Open the IDE and paste the following into my_msg.msg:

int32 my_int
float64 my_float

5. Add the following line to package.xml

<build_depend>message_generation</build_depend>
<exec_depend>message_runtime</exec_depend>

6. Create a source file.

user:~/catkin_ws/src/custom_msg/msg$ cd ../src
user:~/catkin_ws/src/custom_msg/src$ touch custom_msg.cpp
user:~/catkin_ws/src/custom_msg/src$

Add the following to custom_msg.cpp using the IDE: just a reference to the custom message and an empty main function.

#include <custom_msg/my_msg.h>

int main() { return 0; }

7. Edit CMakeLists.txt as follows

– In find_package, add std_msgs and message_generation:

find_package(catkin REQUIRED COMPONENTS 
    roscpp 
    rospy
    std_msgs 
    message_generation
)

– Uncomment and replace add_message_fileswith the following:

add_message_files(
  FILES
  my_msg.msg
)

– Uncomment generate_messages and replace with:

generate_messages(DEPENDENCIES std_msgs )

– Replace catkin_package with the following:

catkin_package(CATKIN_DEPENDS rospy roscpp message_runtime)

– Add these lines under the build section to register the executable for building:

add_executable(custom_msg src/custom_msg.cpp)
target_link_libraries(custom_msg ${catkin_LIBRARIES})

8. Try to build the package

user:~/catkin_ws$ catkin_make

This ends up with the following error

home/user/catkin_ws/src/custom_msg/src/custom_msg.cpp:1:31: fatal error: custom_msg/my_msg.h: No such file or directory
compilation terminated.

Done here. We are able to reproduce the error. Now let’s fix it.

Step 3: Fix the problem and rejoice!

The above error says it cannot find the header file while building the C++ source. This is because we have not specified that this header file is a dependency and should be built first.

Add the following line to the build section of CMakeLists.txt (under the lines added earlier). The format is add_dependencies(source_file_name package_name_generate_messages_cpp).

add_dependencies(custom_msg custom_msg_generate_messages_cpp)

Compile again and it should be, “voila!”:

user:~/catkin_ws$ rm -rf build/ devel/
user:~/catkin_ws$ catkin_make

I’m outta here :).

Extra: Video of the post

Here below you have a “sights and sounds” version of this post, just in case you prefer it that way. Enjoy!

Feedback

Did you like this post? Do you have any questions about the explanations? Whatever the case, please leave a comment on the comments section below, so we can interact and learn from each other.

If you want to learn about other ROS or ROS2 topics, please let us know in the comments area and we will do a video or post about it.


Edited by Bayode Aderinola

[ROS Q&A] 162 – roslaunch file contains multiple nodes named [/map_server]

[ROS Q&A] 162 – roslaunch file contains multiple nodes named [/map_server]

 

In the following video, we are going to show how to solve the common error of “roslaunch file contains multiple nodes named [/whatever]”.

RELATED LINKS

Robot Ignite Academy
ROS Development Studio (ROSDS)
Original Question

Feedback

Did you like this video? Do you have questions about what is explained? Whatever the case, please leave a comment on the comments section below, so we can interact and learn from each other.

If you want to learn about other ROS topics, please let us know on the comments area and we will do a video about it.

[ROS Q&A] 160 – My node doesn’t publish to the topic cmd_vel

[ROS Q&A] 160 – My node doesn’t publish to the topic cmd_vel

In the following video, we are going to show how to properly publish into the topic cmd_vel, using Python classes:

RELATED RESOURCES:

Robot Ignite Academy
ROS Development Studio (ROSDS)
Original Question


We Love Feedback

Did you like this video? Do you have questions about what is explained? Whatever the case, please leave a comment on the comments section below, so we can interact and learn from each other.

If you want to learn about other ROS topics, please let us know on the comments area and we will do a video about it.

How to use rqt_console for debugging in ROS

How to use rqt_console for debugging in ROS

Learn how to use rqt_console for debugging by setting the logger level for ROS nodes. We’ll see some sample messages generated, including that of a turtle, which we will intentionally run into a wall!

Let’s go!

Step1: Create an account and/or Login to Robot Ignite Academy (RIA)

On RIA, you get access to the best online ROS courses and environment. No need to install and set up ROS locally – the only thing you need is a browser!

  • Create an account and/or login here.
  • Launch the ROS Basics in 5 Days Python course.
  • You’ll now have access to the simulation screen with a Notebook, an Editor, four Shells, a Simulation Window, and a Graphical Interface. We are only using the Graphical Interface and Shells for this demo.

Step 2: Launch rqt_console and related commands

Start the RQT tools and a Turtle:

  1. On Shell #1, run rqt_console: user:~$ rosrun rqt_console rqt_console
  2. On Shell #2, run rqt_logger_level: user:~$ rosrun rqt_logger_level rqt_logger_level
  3. On Shell #3, run  turtlesim_node:  user:~$ rosrun turtlesim turtlesim_node

Cannot see much output yet? Not to worry! Now click on the computer monitor icon to the right of the Editor screen to open the Graphical Tools app.

Open the Graphical Tools

Open the Graphical Tools

You should see a screen shown below:

rqt_console Debugging Screens

rqt_console Debugging Screens

The three windows shown above are the ones we launched on Shells #1-3 earlier.

  • The rqt_console window shows messages from the current node being debugged, based on the Severity level set.
  • The rqt_logger_level is where the Severity (or Verbosity or Logger) level is actually set for each node.
  • The TurtleSim window shows the “scapeturtle” we’re using for experiments in this post 😀 .

The current Severity for the /turtlesim node is Info, as you can see from the image. Let’s change that.

  1. Focus the rqt_logger_level window by clicking on it.
  2. Click on the “Refresh” button under the Nodes lists. You should see the /turtlesim node appear now.
  3. Select /tutlesim from the Nodes lists. Looking at the Levels list, you’ll see that “Info” is selected for this node by default.
  4. Change the Level from “Info” to “Debug” and observe the changes on the rqt_console screen. What did you notice? Too many messages among other things!
rqt_console - Before Changing Logger Level

rqt_console – Before Changing Logger Level

 

rqt_console - After Changing Logger Level

rqt_console – After Changing Logger Level

Perhaps everything has been a bit boring till now, so now let’s move to the fun part – run the “scapeturtle” into a wall!

  1. Change the Level to “Warn” in the rqt_logger_level window.
  2. Clean all current messages on the rqt_console window by clicking on the brush icon.
  3. On Shell #4, run the keyboard teleop in order to control the turtle: user:~$ rosrun turtlesim turtle_teleop_key
  4. Keeping the Shell #4 active, use the keyboard to move the turtle forward for a few seconds, so that it runs into the wall!

Now go back to the Graphical Tools window, you should have something like this:

rqt_console - ScapeTurtle runs into a Wall!

rqt_console – ScapeTurtle runs into a Wall!

So you finally ran the turtle into a wall…move to the next section for the verdict!

Step 3: Master the Concept: rqt_console and Logger Levels

rqt_console is for viewing the messages from nodes according to the verbosity level, which is set with rqt_logger_level.

Here are key points to note about the Levels:

  • Debug is the lowest level, and Fatal is the highest.
  • The lower levels usually have more messages than the higher ones. In fact, we would prefer not to see messages from levels like Error and Fatal!
  • Each Level will also show messages from the Levels below it. For example, we would still get the Warn messages on Info level. (Try it out!)

Read more above the Levels at: http://wiki.ros.org/Verbosity%20Levels

And that’s it!

Extra: Video

Prefer to see the ‘sights and sounds’ version of this post? We made this video just for you!

Feedback

If you are interested in this topic, please check our ROS Basics in 5 Days course where you’ll learn more about the debugging tools available in ROS.

Did you like this post? Please leave a comment on the comments section below, so we can interact and learn from each other.

Thank you!

[ROS Q&A] 159 – How to create a Restricted Area on a Map

[ROS Q&A] 159 – How to create a Restricted Area on a Map

In the following video, we are going to show how to create a restricted area (the robot cannot go in) in a Map generated with gmapping.

RELATED LINKS

Robot Ignite Academy
ROS Development Studio (ROSDS)
Original Question

We love feedback!

Did you like this video? Do you have questions about what is explained? Whatever the case, please leave a comment on the comments section below, so we can interact and learn from each other.

If you want to learn about other ROS topics, please let us know on the comments area and we will do a video about it.

Pin It on Pinterest