Publishing on a ROS Topic Simulink
Show older comments

I am trying to publish a message on the /command topic using ROS Toolbox block. I am receiving this error from my linux system where ROS is running. The 'data' variable is 16x1 array as shown above. I am not sure why it says that size is not 16. I have tried to change the data to 1x16 but that doesnt work. The strange thing is that I can publish a message using an m script and it works fine. Below you can see that the message.Data is the same data type and size as 'data'.
I would appreciate any help on this, this step is crucial for my project. Thanks in advance!
Answers (1)
Josh Chen
on 25 Apr 2021
3 votes
Hello Hassan,
In Simulink when creating a bus, it requires more information than MATLAB to lock down the message you want to send when it comes to variable size messages. As you might have noticed, 'std_msgs/Int32MultiArray' is one of the variable size messages. To get this to work, you would need to make sure you've done the following to steps:
- Under Simulink->Prepare->VariableSize Messages, click on 'std_msgs/Int32MultiArray', uncheck 'Use default limits for this message type', and write down the correct length (in this case, 16) for the 'Data' field on the right pane.
- Provide the correct length with 'Data_SL_CurrentLength' when you assign values with bus assignment block.
I am not sure which version of MATLAB are you using, but I've attached an image based on R2021a for your reference.
Hope this helps,
Josh

1 Comment
Hassan Hotait
on 28 Apr 2021
Categories
Find more on ROS 2 Network Access in Simulink in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!