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 options, args = parser.parse_args(argv[1:])
75
76
77 for arg in args:
78 if not arg.startswith('__log:='):
79 parser.error("unrecognized arg: %s"%arg)
80 configure_logging()
81
82 port = rosmaster.master.DEFAULT_MASTER_PORT
83 if options.port:
84 port = int(options.port)
85
86 if not options.core:
87 print("""
88
89
90 ACHTUNG WARNING ACHTUNG WARNING ACHTUNG
91 WARNING ACHTUNG WARNING ACHTUNG WARNING
92
93
94 Standalone zenmaster has been deprecated, please use 'roscore' instead
95
96
97 ACHTUNG WARNING ACHTUNG WARNING ACHTUNG
98 WARNING ACHTUNG WARNING ACHTUNG WARNING
99
100
101 """)
102
103 logger = logging.getLogger("rosmaster.main")
104 logger.info("initialization complete, waiting for shutdown")
105
106 if options.timeout is not None and float(options.timeout) >= 0.0:
107 logger.info("Setting socket timeout to %s" % options.timeout)
108 import socket
109 socket.setdefaulttimeout(float(options.timeout))
110
111 try:
112 logger.info("Starting ROS Master Node")
113 master = rosmaster.master.Master(port, options.num_workers)
114 master.start()
115
116 import time
117 while master.ok():
118 time.sleep(.1)
119 except KeyboardInterrupt:
120 logger.info("keyboard interrupt, will exit")
121 finally:
122 logger.info("stopping master...")
123 master.stop()
124
125 if __name__ == "__main__":
126 main()
127