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

Revision history [back]

click to hide/show revision 1
initial version

As it is, you only publish the message once for each publisher. Is that by design? It's likely that by the time your subscriber is up and running, the messages have already been published and are unavailable to your subscriber. Here are a few options:

If all you need is a vector one time, then the parameter server would be an excellent choice.

If this is just test code, and you plan in the future to publish in a loop, your subscriber should be fine. Note, however, that a subscriber must be up when messages are published in order to recieve those messages.

You could also use latched publishers if you want to make sure you get the first message.

As it is, you only publish the message once for each publisher. Is that by design? It's likely that by the time your subscriber is up and running, the messages have already been published and are unavailable to your subscriber. Here are a few options:

If all you need is a vector one time, then the parameter server would be an excellent choice.

If this is just test code, and you plan in the future to publish in a loop, your subscriber should be fine. Note, however, that a subscriber must be up when messages are published in order to recieve those messages.

You could also use latched publishers if you want to make sure you get the first message.

EDIT: In reference to your first sub-question, I agree. I'd expect the messages to be immediately received by the subscriber if the subscriber existed before the publishers were started. Note that roslaunch makes no guarantee of launch order. It also takes some time to set up the subscriber, so perhaps the publishers had already published the messages by the time the subscriber was alive. In any case, I'm glad latching the publishers solved your problem. If you want to delve deeper, look here and here.

Here is the std_msgs documentation. A link to the Int32MultiArray is on there. You used the data parameter correctly in your publisher examples above. From there you'd just use it as a normal c++ array.

Hope that answers your questions. In the future, I encourage you to ask other questions in new questions so that others can find them in searches.