How do I enter a string into a ROS message in Simulink?

6 ビュー (過去 30 日間)
Harry Parsons
Harry Parsons 2020 年 9 月 21 日
回答済み: Josh Chen 2020 年 10 月 26 日
I'm attempting to send a path message to a ROS system. However, in order for this to be correctly published to RVIZ it requires a reference frame ID (FrameId in the header). I have attempted to complete this in multiple ways- First I attempted to enter a String Constant into a bus assignment block:
This has come up with the following error:
I then attempted in the shown matlab block to create a 128x1 uint8 array of the ASCII values of "odom", and blank characters (ASCII 32) making up the remaining 124 characters, using the following code:
frameid = zeros(128,1, 'uint8');
string = ['o', 'd', 'o', 'm'];
frameid(1:4) = uint8(string);
frameid(5:128) = 32;
frameid = uint8(frameid);
globalplannermessage.Header.FrameId = frameid;
This, however, simply ended up with RVIZ showing that the reference frame was blank (For frame []: Frame [] does not exist)
What is the recommended method to complete this?
This is my first question on here, so if I have missed any important information please let me know and I'll change whatever needs to be changed!

採用された回答

Josh Chen
Josh Chen 2020 年 10 月 26 日
Hello Harry,
Since ROS strings in Simulink have to be fixed-length uint8 array, normally there are two ways of entering a string into a ROS message in Simulink.
(1) Use a MATLAB Function block to convert a string to uint8. Refer to the following page as an example:
(2) Use the "String to ASCII" block to convert the string signal to uint8 array.
Hope this helps,
-Josh

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpecialized Messages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by