Note: This tutorial assumes that you have completed the previous tutorials: Launching a Hub. |
Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags. |
Writing a Hub Client
Description: Using the hub client api to conveniently connect/use a rocon hub.Keywords: rocon, hub, multimaster
Tutorial Level: INTERMEDIATE
Contents
rocon_hub_client is a python package designed to help you discover and connect to hubs.
Hub Discovery
Hub discovery works either via a list of uri's passed directly, or via zeroconf. It does this in a background thread which periodically checks for existence of rocon hubs.
Note, the uri list may be empty, and the zeroconf discovery may be optionally disabled. As hubs are discovered, they trigger the discovery callback you have specified.
Zeroconf
To get the zeroconf module to work on linux, you'll need something like the following in your launcher (it uses the zeroconf_avahi package).
1 <node ns="zeroconf" pkg="zeroconf_avahi" type="zeroconf" name="zeroconf"/>
2 <node pkg="my_hub_client" type="my_hub_client.py" name="my_hub_client">
3 <remap from="my_hub_client/add_listener" to="zeroconf/add_listener"/>
4 <remap from="my_hub_client/list_discovered_services" to="zeroconf/list_discovered_services"/>
5 </node>
Hub Client
Once you have an ip/port of a discovered hub, you can use the Hub class to connect to the hub.
Note - the rocon hub name is a key on the redis server of the form rocon:hub:name. Whitelists and blacklists can be used to selectively filter the hubs you wish to connect to.