1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 """Command-line handler for ROS zenmaster (Python Master)"""
36
37 import logging
38 import os
39 import sys
40 import time
41 import optparse
42
43 import rosmaster.master
44 from rosmaster.master_api import NUM_WORKERS
45
59
60 -def rosmaster_main(argv=sys.argv, stdout=sys.stdout, env=os.environ):
61 parser = optparse.OptionParser(usage="usage: zenmaster [options]")
62 parser.add_option("--core",
63 dest="core", action="store_true", default=False,
64 help="run as core")
65 parser.add_option("-p", "--port",
66 dest="port", default=0,
67 help="override port", metavar="PORT")
68 parser.add_option("-w", "--numworkers",
69 dest="num_workers", default=NUM_WORKERS, type=int,
70 help="override number of worker threads", metavar="NUM_WORKERS")
71 parser.add_option("-t", "--timeout",
72 dest="timeout",
73 help="override the socket connection timeout (in seconds).", metavar="TIMEOUT")
74 parser.add_option("--master-logger-level",
75 dest="master_logger_level", default=False, type=str,
76 help="set rosmaster.master logger level ('debug', 'info', 'warn', 'error', 'fatal')")
77
78 options, args = parser.parse_args(argv[1:])
79
80
81 for arg in args:
82 if not arg.startswith('__log:='):
83 parser.error("unrecognized arg: %s"%arg)
84 configure_logging()
85
86 port = rosmaster.master.DEFAULT_MASTER_PORT
87 if options.port:
88 port = int(options.port)
89
90 if not options.core:
91 print("""
92
93
94 ACHTUNG WARNING ACHTUNG WARNING ACHTUNG
95 WARNING ACHTUNG WARNING ACHTUNG WARNING
96
97
98 Standalone zenmaster has been deprecated, please use 'roscore' instead
99
100
101 ACHTUNG WARNING ACHTUNG WARNING ACHTUNG
102 WARNING ACHTUNG WARNING ACHTUNG WARNING
103
104
105 """)
106
107 logger = logging.getLogger("rosmaster.main")
108 logger.info("initialization complete, waiting for shutdown")
109
110 if options.timeout is not None and float(options.timeout) >= 0.0:
111 logger.info("Setting socket timeout to %s" % options.timeout)
112 import socket
113 socket.setdefaulttimeout(float(options.timeout))
114
115 if options.master_logger_level:
116 levels = {'debug': logging.DEBUG, 'info': logging.INFO, 'warn': logging.WARN, 'error': logging.ERROR, 'fatal': logging.FATAL}
117 if options.master_logger_level.lower() in levels.keys():
118 logger.info("set rosmaster.master logger level '{}'".format(options.master_logger_level))
119 rosmaster.master_api.LOG_API = True
120 logging.getLogger("rosmaster.master").setLevel(levels[options.master_logger_level.lower()])
121 else:
122 logger.error("--master-logger-level received unknown option '{}'".format(options.master_logger_level))
123
124 try:
125 logger.info("Starting ROS Master Node")
126 master = rosmaster.master.Master(port, options.num_workers)
127 master.start()
128
129 import time
130 while master.ok():
131 time.sleep(.1)
132 except KeyboardInterrupt:
133 logger.info("keyboard interrupt, will exit")
134 finally:
135 logger.info("stopping master...")
136 master.stop()
137
138 if __name__ == "__main__":
139 main()
140