How to use String array in a custom Message in Simulink?

조회 수: 1 (최근 30일)
David Shawky
David Shawky 2020년 7월 28일
답변: Josh Chen 2021년 1월 22일
I have a custom message imported in matlab which requires Velocity and Name. In the custom msg file, Name is defined as string[] name. So I read The robotrosmessageExample and followed the same procedure, However I get an error in ros of a dimension mismatch. I used same messages in matlab and It worked fine. So How can this issue be resolved ?
The model is attached in the screenshot below with the code of matlab function.
Thank you for your time
function msg = assignString(blankMsg)
stringToAssign = '[blade_joint_1; blade_joint_2; blade_joint_3; blade_joint_4; blade_joint_5; blade_joint_6]';
msg = blankMsg;
strLength = length(stringToAssign);
msg.Data(1:strLength) = uint8(stringToAssign);
msg.Data_SL_Info.CurrentLength = uint32(strLength);

답변 (1개)

Josh Chen
Josh Chen 2021년 1월 22일
Hello David,
It seems that the the message you are assigning here is of type "std_msgs/String", have you tried to change the maximum length of the "std_msgs/String" message to match the actual assigned string length?
The screenshot shows the correct pane to set this up, however, I assume it should be the third message (currently it is showing the first message). If this is not the case, please share a model so we can take a look.
Not sure if you've already checked this out, but this example model tries to do a pretty similar work.
Hope this helps.
Josh

카테고리

Help CenterFile Exchange에서 LEGO MINDSTORMS EV3 Hardware에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by