Receiving subscribing data delayed between multiple devices
I'm new to ROS and do not fully understand how its messaging system works.
I have two Raspberry Pi 3's that are communicating with each other over a local network. On one of the pi's, it takes a string input from the user through the console and publishes it to a topic. The other raspberry pi then subscribes to the topic, receives the user-inputted string, edits it, and then prints it to its terminal.
The problem I'm having is when I first publish to the topic, the subscribing node does not take the string data until I publish to the topic for a second time. I would like the subscribing node to edit and print the string as soon as the data is published to the topic. Does anyone know how this could be done?
Asked by Passless11 on 2018-07-19 13:58:42 UTC
Answers
Please use the search: subscribing takes time. Setting up connections between publishers and subscribers takes time. If you don't allow for this setup, published msgs are lost (ie: no one is listening).
If you don't want to lose any messages, then bare publish-subscribe in ROS 1 is not what you should use. Services or actions might be more suitable.
Alternatively: consider using ros::Publisher::getNumSubscribers() and waiting for at least a single subscriber before publishing anything.
Asked by gvdhoorn on 2018-07-20 08:22:15 UTC
Comments
Seems like either your program somehow ignores the first message or it didn't get it. Rostopic echo the topic you are listening to in the receiving PI before you send it. If it doesn't echo it, it didn't go through. It's impossible to tell what is going wrong from the information you have provided.
Asked by Reamees on 2018-07-20 01:33:50 UTC