Hello. I want to use matlab as an independent ros node for publishing std_msgs/Float64MultiArray type messages. I am able to assign parameters to the Data field. However I am getting errors while assigning parameters to other fields. Please help

asked 2020-06-28 18:28:54 -0500

Ritish Shailly gravatar image

updated 2020-06-28 22:00:41 -0500

jayess gravatar image

Here is what my code looks like:

rosinit('IP ADDRESS');
mySub =  rossubscriber('/wx200/joint_states');
myPub = rospublisher('/wx200/arm_controller/command',...
    'std_msgs/Float64MultiArray');

.
.
.

recvMsg =  mySub.LatestMessage;
msg = rosmessage(myPub);
msg.Data = [0 0 0 0 0];

My code is working fine until this line. However, it starts to throw errors from the following line:

msg.Layout.Dim.Size = [0 0 0 0 0];
msg.Layout.Dim.Label= ['shoulder', 'waist','elbow', 'wrist_angle', 'wrist_rotate'];
msg.Layout.Dim.Stride = [0, 0, 0, 0, 0];

Error Message is:

Property assignment is not allowed when the object is empty.  Use
subscripted assignment to create an array element.
Error in rosnode_matlab_controller (line 23)
msg.Layout.Dim.Size = [0 0 0 0 0];

I don't know how to assign parameters to other parts of the std_msgs/Float64MultiArray topic. The requirements are:

std_msgs/MultiArrayLayout layout
 std_msgs/MultiArrayDimension[] dim
  string label
  uint32 size
  uint32 stride
 uint32 data_offset
float64[] data
edit retag flag offensive close merge delete

Comments

I'd suggest to ask this on the Mathworks support forums.

gvdhoorn gravatar image gvdhoorn  ( 2020-06-29 03:34:08 -0500 )edit