Creating Custom ROS2 message types for simulink
Show older comments
Hello everyone,
i am currently trying to subscribe a topic with the ROS2 subscribe block. The problem is, the message type of the topic gets not detectet when i choose the topic. See pic 1.

I already tried to select message types from the list "ros2 msg list". How can i add my own message type to the list? Or: What i have to do, that the /sensor_state topic sees the correct type?
My Matlab Version is 2022a. ROS Toolbox Version is 1.5. ROS2 Version is foxy. I allready tried ros2message(msgtype), but i dont know where i have to use the freshly created message.
i would much appreciate your answers.
Accepted Answer
More Answers (1)
Josh Chen
on 30 Mar 2022
0 votes
Hello Andre,
When running "ros2 msg list", are you able to see the custom message you are trying to use? If not, you would need to follow this documentation page to generate the custom message using ros2genmsg.
After generating the custom message, you should be able to create a message in MATLAB with ros2message(msgType), where msgType is the message type of your custom message.
If you are able to create such message in MATLAB, you can then go back to the ROS2 Subscribe block, choose "Specify your own" as the "Topic source", and select the newly created custom message in the pop-up window for "Message type".
Hope this helps,
Josh
5 Comments
Andre Below
on 1 Apr 2022
Edited: Andre Below
on 1 Apr 2022
Josh Chen
on 1 Apr 2022
Hi Andre,
I think you are very close to get it work now!
Unfortunately, MinGW64 is not supported in ROS Toolbox. If you are working with Foxy, please consider to use Visual Studio 2019 instead. This page listed out all system requirements for ROS Toolbox. As for python version, I think 3.9 is the correct version.
Best,
Josh
Andre Below
on 4 Apr 2022
Edited: Andre Below
on 4 Apr 2022
Josh Chen
on 4 Apr 2022
Hi Andre,
Have you tried to walk through the example on this documentation page? If you haven't, I would highly recommand to try this out. This should clarify questions related to folder structure and proper path. The custom message need to follow the same pattern as shown in the example.
Given the one-line error message you posted, I suspect the input path to ros2genmsg might be incorrect. Please feel free to reach out to MathWorks Technical Support team if you need help walking through this.
ros2genmsg is the only way to generate custom messages for ROS 2. ros2message will only create ROS 2 message structure successfully after you use ros2genmsg to generate custom messages. There is no such function as "ros2massage" though.
Thanks,
Josh
Andre Below
on 4 Apr 2022
Categories
Find more on Get Started with ROS Toolbox 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!