MATLAB Answers

How can I load, read and save ros ".msg" file by Matlab?

24 views (last 30 days)
Sui
Sui on 17 Jan 2019
Edited: Sui on 29 Jan 2019
I am trying to load those Autoware code in to Matlab and create a excel files. Autoware is on ROS. ROS has some massage files. I am trying to load those files by MATLAB and get the output as execel files. For example, I have a ROS .msg file called "AccelCmd.msg". Inside of this message I have something as :
Header header
int32 accel
I am able to open it by duble cleck this from "Current folder" window. Or I can right cleck and choose open it as txt. However, that is not what I want. I want load them and save them as a csv or xsml files. Anyone can help me with it?
Thank you.

  0 Comments

Sign in to comment.

Answers (1)

Cam Salzberger
Cam Salzberger on 21 Jan 2019
Edited: Cam Salzberger on 22 Jan 2019
Hello David,
If you are simply looking to import the text from ROS message files, then possibly write it back out into a different file format, there are many ways of pulling text into MATLAB. I'd suggest using the Import Tool as a good first step, as you can use it to generate code for later use in automatically importing text. textscan is also useful if you just want to pull all the text in, and parse it to ignore comment and blank lines. If none of the files have comments, you could check out readtable.
Now that is all about how to get the text data into MATLAB. However, most of the time people are looking to do something with ROS MSG files, they are looking to create ROS message objects in MATLAB, and send and receive that type of ROS message from MATLAB to an external network. If you would like to use MATLAB to access data in these messages (whether the messages are in rosbags or received over the ROS network), you can follow the ROS Custom Message workflow to add support for these messages to MATLAB.
Hope that helps!
-Cam

  7 Comments

Show 4 older comments
Sui
Sui on 22 Jan 2019
Hi Cam
Thank you so much for you time. That does help me a lot. I thought readtable will only work for txt files, therefore I did not tried that. Thank you again.
Sui
Sui on 24 Jan 2019
Hi Cam
Thank you so much for all you did. But just quick question. I am doing this thing. But some of them does not looks like "normal". I mean some of them has long commen word. For that, it is not really I want. If I use the same code to run this, it looks like:
out.PNG
in Excel.
As you can see, it is miss first part. Also, it is really mess. Therefore, if you have time. Will you please take look at it. Also, is there a way that I can code in MATLAB to block those describe word. Only plot what I want?
Sincerely,
Sui
Sui on 29 Jan 2019
Hello Cam
Also I found something that I do not really understand why. For example, I open it by right click select 'open as text' in Matlab. Then I edite like this
q1.PNG
I delecte all commen word by hands. Then I save this file and use the same code to run it. But the output is not really good. I mean it looks like
Q2.PNG
If you do have time, please check out those two common that I just added. Thank you so much.
Sincerely,

Sign in to comment.

Sign in to answer this question.