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

1 visualización (últimos 30 días)
David Shawky
David Shawky el 28 de Jul. de 2020
Respondida: Josh Chen el 22 de En. de 2021
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);

Respuestas (1)

Josh Chen
Josh Chen el 22 de En. de 2021
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

Categorías

Más información sobre LEGO MINDSTORMS EV3 Hardware en Help Center y File Exchange.

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by