ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Problems with trajectory_msgs/JointTrajectory message type in Matlab-ROS

asked 2022-05-21 19:46:40 -0500

LuisEFA1998 gravatar image

I am working with ROS toolbox in Matlab, I want to publish a message inside a topic to move the joints of my robot, but when I execute the command line:

msg.Points.Positions=zeros(6,1);

I get the following message:

Property assignment is not allowed when the object is empty. Use subscribed assignment to create an array element.

I have already searched many Matlab forums for the problem but nowhere have I seen the solution, has anyone worked with the ROS message type trajectory_msgs/JointTrajectory in Matlab?

I used it without any problem in C++, but I don't know what the problem is in Matlab, nor do I understand why the value of the Points attribute of the message cannot be modified, it seems that it cannot be made non-empty.

My complete code is as follows:

clc; 
clear;

rosshutdown; 
rosinit; 

node=ros.Node('/kuka_joints');

pub= ros.Publisher(node,'/kuka_arm_controller/command','trajectory_msgs/JointTrajectory');
msg = rosmessage(pub);

msg.JointNames={'joint_A1' 'joint_A2' 'joint_A3' 'joint_A4' 'joint_A5' 'joint_A6'};
msg.Points.Positions=zeros(6,1);

send (pub,msg);

If I open the ROS message type in the Matlab workspace, this appears:

image description

image description

Here is an example of a problem similar to mine but the solution didn't work for me. I have several days with this problem.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2022-05-23 02:42:38 -0500

gvdhoorn gravatar image

I feel this is more a problem for the Matlab fora, but having written that: the post you link on Matlab Central seems to provide the solution.

Points is of type JointTrajectoryPoint, not whatever the output of zeros(6,1) is.

The post you link also explains this:

We dig a little deeper an find

>> jointMsg.Trajectory.Points
ans = 
0×1 ROS JointTrajectoryPoint message array with properties:
    MessageType
    TimeFromStart
    Positions
    Velocities
    Accelerations
    Effort

And:

Ok, so we have a JointTrajectoryPoint object. So, we will make a JointTractoryPoint message:

joint_send = rosmessage('trajectory_msgs/JointTrajectoryPoint')
joint_send = 
ROS JointTrajectoryPoint message with properties:
      MessageType: 'trajectory_msgs/JointTrajectoryPoint'
    TimeFromStart: [1×1 Duration]
        Positions: [0×1 double]
       Velocities: [0×1 double]
    Accelerations: [0×1 double]
           Effort: [0×1 double]

And finally:

Now we plug in Positions and velocities

>> joint_send.Positions = zeros(7,1);
>> joint_send.Velocities = zeros(7,1);

Now we set our original message

jointMsg.Trajectory.Points = joint_send;

And finally:

Now that your object is no longer empty you can work with it directly.

>> jointMsg.Trajectory.Points.Positions = [1;1;1;1;1;1;1]
>> jointMsg.Trajectory.Points.Positions
ans =
   1
   1
   1
   1
   1
   1
   1

So in the end you can use the syntax you're trying to use, but that's because jointMsg.Trajectory.Points has been initialised to be a JointTrajectoryPoint already.

If this doesn't work for you, I'd advice you to post on Matlab Central yourself, showing the sequence of commands you're using and clearly explaining what doesn't work for you.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2022-05-21 19:46:40 -0500

Seen: 315 times

Last updated: May 23 '22