[ROS in 5 mins] 024 – How to compile a ROS Message

How to compile a ROS Message

Written by Ruben Alves

14/08/2018

 

Hello ROS Developers!

In today’s video we are going to learn how to compile a ROS Message.

For that we are going to use Robot Ignite Academy, which is the best tool if you want Learn ROS Fast.

Before we start, if you are new to ROS and want to Learn ROS Fast, I highly recommend you to take any of the following courses on Robot Ignite Academy:

We love feedback, so, whether you like the video or not, please share your thoughts on the comments section below.

Step1. Create a project in Robot Ignite Academy(RIA)

We have the best online ROS course available in RIA. It helps you learn ROS in the easiest way without setting up ROS environment locally. The only thing you need is a browser! Create an account here and start to browse the trial course for free now! We’ll use the ROS Basic in 5 days course unit 4 as an example today.

Step2. Create a package

We’ll create a package for our code with the following command.

cd ~/catkin_ws/src
catkin_create_pkg financial_market rospy

We also need one folder for our message definition

cd financial_market
mkdir msg

Let’s call our message SharePrice.msg with the following definition

string name
float32 price

In the package.xml file, please uncomment the following part.

...
  <build_depend>message_generation</build_depend>
...
  <run_depend>message_runtime</run_depend>
...

In the CMakeLists.txt, change the following part to compile the message.

...
find_package(catkin REQUIRED COMPONENTS
  rospy
  std_msgs
  message_generation
)
...
add_message_files(
   FILES
   SharePrice.msg
#   Message2.msg
)
...
generate_messages(
   DEPENDENCIES
   std_msgs  # Or other packages containing msgs
)
...
catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES my_sense_package
  CATKIN_DEPENDS rospy message_runtime
#  DEPENDS system_lib
)
...

Then we compile the message with the following command

cd ~/catkin_ws
catkin_make

Please source the file after compile.

source devel/setup.bash

You can then check the message with

rosmsg info financial_market/SharePrice

In your python code, you can then add from financial_market.msg import SharePrice  to use the message.

Want to learn more?

If you are interested in this topic, please check our ROS Basics In 5 Days (Python) course. You’ll learn how to create service and action message in ROS as well.

 

Edit by: Tony Huang

Masterclass 2023 batch2 blog banner

Check Out These Related Posts

129. ros2ai

129. ros2ai

I would like to dedicate this episode to all the ROS Developers who believe that ChatGPT or...

read more

0 Comments

Submit a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Pin It on Pinterest

Share This