-
Notifications
You must be signed in to change notification settings - Fork 27
/
setinitposes.py
executable file
·52 lines (40 loc) · 1.65 KB
/
setinitposes.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
#!/usr/bin/env python3
#
import sys, time, os
from math import degrees, radians
colors = ['blue', 'red', 'cyan', 'magenta', 'blue', 'red', 'cyan', 'magenta', 'blue', 'red', 'cyan', 'magenta']
def setIP(mapname,vip):
cmd = 'rosparam set initial_pos "'+vip+'"'
print(cmd)
os.system(cmd)
ip = eval(vip)
n = int(len(ip)/2)
print("Set initial poses of ",n," robots")
fnr = 'maps/'+mapname+'/robots.inc'
fr = open(fnr, 'w')
for i in range(0,n):
x = ip[i*2]
y = ip[i*2+1]
th = 90
fn = 'params/amcl/robot_'+str(i)+'_initial_pose.xml'
f = open(fn, 'w')
f.write('<launch>\n')
f.write(' <param name="amcl/initial_pose_x" value="'+str(x)+'"/>\n')
f.write(' <param name="amcl/initial_pose_y" value="'+str(y)+'"/>\n')
f.write(' <param name="amcl/initial_pose_a" value="'+str(radians(th))+'"/>\n')
f.write(' <param name="srrg_localizer/initial_pose_x" value="'+str(x)+'"/>\n')
f.write(' <param name="srrg_localizer/initial_pose_y" value="'+str(y)+'"/>\n')
f.write(' <param name="srrg_localizer/initial_pose_a" value="'+str(radians(th))+'"/>\n')
f.write('</launch>\n')
f.close()
fr.write('crobot( pose [ '+str(x)+' '+str(y)+' 0 '+str(th)+' ] name "robot'+str(i)+'" color "'+colors[i]+'")\n')
if (n==1):
# inactive robot for having correct namespaces
fr.write('crobot( pose [ -2.0 -2.0 0 0.0 ] name "robot1" color "red")\n')
fr.close()
if __name__ == '__main__':
if (len(sys.argv)<3):
sys.exit(0)
mapname = sys.argv[1]
vip = sys.argv[2]
setIP(mapname,vip)