How can I handle the array type of ROS messages ?

조회 수: 15 (최근 30일)
Jaehyeon Im
Jaehyeon Im 2019년 5월 13일
편집: Jaehyeon Im 2019년 5월 14일
Hi MathWorks team,
I wonder that how can I handle the array type of ROS messages for subscribing or publishing.
For example, I want to publish [ 350 x 2 ] type of ROS message.
To publish ROS msg, I have to assign my data to ROS-supported-type using "Blank Message Block" like std_msgs/Float64 or customized message type.
It seems like that I have to use "std_msgs/Float64MultiArray" type to publish [ 350 x 2 ] ROS msg.
I want to know that this is right. And if it is right or not, please let me know the way.
Thanks !

채택된 답변

Cam Salzberger
Cam Salzberger 2019년 5월 13일
편집: Cam Salzberger 2019년 5월 13일
Hello Jaehyeon,
It looks like the std_msgs/Float64MultiArray should be able to handle the array of data you are looking to provide it. Note, however, that none of the data shaping is done automatically. You will need to convert it to a 1-D array to provide to the "Data" field of the Float64MultiArray message, and then provide any metadata you want to the Layout field about how to transform it back into its expected shape. The transformation back from 1x700 to 350x2 will need to be done on the other end (where you subscribe to the message), preferably using the metadata provided (since that will be most modular if you change the array size later).
Also, since the Float64MultiArray contains a variable size array, you will need to Manage Array Sizes in Simulink to allow it to handle all 700 elements.
-Cam
  댓글 수: 1
Jaehyeon Im
Jaehyeon Im 2019년 5월 14일
편집: Jaehyeon Im 2019년 5월 14일
Thanks for your reply.
I understand I have to transform all of my multi-dimension-arrays to 1-D.
But can you give me some more information about connecting "Black Message" block (std_msgs/Float64MultiArray) with "Bus Assignment" block ?
The problem is here.
I want to publish '/Topic_1' which data type is 2x1.
And also want to publish '/Topic_2' which data type is 4x1.
I want to use "Blank Message" block (std_msgs/Float64MultiArray) for both in same model but I'm not sure how to do that.
Thanks !

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Specialized Messages에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by