def master_changed(msg, cb_args): param_cache, local_master = cb_args local_name = '' if local_master: local_name = local_master[0] if msg.master.uri != masteruri_from_master() and local_name in param_cache: master_to = rospy.MasterProxy(masteruri_from_master()) master_from = rospy.MasterProxy(msg.master.uri) rospy.logdebug("Getting params from {}...".format(msg.master.uri)) params_from = master_from['/'] rospy.logdebug("Got {} params.".format(len(msg.master.uri))) if local_name in params_from: del params_from[local_name] if '/' + local_name in params_from: del params_from['/' + local_name] rospy.logdebug("Syncing params from {} to {}...".format( msg.master.name, local_name)) if param_cache.get(msg.master.name, None) != params_from: param_cache[msg.master.name] = params_from master_to['/' + msg.master.name] = params_from rospy.logdebug("Done syncing params from {} to {}.".format( msg.master.name, local_name)) else: rospy.logdebug("Params have not changed from {} to {}.".format( msg.master.name, local_name)) else: local_name = msg.master.name local_master.append(local_name) master_from = rospy.MasterProxy(msg.master.uri) rospy.logdebug("Getting params from local {}...".format( msg.master.uri)) param_cache[local_name] = master_from['/'] rospy.logdebug("Got {} params.".format(len(msg.master.uri)))
def master_changed(msg, cb_args): master_proxies, param_cache, __add_ns = cb_args master_proxies[msg.master.name] = rospy.MasterProxy(msg.master.uri) for name_from, master_from in master_proxies.items(): for name_to, master_to in master_proxies.items(): if name_to != name_from: rospy.logdebug("Getting params from...".format(name_from)) params_from = master_from['/'] rospy.logdebug("Got {} params.".format(len(params_from))) if name_to in params_from: del params_from[name_to] if '/'+name_to in params_from: del params_from['/'+name_to] rospy.logdebug("Syncing params from {} to {}...".format(name_from, name_to)) if __add_ns: _ns = name_from else: _ns = '' if param_cache.get(_ns, None) != params_from: param_cache[_ns] = params_from master_to['/'+_ns] = params_from rospy.logdebug("Done syncing params from {} to {}.".format(name_from, name_to)) else: rospy.logdebug("Params have not changed from {} to {}.".format(name_from, name_to))
def master_changed(msg, cb_args): param_cache, local_master, __add_ns, __ignore, __only = cb_args local_name = '' if local_master: local_name = local_master[0] if msg.master.uri != masteruri_from_master() and local_name in param_cache: master_to = rospy.MasterProxy(masteruri_from_master()) master_from = rospy.MasterProxy(msg.master.uri) rospy.logdebug("Getting params from {}...".format(msg.master.uri)) params_from = master_from.getParam('/')[2] if not __add_ns: for key in ['run_id', 'rosversion', 'roslaunch', 'rosdistro', 'master_sync', 'master_discovery', 'capabilities', 'mastername', 'robots']: try: del params_from[key] except Exception: pass for key in __ignore + [local_name, '/'+local_name]: try: del params_from[key] except Exception: pass if __only: for key in params_from.keys(): if key not in __only: del params_from[key] rospy.logdebug("Syncing params from {} to {}...".format(msg.master.name, local_name)) if __add_ns: _ns = msg.master.name else: _ns = '' rospy.logdebug("Got {} params.".format(len(params_from))) if param_cache.get(_ns, None) != params_from: param_cache[_ns] = params_from for key, value in params_from.items(): master_to.setParam('/'+_ns+key, value) rospy.logdebug("Done syncing params from {} to {}.".format(msg.master.name, local_name)) else: rospy.logdebug("Params have not changed from {} to {}.".format(msg.master.name, local_name)) else: local_name = msg.master.name local_master.append(local_name) master_from = rospy.MasterProxy(msg.master.uri) rospy.logdebug("Getting params from local {}...".format(msg.master.uri)) param_cache[local_name] = master_from.getParam('/')[2] rospy.logdebug("Got {} local params.".format(len(param_cache[local_name])))