Creating Custom ROS2 message types for simulink

4 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Andre Below
Andre Below il 20 Apr 2022
Modificato: Andre Below il 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)

Più risposte (1)

Josh Chen
Josh Chen il 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 Commenti
Josh Chen
Josh Chen il 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
Andre Below il 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

Accedi per commentare.

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by