Creating Custom ROS2 message types for simulink

4 views (last 30 days)
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

Andre Below
Andre Below on 20 Apr 2022
Edited: Andre Below on 20 Apr 2022
For the peeps out there with similar problems:
Solution that worked for me (Matlab 2022a, Ros Toolbox version 1.5, ROS2 Foxy):
  1. Installed Ros2 on Windows (https://docs.ros.org/en/foxy/Installation/Windows-Install-Binary.html)
  2. Then created a new package (https://docs.ros.org/en/foxy/Tutorials/Custom-ROS2-Interfaces.html)
  3. Created a msg folder in the new package, as descriped here: (https://de.mathworks.com/help/ros/ref/ros2genmsg.html)
  4. pasted my massages into the new folder (https://github.com/ROBOTIS-GIT/turtlebot3_msgs/tree/master/msg)
  5. used the script:
% path to the custom packages:
msgpath = fullfile('C:\','dev','ros2_foxy','custom');
% read the msgs from the packages in the path:
ros2genmsg(msgpath)

More Answers (1)

Josh Chen
Josh Chen on 30 Mar 2022
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
Andre Below on 4 Apr 2022
Hello,
yes i alrady walk through the linked example. guess i have to install ROS2 Foxy with a custom created package with colcon with my desired msg files just to import them..
thanks for your help

Sign in to comment.

Categories

Find more on ROS 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!

Translated by