Note: This tutorial assumes that you have completed the previous tutorials: Launching a Gateway 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.

Flipping

Description: Introduction to flipping connections across gateways.

Keywords: rocon, multimaster, gateway, flip

Tutorial Level: BEGINNER

Next Tutorial: Advertising & Pulling

Overview

Flipping is a means of getting a local connection across to remote ros system via the gateway network. Note that the flipped connection is not a relay, it is a direct node to node connection where your local node's connection details get registered at the remote master via the instruction of the remote gateway.

Workflow

The usual workflow for a flip is as follows (note that some of these steps are internal, but presented here for illustration):

  • You create a flip rule containing the following data:
    • Target remote gateway name (e.g. 'Foobar Gateway')
    • Local connection name (e.g. '/chatter')
    • Local connection type (e.g. 'publisher')
    • Local connection node name (e.g. '/talker')

Note that each of the fields except for type may also be a python regex pattern, e.g. '/chat.*'.

  • The flip rule gets added to a watchlist
  • If a matching connection is available, it immediately sends a flip request.
  • The local gateway periodically checks for matches against the flip rule and acts when it finds a match.

Any flip request is handled by the remote gateway before proceeding.

  • If the remote gateway has a firewall flag configured, it blocks, otherwise
  • It registers the connection with it's local master.

https://docs.google.com/drawings/pub?id=1uvaoAI-G3IXbBi0togs-LefKND3Oy5VXJetHsde7djo&w=574&h=337

Code

Firstly launch the gateway tutorial masters

> rocon_launch rocon_gateway_tutorials gateway_tutorials.concert

and then let's write a very simple example python program to do some flipping:

   1 import rospy
   2 import gateway_msgs.msg as gateway_msgs
   3 import gateway_msgs.srv as gateway_srvs
   4 import rocon_gateway
   5 
   6 rospy.init_node('testies')
   7 remote_gateway = rocon_gateway.samples.find_first_remote_gateway()
   8 flip_service = rospy.ServiceProxy('/gateway/flip', gateway_srvs.Remote)
   9 req = gateway_srvs.RemoteRequest()
  10 req.cancel = False
  11 req.remotes = []
  12 rule = gateway_msgs.Rule()
  13 rule.name = '/chatter'
  14 rule.type = gateway_msgs.ConnectionType.PUBLISHER
  15 rule.node = '/talker'
  16 req.remotes.append(gateway_msgs.RemoteRule(remote_gateway,rule))
  17 rospy.loginfo("Flip : [%s,%s,%s,%s]."%(remote_gateway, rule.name, rule.type, rule.node))
  18 
  19 resp = flip_service(req)
  20 if resp.result != 0:
  21     rospy.logerr("Flip : %s"%resp.error_message)

Open a new shell, export ROS_MASTER_URI=https://localhost:11312 and then run your program directly - you should see the flipping working across the masters. Introspect further with gateway_info, remote_gateway_info or rocon_gateway_graph.

Examples

There are quite a few more complete examples in rocon_gateway_tutorials. As above, start up the gateway tutorial masters: To flip a the publisher /chatter only from the first gateway to the second, in a shell with ROS_MASTER_URI=http://localhost:11312:

> rocon_launch rocon_gateway_tutorials gateway_tutorials.concert

Then to test flipping, in another shell:

> export ROS_MASTER_URI=http://localhost:11312
> rosrun rocon_gateway_tutorials flip_tutorials.py --pubonly

Run flip_tutorials with --help to find the other target operations. For more code samples, check the source code of the flip scripts in rocon_gateway_tutorials.

Limitations

Gateways can't remap connection namespaces, beware of conflicts with flips from other gateways. You may need some infrastructure to ensure that you are flipping to a unique namespace on the remote system. Note that you can remap connection namespaces before those connections are started, so this infrastructure would ideally be launching applications at the same time as remapping and flipping (see rocon_app_platform.

Flipping creates a direct registration/connection. It does not change the type (e.g. tcpros/udpros) of connection made. We are waiting for changes in the communication infrastructure before handling this.

Wiki: rocon_gateway_tutorials/Tutorials/indigo/Flipping (last edited 2014-03-25 00:23:35 by DanielStonier)