1
3 """
4 Switch the ROS master currently in use, e.g. master('prh'). If
5 master() is called with no args, defaults to localhost.
6
7 @param name: name of master (if running on default port), or full URI
8 @type name: str
9 """
10
11
12
13
14 if name.startswith('http://'):
15 ctx.master._reinit(name)
16 else:
17
18 ctx.master._reinit('http://%s:11311'%name)
19
20
21 os.environ[roslib.rosenv.ROS_MASTER_URI] = ctx.master.master_uri
22 return ctx.master.is_online()
23
25
26 - def __init__(self, from_topic, to_topic):
27 self.from_topic = from_topic
28 self.to_topic = to_topic
29
31
32 to_topic = self.to_topic
33 if to_topic is None:
34 return
35
36
37 if to_topic._type_name is None:
38 try:
39 to_topic._init(msg._type)
40 except:
41
42 print >> sys.stderr, "FAILED to initialize, destroying relay [%s] | [%s]"%(self.from_topic, self.to_topic)
43 self._unrelay()
44
45 if msg._type == to_topic._type_name:
46 to_topic(msg)
47 else:
48
49 pass
50
52 if self.from_topic is not None:
53 self.from_topic._remove_subscriber_callback(self)
54 self.from_topic = self.to_topic = None
55
58
60
61 - def __init__(self, from_topic, to_topic, filter_fn):
62 super(_FilteredRelay, self).__init__(from_topic, to_topic)
63 self.filter_fn = filter_fn
64
68
69 -def relay(from_topic, to_topic, filter_fn=None):
70 if filter_fn:
71 relay_obj = _FilteredRelay(from_topic, to_topic, filter_fn)
72 else:
73
74 relay_obj = _Relay(from_topic, to_topic)
75 from_topic._add_subscriber_callback(relay_obj)
76 return relay_obj
77
80