-
Notifications
You must be signed in to change notification settings - Fork 1
/
send_config.py
executable file
·66 lines (53 loc) · 2.02 KB
/
send_config.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
"""
send_config.py - publish config msg using lcm
Copyright (C) 2015 Eduardo Feo
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import lcm
from configmsg import config_msg_t as config_msg
import sys
import time
from optparse import OptionParser
if __name__ == '__main__':
""" main """
parser = OptionParser(usage="usage: %prog [options] filename",
version="%prog 1.0")
parser.add_option("-f", "--file",
default=None,
help="file containing a config msg per line")
(options, args) = parser.parse_args()
lc = lcm.LCM("udpm://239.255.76.67:7667?ttl=1")
if options.file != None:
for line in open(options.file).readlines():
s = line.split()
rid = int(s[0])
timestamp = int(s[1])
cmd = " ".join(s[2:])
msg = config_msg()
msg.robotid = rid
msg.timestamp = timestamp
msg.msg = cmd
lc.publish("CONFIG", msg.encode())
else:
if len(args) < 3:
print "Invalid number of arguments ", len(sys.argv)
print args
exit(1)
rid = int(args[0])
timestamp = int(args[1])
cmd = " ".join(args[2:])
msg = config_msg()
msg.robotid = rid
msg.timestamp = timestamp
msg.msg = cmd
lc.publish("CONFIG", msg.encode())