本文介绍 ROS-2 Personize your message in ros

ROS-2 Personize your message in ros

This article was original written by Jin Tian, welcome re-post, first come with https://jinfagang.github.io . but please keep this copyright info, thanks, any question could be asked via wechat: jintianiloveu

0. Definite Your Message

this part, we will explore how to write our own messages. Before it, I have to mention that, in other companies such as Baidu, they prefer using Protobuf as their message library, but I don’t think this is a good idea. As ros official has a system to organize there messages. The process of create a personized message is:

  • Add a YourMsgName.msg file in msg folder in your package;
  • Add these in CMakeLists.txt;
  • catkin_make and generate your message in devel folder

OK, this is it. Personize your message are so simple, but let’s see how to write it exactly:

1
2
3
string messageContent
float32 speedLeft
float32 speedRight

this an example of message. By using this, you will have your own message type.

1. Using Your Message in C++

OK, let’s explore how to using this message in C++.