Failed to create custom ROS2 message

17 views (last 30 days)
JLepers
JLepers on 20 Nov 2019
Answered: Cam Salzberger on 5 Dec 2019
But I have an error with: ros2genmsg(folderPath)
Error using ros.ros2.internal.validateMsg (line 17)
Invalid message format, package, or structure found during validation.
Ensure that custom message packages follow structure and
naming rules.
Error in ros2genmsg (line 72)
ros.ros2.internal.validateMsg(folderPath);
If I test my custom message in a ROS2 environment it works fine so I assume that my CMakeLists.txt and package.xml are setup correctly.
How can I know if the setup of my message package is correct. Is there an example available to show what I need to add to my CMakeLists.txt and package.xml file so that Matlab can create my custom message.
Thanks!
  2 Comments
Alessandro Melino
Alessandro Melino on 27 Nov 2019
Hello.
I got the same error trying to add this custom message:
#Name of file: CAN.msg
time timestamp
uint16 stdId
int32 extId
uint8[] data
It currently works on ROS as yours, so we have the same problem.
Did you find any solution?
Best regards.
Alessandro
JLepers
JLepers on 27 Nov 2019
Be sure to have a correct workfolder layout.
I would use something like : project > model > custom_msgs > CAN.msg
Be sure to use lower case letters in your path (only the msg file can have a capital letter).
In matlab open the project workspace and use following code:
folderPath = fullfile(pwd,"model");
ros2genmsg(folderPath)
My mistake was that I used capital letters.
Good luck!

Sign in to comment.

Answers (1)

Cam Salzberger
Cam Salzberger on 5 Dec 2019
ROS 2 has more strict rules about package, message, and field names than ROS did. Relevant here, fieldnames need to be all lowercase, except constants, message packages must be lowercase, message names must start with upper case, among other rules.
You also don't need to write your own package.xml and CMakeLists.txt files. MATLAB will generate those for you based on the message definitions.
If you check out the example here, it shows example custom message packages and the workflow. You can also look at the built-in message definitions for more extensive examples of message files.
-Cam

Categories

Find more on Custom Message Support in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!