Reading Custom Messages from ROS2 bag files without redefining messages

26 visualizaciones (últimos 30 días)
megalomaniac
megalomaniac el 22 de Sept. de 2023
Respondida: Sai el 15 de Nov. de 2024 a las 13:39
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 comentario
Varun
Varun el 31 de En. de 2024
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!

Iniciar sesión para comentar.

Respuestas (1)

Sai
Sai el 15 de Nov. de 2024 a las 13:39
It is my understanding that you are trying to read from ROS2 bag file by referencing your custom message and you code returns error while referencing to your custom message.
The errors are relevant to the function used for custom message definition and syntax of the function used for reading the custom message from ros2 bag.
Your custom message must be created by using ros2genmsg function, before creating the ros2bag object.
You can refer to syntax and examples of ros2genmsg and ros2bag functions from below product documents. :

Categorías

Más información sobre Custom Message Support en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by