flip_chatter.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #       
00003 # License: BSD
00004 #   https://raw.github.com/robotics-in-concert/rocon_multimaster/master/rocon_gateway_examples/LICENSE 
00005 #
00006 ##############################################################################
00007 # Imports
00008 ##############################################################################
00009 
00010 import roslib; roslib.load_manifest('rocon_gateway_examples')
00011 import rospy
00012 import rocon_gateway
00013 from gateway_comms.srv import Remote,RemoteRequest
00014 from gateway_comms.msg import ConnectionType
00015 
00016 """
00017     Flipping chatter. It flips /chatter topic from master_uri 11312 to 11313
00018 
00019     Usage:
00020         1 > roslaunch --port=11311 rocon_gateway_hub priate.launch           // starts hub
00021 
00022         2a > roslaunch --port=11312 rocon_gateway pirate_tutorials.launch     // launches gateway on master_uri 11312 its gateway name is 'gateway' and starts /chatter publisher
00023         3a > roslaunch --port=11313 rocon_gateway priate.launch               // launches gateway on master_uri 11313 its gateway name is 'gateway2'
00024 
00025         2b > rosrun rocon_gateway_examples flip_chatter.py  __master:=http://localhost:11312  // flips /chatter topic in 11312
00026         3b > rostopic list                                                                    // check if the topic exists in 11313
00027 """
00028 
00029 if __name__ == '__main__':
00030     
00031     rospy.init_node('flip_chatter')
00032     rospy.loginfo("Fliping /chatter topic")
00033 
00034     # Gateway flip service
00035     flip_service = rospy.ServiceProxy('/gateway/flip',Remote)
00036 
00037     # Gateway name where the topic is flip-in to it may differ
00038     remote_gateway_name = 'gateway1'
00039 
00040     # Create Request for flip service
00041     req = RemoteRequest()
00042     req.remote.gateway = remote_gateway_name 
00043     req.cancel = False          # if true, attempt to cancel existing /chatter
00044     req.remote.rule.name = "/chatter"
00045     req.remote.rule.type = ConnectionType.PUBLISHER     # Indicates that it is attempting to flip publisher
00046     req.remote.rule.node = '' # Optional. If specified, it flips a particular node's publisher. It is useful if there is a multiple publisher and want to flip just ones
00047 
00048     # Call service and receive the response
00049     rospy.loginfo("Flip : %s [%s,%s,%s,%s]."%('flipping', req.remote.gateway, req.remote.rule.type, req.remote.rule.name, req.remote.rule.node or 'None')) 
00050     resp = flip_service(req)
00051 
00052     # Print response
00053     rospy.loginfo(str(resp))
00054 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends


rocon_gateway_examples
Author(s): Jihoon
autogenerated on Sat Nov 10 2012 12:28:18