Manage Ros Custom Message with Variable-Length array
6 views (last 30 days)
I'm trying to read a message from ROS that is structured like this
The message is called WaypointArray.msg and contains header, two booleans and an array of Waypoints
Every waypoint has the fields x and y
I'm trying to read them following the example of reading variable-length array from ros but i cannot manage to find a solution. I place a bus selector to select the Array field and the count, a selector to select the indexes and now I have a variable length array of buses. I cannot make it work with nothing, if I place another bus selector to get the X field it tells me that it cannot work with variable length buses, the same if i place a "to workspace" field.
Is there a block in simulink to select and work the fields from the array elements? What I want at the end is like a 2xN matrix with the x and y element from every waypoint
Josh Chen on 24 Nov 2020
Edited: Josh Chen on 24 Nov 2020
For WaypointArray.msg, are you referring to rsm_msgs/Waypoint?
It's a bit difficult to see the full picture without a model, but if I understand correctly, you've already managed to create this custom message, receive the message in Simulink, and extract the array out through bus selector. And you are looking for a way to return this waypoint array in the message as a 2xN matrix?
If the above description sounds right, I would recommend you use a MATLAB Function block. This block gives you the flexibility to extract and postprocess the array data just as what you can do in MATLAB. This example of using MATLAB Function block with Simulink ROS messages might be helpful.
As an alternative, you might also be able to use a Selector block.
Hope this helps,