Package rocon_gateway :: Module ros_parameters
[frames] | no frames]

Source Code for Module rocon_gateway.ros_parameters

  1  #!/usr/bin/env python 
  2  # 
  3  # License: BSD 
  4  #   https://raw.github.com/robotics-in-concert/rocon_multimaster/master/rocon_gateway/LICENSE 
  5  # 
  6   
  7  import rospy 
  8  import re 
  9  from gateway_msgs.msg import Rule, RemoteRule 
 10  import utils 
 11   
 12  ############################################################################### 
 13  # Functions 
 14  ############################################################################### 
 15   
 16   
17 -def setup_ros_parameters():
18 ''' 19 Returns the gateway parameters from the ros param server. 20 Most of these should be fairly self explanatory. 21 ''' 22 param = {} 23 24 # Hub 25 param['hub_uri'] = rospy.get_param('~hub_uri', '') 26 # Convert these back to accepting lists once https://github.com/ros/ros_comm/pull/218 27 # goes through, for now we use semi-colon separated lists. 28 param['hub_whitelist'] = rospy.get_param('~hub_whitelist', "") 29 param['hub_blacklist'] = rospy.get_param('~hub_blacklist', "") 30 param['hub_whitelist'] = filter(bool, param['hub_whitelist'].split(';')) # avoid '' hub name strings 31 param['hub_blacklist'] = filter(bool, param['hub_blacklist'].split(';')) 32 33 # Gateway 34 param['name'] = rospy.get_param('~name', 'gateway') 35 param['watch_loop_period'] = rospy.get_param('~watch_loop_period', 10) # in seconds 36 37 # Blacklist used for advertise all, flip all and pull all commands 38 param['default_blacklist'] = rospy.get_param('~default_blacklist', []) # list of Rule objects 39 40 # Used to block/permit remote gateway's from flipping to this gateway. 41 param['firewall'] = rospy.get_param('~firewall', True) 42 43 # The gateway can automagically detect zeroconf, but sometimes you want to force it off 44 param['disable_zeroconf'] = rospy.get_param('~disable_zeroconf', False) 45 46 # The gateway uses uui'd to guarantee uniqueness, but this can be disabled if you want clean names without uuid's (but you have to manually guarantee uniqueness) 47 param['disable_uuids'] = rospy.get_param('~disable_uuids', False) 48 49 # Make everything publicly available (excepting the default blacklist) 50 param['advertise_all'] = rospy.get_param('~advertise_all', []) # boolean 51 52 # Topics and services for pre-initialisation/configuration 53 param['default_advertisements'] = rospy.get_param('~default_advertisements', []) # list of Rule objects 54 param['default_flips'] = rospy.get_param('~default_flips', []) # list of RemoteRule objects 55 param['default_pulls'] = rospy.get_param('~default_pulls', []) # list of RemoteRule objects 56 57 return param
58 59
60 -def generate_rules(param):
61 ''' 62 Converts a param of the suitable type (see default_blacklist.yaml) 63 into a dictionary of Rule types. 64 65 @return all rules as gateway_msgs.msg.Rule objects in our usual keyed dictionary format 66 @rtype type keyed dictionary of Rule lists 67 ''' 68 rules = utils.create_empty_connection_type_dictionary() 69 for value in param: 70 rule = Rule() 71 rule.name = value['name'] 72 # maybe also check for '' here? 73 pattern = re.compile("None", re.IGNORECASE) 74 if pattern.match(value['node']): 75 rule.node = '' # ROS Message fields should not be None, maybe not a problem here though, see below 76 else: 77 rule.node = value['node'] 78 rule.type = value['type'] 79 rules[rule.type].append(rule) 80 return rules
81 82
83 -def generate_remote_rules(param):
84 ''' 85 Converts a param of the suitable type (default_flips, default_pulls) into 86 a list of RemoteRule objects and a list of target gateways for flip_all/pull_all. 87 88 @param yaml object 89 @type complicated 90 91 @return list of remote rules 92 @return RemoteRule[] 93 ''' 94 remote_rules = [] 95 all_targets = [] 96 pattern = re.compile("None", re.IGNORECASE) 97 for remote_rule in param: 98 if 'rule' in remote_rule: 99 # maybe also check for '' here? 100 node = None if pattern.match(remote_rule['rule']['node']) else remote_rule['rule']['node'] 101 remote_rules.append(RemoteRule(remote_rule['gateway'], 102 Rule(remote_rule['rule']['type'], 103 remote_rule['rule']['name'], 104 node 105 ) 106 ) 107 ) 108 else: 109 all_targets.append(remote_rule['gateway']) 110 return remote_rules, all_targets
111