Manage Ros Custom Message with Variable-Length array

조회 수: 10 (최근 30일)
Marco Mandelli
Marco Mandelli 2020년 11월 23일
편집: Josh Chen 2020년 11월 24일
Hi
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
Thank you!

답변 (1개)

Josh Chen
Josh Chen 2020년 11월 24일
편집: Josh Chen 2020년 11월 24일
Hi Marco,
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,
Josh

카테고리

Help CenterFile Exchange에서 ROS 2 Network Access in Simulink에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by