Data from Simulink does not update ROS2 topic
조회 수: 3 (최근 30일)
이전 댓글 표시
Hello. I am trying to send a message to a topic. My message seems to have the correct data when seen in simulink, but my ros2 topic is not getting updated with this data.
System:
Ubuntu 20.04
Matlab R2022b
ROS2 Humble
Here is my Simulink block:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1241307/image.png)
I have two message files:
VPGWaypoints.msg
std_msgs/Header header
Waypoint[] wps
Waypoint.msg
float64 x
float64 y
float32 theta
float32 vref
Inside the matlab function - Assign:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1241312/image.png)
What I am trying to do is write a new message of type VPGWaypoints and publish it to the topic /control/velocity_profile with a list of Waypoints messages. I do not know how to create a list/array of custom messages. The function assignArray is my attempt that doing so by modifying the field wps directly. As you can see in the first screenshot, the data is correctly getting updated. x=1.57 in the first element, y=1.57 in the second element. However, in my terminal, when I run ros2 topic echo /control/velocity_profile , all I see is an empty list :
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1241317/image.png)
댓글 수: 0
채택된 답변
Josh Chen
2022년 12월 23일
Hello Renzo,
When publishing messages with vector fields in Simulink, Simulink needs to know the length of valid data in those fields. This information is captured under "xxx_SL_Info.CurrentLength".
In your case, you can add the following line at the end of your MATLAB Function block:
msg.wps_SL_Info.CurrentLength = int32(2);
You may also find this page helpful - Work with ROS Messages in Simulink
Hope this helps,
Josh
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!