Spelunking ros_comm
In examining implementation details for bringing up native ROS1 support for roslibrust
, I’ve noticed that the documentation available on the process for a ROS node to start publishing, subscribing, etc is a little underdocumented and scattered. I’ve started to fill in some missing pieces and will be word vomiting what I’ve discovered so far here while it’s still fresh.
Let’s look at what is required for a node to startup and publish to a topic. I’ve discovered a few steps:
- It needs to call an XML RPC API
registerPublisher
on therosmaster
. This communicates the topic name, the publishing node’s name, the type in Package/Message format as a string, and a TCPROS URI for the node. The URI is important as we’ll see in the next step. - Listen on it’s own TCPROS API (URI from previous step) for subscribers. These subscribers will send a connection header. The fields are documented here. If valid, it establishes a persistent Transport Subscriber Link, wrapped in a Publication.
- As the calling code publishes data on the topic, it will send data encoded in the TCPROS format over the persistent link.
On the other hand, for subscribers:
- It needs to XML RPC API
registerSubscriber
on therosmaster
. This is very similar to the publish case except that instead of leaving a TCPROS URI, it leaves an XML RPC URI. - Listen on its XML RPC API. The
rosmaster
will indicate to the node anytime a publisher is registered and will send it the TCPROS URI of the publisher. - When a subscriber is notified of a new publisher, it makes a TCPROS API call to the publisher and establishes a link.
- It should listen for a connection header response from the publisher, and then thereafter listen for TCPROS encoded message data for the topic.
I have not read in on services yet, though many of the workflows are likely similar. The publish / subscribe protocol is a little awkward in that the connection is negotiated over the same connection that the data is sent over. This is not really a problem for publishers, but for subscribers a little statefulness of their link connection is required.
What I’ve discussed above should be enough to get me started supporting publish and subscribe in roslibrust
. It seems the minimum required is an XML RPC client for talking to the master, an XML RPC server for handling subscribing, and a TCPROS server for handling publishing. Pretty excited to see some messages start flowing without needing the rosbridge
!
Bonus: The best documentation for the XML RPC API for rosmaster
that I’ve found so far are actually just the doc comments in the python code for the handlers.
If you notice a dead link or have some other correction to make, feel free to make an issue on GitHub!