params.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 import subprocess
4 import threading
5 import time
6 import sys, os, getopt
7 
8 import roslib.scriptutil
9 from roslib.names import ns_join, get_ros_namespace, make_caller_id, make_global_ns, GLOBALNS
10 
11 PKG_NAME = 'rosweb'
12 import roslib; roslib.load_manifest(PKG_NAME)
13 
15  return make_caller_id('rosparam-%s'%os.getpid())
16 
17 class Params(roslib.message.Message):
18  __slots__ = ('parameters', )
19  def __init__(self, params):
20  self.parameters = params
21 
22 def succeed(args):
23  code, msg, val = args
24  if code != 1:
25  raise RosTopicException("remote call failed: %s"%msg)
26  return val
27 
28 class ParamThread(threading.Thread):
29  def __init__(self):
30  threading.Thread.__init__(self)
31 
32  self.callback = None
33 
34  def setCallback(self, callback):
35  self.callback = callback
36 
37  def flatten(self, params, path="/"):
38  l = []
39  for k,v in params.items():
40  _path=path + k
41  if type(v) == type({}):
42  l = l + self.flatten(v, _path + "/")
43  else:
44  l.append((_path, str(v)))
45  return l
46 
47  def getParams(self):
48  master = roslib.scriptutil.get_master()
49 
50  _c, _t, params = master.getParam(_get_caller_id(), "/")
51  paramlist = self.flatten(params)
52  paramlist.sort()
53 
54  return paramlist
55 
56  def run(self):
57  lastval = ()
58  while 1:
59  try:
60  val = self.getParams()
61  if val != lastval:
62  self.callback(Params(val))
63  lastval = val
64  except:
65  pass
66  time.sleep(3)
67 
68 def main(argv, stdout, environ):
69  progname = argv[0]
70  optlist, args = getopt.getopt(argv[1:], "", ["help", "test", "debug"])
71 
72  p = ParamThread()
73  p.callback = None
74  p.run()
75 
76 if __name__ == "__main__":
77  main(sys.argv, sys.stdout, os.environ)
78 
def __init__(self, params)
Definition: params.py:19
def flatten(self, params, path="/")
Definition: params.py:37
def run(self)
Definition: params.py:56
def setCallback(self, callback)
Definition: params.py:34
def main(argv, stdout, environ)
Definition: params.py:68
def succeed(args)
Definition: params.py:22
def _get_caller_id()
Definition: params.py:14
def getParams(self)
Definition: params.py:47
def __init__(self)
Definition: params.py:29


rosweb
Author(s): Scott Noob Hassan, Rob Wheeler, Nate Koenig
autogenerated on Mon Jun 10 2019 15:51:19