Borrar filtros
Borrar filtros

Subscripted Assignment to Create Array Element

15 visualizaciones (últimos 30 días)
Umer Huzaifa
Umer Huzaifa el 2 de Mzo. de 2016
Respondida: Umer Huzaifa el 26 de Abr. de 2017
Hi,
I am using MATLAB with Robotics System Toolbox. I am running a Gazebo simulation in ROS that I want MATLAB to talk to. In particular, I want to make a node for a given topic related to that simulation. The way to do this is following (as I understood from the tutorials and examples):
pub_cmd=rospublisher('<any topic that receives commands>');
pub_cmd_msg=rosmessage(pub_cmd)
Now, pub_cmd_msg returns the following:
pub_cmd_msg =
ROS JointTrajectory message with properties:
MessageType: 'trajectory_msgs/JointTrajectory'
Header: [1x1 Header]
JointNames: {0x1 cell}
Points: [0x1 JointTrajectoryPoint]
Use showdetails to show the contents of the message.
Now as I try to assign some values to different fields in this pub_cmd_msg, I get the following error:
pub_cmd_msg.Points
ans =
0x1 ROS JointTrajectoryPoint message array with properties:
MessageType
TimeFromStart
Positions
Velocities
Accelerations
Effort
>> pub_cmd_msg.Points.Positions=ones(1,7)
Property assignment is not allowed when the object is empty. Use subscripted assignment to create an array element.
I have no idea what the error means and how can subscripted assignment help? Kindly guide how can I solve this problem.

Respuesta aceptada

Benjamin Brandwin
Benjamin Brandwin el 26 de Abr. de 2017
Editada: Benjamin Brandwin el 26 de Abr. de 2017
This was one tough cookie but I figured it out. The key was actually in the PR2 example code. If you read it carefully and compare it to the data types in the jointMsg below you can figure this out.
[jointClient,jointMsg] = ...
rosactionclient('/robot/limb/right/follow_joint_trajectory');
Take a look at jointMsg
jointMsg =
ROS FollowJointTrajectoryGoal message with properties:
MessageType: 'control_msgs/FollowJointTrajectoryGoal'
Trajectory: [1×1 JointTrajectory]
GoalTimeTolerance: [1×1 Duration]
PathTolerance: [0×1 JointTolerance]
GoalTolerance: [0×1 JointTolerance]
We look closer to find an object called jointMsg.Trajectory.Points.Position but when we do this :
>> jointMsg.Trajectory.Points.Positions = [0;0;0;0;0;0;0]
Property assignment is not allowed when the object is empty.
Use subscripted assignment to create an array element.
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
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]
Use showdetails to show the contents of the message
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;
Lets take a look
jointMsg.Trajectory.Points
ans =
ROS JointTrajectoryPoint message with properties:
MessageType: 'trajectory_msgs/JointTrajectoryPoint'
TimeFromStart: [1×1 Duration]
Positions: [7×1 double]
Velocities: [7×1 double]
Accelerations: [0×1 double]
Effort: [0×1 double]
Use showdetails to show the contents of the message
Voila
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

Más respuestas (2)

Yinai Fan
Yinai Fan el 31 de Oct. de 2016
Hi I got the same problem, did you solve it? Thank you.

Umer Huzaifa
Umer Huzaifa el 26 de Abr. de 2017
Thanks @Benjamin. I am not working on it currently but will get back to it at some point. But anyways, it makes sense.

Categorías

Más información sobre Publishers and Subscribers en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by