Creating Custom ROS2 message types for simulink

7 次查看(过去 30 天)
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.

采纳的回答

Andre Below
Andre Below 2022-4-20
编辑:Andre Below 2022-4-20
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)

更多回答(1 个)

Josh Chen
Josh Chen 2022-3-30
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 个评论
Josh Chen
Josh Chen 2022-4-4
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 2022-4-4
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 ROS Network Access in Simulink 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by