I can only guess what's going on...
Are you planning on sticking to desktop simulations from MATLAB or will you be generating code from the model? It's fairlytough to work with string messages with the ROS-Simulink interface, so if you're sticking to desktop simulations I'd suggest writing a MATLAB Function and enveloping all the ROS interface code as interpreted.
For example, here is a 3-joint, 2-point example:
function sendMsg
coder.extrinsic('sendTrajMsgs');
sendTrajMsgs([1 2 3],[4 5 6]);
end
The following implementation of sendTrajMsgs.m worked fine for me:
function sendTrajMsgs( pos1, pos2 )
persistent pub
if isempty(pub)
pub = rospublisher('/my_joints','trajectory_msgs/JointTrajectory');
end
msg = rosmessage('trajectory_msgs/JointTrajectory');
msg.JointNames = {'joint1','joint2','joint3'};
p1 = rosmessage('trajectory_msgs/JointTrajectoryPoint');
p1.Positions = pos1;
msg.Points(1) = p1;
p2 = rosmessage('trajectory_msgs/JointTrajectoryPoint');
p2.Positions = pos2;
msg.Points(2) = p2;
send(pub,msg)
end
If you have to use the Simulink blocks, you'll notice that you have to treat the strings as you would in C code. The JointNames field of the bus will actually have an array of string buses, each of which has a 128-element uint8 (or char ) array and a supplementary "information" bus that tells you the length of that string -- in other words, how far along the 128 char vector you have to read before it's just empty space.
Going this route, I would follow the tutorial you linked to. What would help is grabbing an "Empty Message" block from the ROS library, filling in the trajectory_msgs/JointTrajectory message type, and then going to Edit > Bus Editor in Simulink. You'll be able to view the structure of all the bus messages that were created for this message.
This should help you add all the necessary "info" metadata to the string messages such as
strLength = length(str);
msg.Name(idx).Data(1:strLength) = uint8(str);
msg.Name(idx).Data_SL_Info.CurrentLength = uint32(strLength);
Hope this helps.
- Sebastian
Best Answer