MATLAB: Subscribe the topic /robot/joint_states ,but i get l_gripper_l_finger_joint message.

baxterMATLABRobotics System Toolboxros

How to reject the {'l_gripper_l_finger_joint'}, i use subscribe Block and the topic /robot/joint_states ,but i get l_gripper_l_finger_joint message.
The physical Baxter sends the gripper states separately on the same topic, so we have to reject it. Can you help me with it.
I use the receive function to read the joint states,the same thing happened again.
The messages returned at different times are as follows,which i don't want these messages.
jntState1 = receive(jointSub1)
jntState1 =
ROS JointState message with properties:
MessageType: 'sensor_msgs/JointState'
Header: [1×1 Header]
Name: {'l_gripper_l_finger_joint'}
Position: 0.020830000000000
Velocity: 0
Effort: 0
These messages are what i want.
jntState1 = receive(jointSub1)
jntState1 =
ROS JointState message with properties:
MessageType: 'sensor_msgs/JointState'
Header: [1×1 Header]
Name: {17×1 cell}
Position: [17×1 double]
Velocity: [17×1 double]
Effort: [17×1 double]
In the simulink the messages returned at different times are as follows:
1、
X@FT[27V{0F6GA0~DAWY6]D.png
2、
$G585LW4)RI08R3BNOBUIMW.png
Can someone help me.
Best wishes!

Best Answer

Well, I was hoping to get your overall workflow so that I could suggest something that would fit in with it. However, the simpliest solution is simply to check what you have received after you get the message, but before you react with it. For example, if you are using receive in a loop, you can do something like:
while keepMoving
jntStateMsg = receive(jointSub1);
if contains(jntStateMsg.Name, 'head_pan')
% react to he message here
end
pause(0.2)
end
You could even check the message to see if it has each specific joint you are using right before you use it. A similar pattern would apply if you were using a NewMessageFcn callback to the subscriber instead of receive, and using the LatestMessage property in a loop would be similar to receive.
So, overall, my advice would be to check that the message applies to the joints before you use it. Hope that helps!
-Cam
Related Question