Reading Custom Messages from ROS2 bag files without redefining messages

34 次查看(过去 30 天)
I am trying to read my ROS2 bag file (.db3) using Matlab just to plot some variables of interest from my custom package. I don't want to edit, send, or receive messages from this ROS2. However, my code returns an error referencing my custom messages.
Error using ros2
Unrecognized message type custom_package/custom_message_name. Use ros2 msg list to see available types.
Error in ros2bag (line 156)
rosMsgDef = ros2("msg","show",topicTypes{i});
Error in ExtractPlot_ROS2 (line 33)
bag = ros2bag(folder_path);
Other answers regarding this issue want me to use pyenv to individually define these messages. Is there a way to just view the data without having to remake my entire custom ROS2 environment in Matlab?
  1 个评论
Varun
Varun 2024-1-31
Hey! I think that to retrieve data from DB3 file, MATLAB would need information regarding your custom packages regardless of whether you send or receive messages. Maybe importing the definitions of these custom messages can help resolve the issue. Please check whether the custom ROS messages have been added to MATLAB path or not.
If they aren't, use the "ros2genmsg" function to generate the custom messages from ROS 2 definitions. Here's the documentation link for the same: https://www.mathworks.com/help/ros/ref/ros2genmsg.html.
If the message definitions are not on the path, you can add them to the MATLAB path using the "addpath" function and then run the following commands:
savepath
clear classes
rehash toolboxcache
After this, you can call 'ros2 msg list' to verify the creation of new custom messages.
ros2 msg list
This should add the custom message definitions to your path and help MATLAB reference them. Hope this helps!

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Publishers and Subscribers 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by