ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
I think your question is a bit ambiguous, the way you access the content of a message depends on the type of message you are working with. Each message has its own attributes.
I don't know if what you want is for the first subscriber node to read the first message published by the publisher node, then the second node to read the second message, and so on. Namely:
Example of messages from a topic in the terminal:
hello_world_1
-> Read by the first node
hello_world_2
-> Read by the second node
hello_world_3
-> Read by the third node
.
.
.
hello_world_i
-> Read by the ith node
If what you are looking for is the above you can use an i counter to identify each published message.
Now, if what you are looking for is to read a message that continuously publishes a vector and from that vector you want a node to read a component, another node another component, and so on, you would have to use the callback function of the subscriber nodes to store the message vector inside a variable in your code, this way you can select the component you want to read with each node. Remember that the callback(msg_type msg) function receives the message you are working with as an input parameter, and within it you can directly access each of the variables, vectors and other attributes that the message in question has. For example, if the message type you are using is std_msgs/String, with the callback function you can access the Data attribute to read the text stored there.
Maybe I'm misunderstanding your question, but if you give a little more context about what exactly you're looking to do, then I'll be able to help you.