-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_nav2d_all.py
1349 lines (1209 loc) · 64.5 KB
/
plot_nav2d_all.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Nov5:
# Collect ALL metrics for 16runs: fi of each subchain = 2/8.
# Plot each perf metric wrt 2or3 low-level metrics.
import math
import sys
import matplotlib.pyplot as plt
import numpy as np
#from sympy import *
#from sympy.geometry import *
import random
import json
slot = 5 # in seconds.
#For plotting area covered in first 60sec: change slot=60, end_t=start_t+60+1.
#slot = 14.0
all_CHAINS = ["Scan_MapCB_MapU_NavP_NavC_LP", "Scan_MapCB_NavCmd_LP","Scan_LC_LP", "Scan_MapCB_NavPlan_NavCmd_LP"]
def get_num_collisions_run(ts_arr, ts_colln_arr, start_ts):
# make clusters of continuous true's
colln_cluster_len = []
colln_cluster_start = []
colln_cluster_end = []
i = 0
last_col_ts = 0.0
while i < len(ts_arr):
while ( ( i < len(ts_arr) ) and (not ts_colln_arr[i]) ):
i += 1
if ( ( i < len(ts_arr) ) and ts_colln_arr[i] ):
st = i
while ( ( i < len(ts_arr) ) and ts_colln_arr[i]):
i += 1
end = i-1
print("GOT a cluster!! s: %i [%f], e: %i [%f]"%(st, ts_arr[st], end, ts_arr[end]) )
colln_cluster_len.append(end - st + 1)
colln_cluster_start.append( st )
colln_cluster_end.append( end )
last_col_ts = (ts_arr[end] - start_ts)
# merge clusters with |end_i - start_i| <= ?
newcolid_colid = {} # new id -> arr of col ids.
if len(colln_cluster_len) > 0:
new_colln_len = []
new_colln_start = []
new_colln_end = []
colid_newcolid = {}
colid_newcolid[0] = 0 # col id -> new col id
newcolid_colid[0] = [0]
for cid in range( len(colln_cluster_len) - 1 ):
ei = colln_cluster_end[cid]
si1 = colln_cluster_start[cid+1]
if (abs(si1-ei) < 3) or ( abs(ts_arr[ei] - ts_arr[si1]) < 10.0): # 0.505 if smallmap, old data
colid_newcolid[cid+1] = colid_newcolid[cid]
print("MERGED cluster %i [ end %i:%f] WITH cluster %i [start %i: %f]"%(cid, ei, ts_arr[ei], cid+1, si1, ts_arr[si1]) )
else:
colid_newcolid[cid+1] = 1+colid_newcolid[cid]
newcolid_colid[ 1+colid_newcolid[cid] ] = []
print("Cluster %i is a new cluster!"%(cid+1) )
newcolid_colid[ colid_newcolid[cid+1] ].append(cid+1)
# return final #colln clusters with >= 5 true's
final_cols = set()
for newid in newcolid_colid.keys():
numvals = sum( [colln_cluster_len[x] for x in newcolid_colid[newid] ] )
if numvals > 5: # 4 if smallmap, old data
final_cols.add( round( ts_arr [ colln_cluster_start[ newcolid_colid[newid][0] ] ] - start_ts, 3 ) )
print("FINAL #nEW COLS : ", len(newcolid_colid), " #COLLISIONS: ", final_cols)
return (final_cols, last_col_ts)
def get_GTarea_time_data(exp_id):
# read OpeMap file: index by last_scan_ts.
'''
arr = []
with open("nav2d_robot_logs_OpeMap_" + exp_id + ".err", 'r') as f:
for l in f.readlines():
if 'ratio of unknown/total area' in l:
mpsz = int(l.split(' ')[-2])
unk = float(l.split(' ')[-3])
known = mpsz - unk
scan_used_ts = int(l.split(' ')[6])
st_ts = float(l.split(' ')[2][:-2] )
#if ( (len(arr) == 0) or (arr[-1][1] < scan_used_ts) ):
arr.append( (known, scan_used_ts, st_ts) )
#print("OPEMAP ARR: line: %s, appening: %i, %i, %f"%(l, known, scan_used_ts, st_ts) )
# read PPMap file, update known based on GTarea:
'''
pparr = []
last_used_tss = {}
# for each OpeMap val, we need the latest PPMap with scants <= val[scants].
with open("nav2d_PPMap_" + exp_id + ".err", 'r') as f:
for l in f.readlines():
if 'ratio of unknown/total area' in l:
mpsz = int(l.split(' ')[-2])
unk = float(l.split(' ')[-3])
known = mpsz - unk
scan_used_ts = int(l.split(' ')[5])
if scan_used_ts in last_used_tss:
print("WEIRDDDD!!!! Repeated last_Scan_used TS!!! ", known, scan_used_ts, " last known area:", last_used_tss[scan_used_ts])
pparr.append((known, scan_used_ts))
last_used_tss[scan_used_ts] = known
'''
if (scan_used_ts <= arr[aind][1]):
ithlist = list(arr[aind])
ithlist[0] = known
arr[aind] = tuple(ithlist)
#print("MODIFYING MapperMap ts %i, ST TS %f, new known ar: %i %i"%(scan_used_ts, arr[aind][2], arr[aind][0], known) )
else:
aind += 1
#else:
#print("WEIRD!!!!! GTMap TS %i and MapperMap %i TS dont match! aind %i, len(opeMapArr) %i "%(scan_used_ts, arr[aind][1], aind, len(arr) ) )
'''
'''
aind = 0
pind = 0
while aind < len(arr):
# find the latest for aind
while pind < len(pparr) and pparr[pind][1] <= arr[aind][1]:
ithlist = list(arr[aind])
ithlist[0] = known
arr[aind] = tuple(ithlist)
pind += 1
print("foR aind %i last scan ts: %i, PP index: %i last scan ts: %i"%(aind, arr[aind][1], pind-1, pparr[pind-1][1]))
aind += 1
'''
return pparr
import math
small_map = ((sys.argv[1]) == "small" ) # whether its the small map
smallest_map = (sys.argv[1] == "smallest")
small_map_obst = ("obst" in sys.argv[1])
print("MAP SIZE: small_map? %i, smallest_map? %i"%(small_map, smallest_map) )
num_phyarea_blocks = 56 if small_map else 100
def get_phy_area(pos_arr):
#small map area : x: -16,16 y: -13.5,13.5
#large map area : ?
# make 4*4 boxes.
#assign each robo locn to a box.
xl=-16 if small_map else -50
xr=16 if small_map else 50
yb=-14 if small_map else -30
yt=14 if small_map else 30
blocksz = 4 if small_map else 5
covered_blocks = {} #block id is x+y
ct = 0
covered_blks_arr = []
for p in pos_arr:
blockx = math.floor( (p[0] - xl) / blocksz )
blocky = math.floor((p[1] - yb)/blocksz)
blockid = str(blockx) + "_" + str(blocky)
ct += 1
if (ct%50 == 7) and (len(covered_blocks) > 26):
print("robot posn : ", p, " block id: ", (blockx, blocky), blockid, " total blocks covered: ", len(covered_blocks) )
if blockid not in covered_blocks:
covered_blocks[blockid] = 0
covered_blocks[blockid] += 1
covered_blks_arr.append(len(covered_blocks))
return covered_blks_arr
# return dict: slot# -> aggregate value.
def aggregate_over_time(m_arr, ts_arr, start_t, slot, end_t):
m_dict = {}
new_m_arr = []
new_ts_arr = []
start_arr = []
# start from startt, any reading
i = 0
curr_ts = start_t
slot_count = 0
#print("#### Func aggregate_over_time called with params: ", slot, start_t, end_t)
#print("Len of array to be aggregated: ", len(m_arr), " 0th TS:", ts_arr[0])
# aggregate until TS > curr_ts + slot.
'''
while (curr_ts + slot) < end_t:
# collect all those in this slot.
this_slot = []
this_slot_ts = []
while i < len(m_arr):
if ts_arr[i] < curr_ts:
i += 1
elif ts_arr[i] <= (curr_ts + slot):
this_slot.append(m_arr[i])
this_slot_ts.append(ts_arr[i])
#print "Adding ind ", i, " TS: ", ts_arr[i], " to slot from ", curr_ts
i += 1
else:
break
#print "Done with this slot, moving to next, i=", i
curr_ts += slot
slot_count += 1
start_arr.append(curr_ts)
if len(this_slot) > 0:
m_dict[slot_count] = this_slot
new_m_arr.append(this_slot)
new_ts_arr.append(this_slot_ts)
'''
while i < (len(m_arr)-1):
# the whole array has not been covered.
if ts_arr[i] < start_t:
i += 1
elif ts_arr[i] > end_t:
i += 1
else:
sl_ct = (ts_arr[i] - start_t)//slot # this is the slot# for this element.
if sl_ct not in m_dict:
m_dict[sl_ct] = []
m_dict[sl_ct].append(m_arr[i])
i += 1
return m_dict
# For intra run metrics:
# 2.5s windows....
tput_agg = { } # SC name -> list of dicts.
rt_agg = {} # chain name -> list of dicts: {slot#->aggregateVal}, one dict for each i.
tput_cc_agg = [] # list of dicts for Tput cc.
odom0_frac_agg = [] # list of dicts, one for each Frac_expt. slot# -> frac of time v=0.
obst_colln_agg = [] # list of dicts, slot# -> Time (d <= 0.8) / Time (d <= 2)
obst_ccall_agg = [] # list of dicts, slot# -> Time (d <= 1.4) / Time (d <= 2)
new_area_agg = [] # list of dicts, slot# -> Total new area seen in this time slot.
collision = {} # frac9A_run1 -> # obstacle collision readings.
runlevel_total_area_expl = {} # exp_id -> area expl.
runlevel_meantputs = {} # exp id -> array of mean tputs [mU,mC,nC,nP,CC]
runlevel_meanRTs = {} # exp id -> array of mean RTs ["Scan_MapCB_MapU_NavP_NavC_LP", "Scan_LC_LP", "Scan_MapCB_NavCmd_LP", "Scan_MapCB_NavPlan_NavCmd_LP"]
run_final_data = {}
def mean_aggregate(agg_dict):
mean_dict = {}
for k in agg_dict.keys():
mean_dict[k] = sum ( agg_dict[k] ) / len ( agg_dict[k] )
return mean_dict
def plot_perf_metric(perf_agg_arr, metr_agg_arr, p,m, slt,plot_first=False):
data_arr = []
print("######## Plotting ", p, " vs", m, len(perf_agg_arr), len(metr_agg_arr))
data0_arr = []
colors = ['red', 'blue', 'cyan', 'purple', 'green', 'orange']
for a in range(len(perf_agg_arr)):
di_arr = []
if plot_first:
data0_arr.append( (metr_agg_arr[a][0], perf_agg_arr[a][0]) )
for b in perf_agg_arr[a].keys():
if b in metr_agg_arr[a]:
#print "For Frac", a, " slot#",b, " present in both", (metr_agg_arr[a][b], perf_agg_arr[a][b])
di_arr.append( (metr_agg_arr[a][b], perf_agg_arr[a][b]) )
data_arr.append( (metr_agg_arr[a][b], perf_agg_arr[a][b]) )
s_di_arr = sorted(di_arr, key=lambda x: x[0])
xi_arr = [x[0] for x in s_di_arr]
yi_arr = [x[1] for x in s_di_arr]
# divide by num expts for each Fraci :
plt.scatter(xi_arr, yi_arr, color=colors[a//10])
s_data_arr = sorted(data_arr, key=lambda x: x[0])
xarr = [x[0] for x in s_data_arr]
yarr = [x[1] for x in s_data_arr]
#plt.scatter(xarr, yarr)
plt.title('Perf metric %s vs Low-Level metric %s, Agg over %f'%(p,m, slt) )
#plt.show()
plt.savefig("Dec4_nav2d_" + p + "_" + m + "_" + str(int(slt)) + "s.png")
if plot_first:
s_d0 = sorted(data0_arr, key=lambda x: x[0])
xarr = [x[0] for x in s_d0]
yarr = [x[1] for x in s_d0]
plt.scatter(xarr, yarr)
plt.title('Perf metric %s vs Low-level metric %s, In first slot of %f s'%(p,m, slt) )
plt.show()
def plot_runlevel_agg(xarr, yarr, titl, yl, xl, yli=0.0, mean=[], tail=[], counts=[]):
#plt.scatter(xarr, yarr, color=col)
plt.plot(xarr, yarr, 'b*--', markersize=9, linewidth=3, label=yl)
if len(mean) > 0:
plt.plot(xarr, mean, 'g.-.', markersize=9, linewidth=3, label="Mean "+yl)
if len(tail) > 0:
plt.plot(xarr, tail, 'r^:', markersize=9, linewidth=3, label="Tail "+yl)
if len(counts) > 0:
print("ABOUT to print texts, xarr: ", xarr, " At ht: ", 0.9*min(yarr), " Counts: ", counts)
for i in range(len(xarr)):
# random no b/w i - i+1 / len(xarr)
plt.text(xarr[i], 0.5*min(yarr)+random.uniform( (i*min(yarr)*0.5)/(len(xarr)), ((i+1)*min(yarr)*0.5)/len(xarr) ), str(counts[i]) )
plt.xlabel(xl)
plt.ylabel(yl)
plt.legend(loc='best')
if yli>0.0:
plt.ylim(0.0,yli)
elif len(tail) > 0:
plt.ylim(0.0, max(tail))
else:
plt.ylim(0.0, max(yarr))
plt.title(titl)
plt.show()
def plot_cdfs(arrs, labels, titl, xl):
print("PLOTTING CDFs, Len(arrs): %i, Til: %s, Xlabel: %s"%( len(arrs), titl, xl ) )
cols = ['olive', 'magenta', 'teal', 'chocolate', 'red', 'blue', 'cyan', 'purple', 'green', 'orange'] #['b.:', 'r.:', 'g.:', '']
for i in range(len(arrs)):
arr = arrs[i]
sa = np.sort(arr)
pr = 1. * np.arange(len(arr))/(len(arr) - 1)
plt.plot(sa, pr, '.:', color=cols[i], linewidth=2, label=labels[i])
plt.title(titl + " CDF")
plt.xlabel(xl)
plt.legend(loc='best')
plt.show()
def plot_scatter(xarr, medyarr_arr_d, tailyarr_arr_d, x_name, y_name):
colors = ['red', 'blue', 'cyan', 'purple', 'green', 'orange']
for i in range(len(xarr)):
med_pts_x = []
tail_pts_x = []
med_pts_y = []
tail_pts_y = []
for j in range(len(medyarr_arr_d[i])):
med_pts_x.append( xarr[i] )
med_pts_y.append( medyarr_arr_d[i][j] )
tail_pts_x.append( xarr[i] )
tail_pts_y.append( tailyarr_arr_d[i][j] )
plt.scatter( med_pts_x, med_pts_y, marker='*', color=colors[i] )
plt.scatter( tail_pts_x, tail_pts_y, marker='^', color=colors[i] )
plt.xlabel('Set period for %s'%(x_name))
plt.ylabel('Resulting %s (s)'%(y_name) )
plt.title('[*: Med, ^: 75ile]Metric %s w.r.t Varying Period of %s'%(y_name, x_name))
plt.show()
# return true of e11-e21 line segment intersets with e21-e22
# treat each wall as 2 lines, thickness apart
# each robot/obstacle as 4lines.
def edges_intersect(e1,e2):
'''
p11 = Point2D(e11)
p12 = Point2D(e12)
p21 = Point2D(e21)
p22 = Point2D(e22)
e1 = Segment2D(p11,p12)
e2 = Segment2D(p21,p22)
'''
ans = intersection(e1,e2)
return (len(ans) > 0)
# closest dist bw 2 edges.
def get_closest_edge_dist(e1,e2):
# TODO
x=1
# get 4edges of the robot, return Segment2D.
def get_robot_edges(px,py,oz,ow):
ts = oz
tc = ow
tantheta = ts*float((2*tc)/((2*tc*tc) - 1.0)) # tan(theta) as a func of sin theta/2 and cos theta/2
ang = math.atan(tantheta)
print("Robot posn : px %f,py %f, ts: %f, tc: %f, Found angle: %f"% ( px,py,oz,ow,ang ) )
rsq = RegularPolygon( Point2D(px,py) , 0.3*sqrt(2), 4, ang - pi/4 )
# ox : sin theta/2, ow : cos theta/2
verts = rsq.vertices
return [ Segment2D(verts[0], verts[1]), Segment2D(verts[1], verts[2]), Segment2D(verts[2], verts[3]), Segment2D(verts[3], verts[0]) ]
def get_obstacle_no_stage(x,y):
# colln setup : obst1 : y: ? to ?, obst2:
if smallest_map:
if (x >= 1.5) and (x <= 6.0):
if (y < 3.17):
return 1
else:
return 2
else:
return -1
elif small_map and small_map_obst:
if (x >= -7) and (x <= -1) and (y >= -1) and (y <= 5):
return 1 # robot1 is line_no+1
elif (x >= -15) and (x <= -9) and (y >= -2) and (y <= +4):
return 2 # robot2 is line_no+2
elif (x >= 1) and (x <= 7) and (y >= 6) and (y <= 12) :
return 3 # robot3 is line_no+3
elif (x >= 0.9) and (x <= 7) and (y >= 1) and (y <= 5.5):
return 4 # robot4 is line_no+4
elif (x >= 9) and (x <= 15) and (y <= -2.5) and (y >= -7):
return 5
elif (x <= 0) and (x >= -8) and (y >= 9) and (y <= 13):
return 6
elif (x <= -8) and (x >= -16) and (y >= 9) and (y <= 13):
return 7
elif (x >= 0) and (x <= 4.5) and (y >= -13) and (y <= -8):
return 8
else:
return -1
elif small_map and (not small_map_obst):
if (x >= -7) and (x <= -1) and (y >= -1) and (y <= 5):
return 1
else:
return -1
else:
if (x >= -27) and (x <= -17) and (y >= -11) and (y <= -5):
return 1
elif (x >= 5.5) and (x <= 11.5) and (y >= -14) and (y <= -5):
return 2
elif (x >= 0) and (x <= 5.5) and (y >= 5) and (y <= 13):
return 3
elif (x >= 7) and (x <= 15) and (y >= 7) and (y <= 13):
return 4
elif (x >= 13) and (x <= 22) and (y >= -11) and (y <= -5):
return 5
elif (x >= -28) and (x <= -19) and (y >= 9.5) and (y <= 15.5):
return 6
elif (x >= -18) and (x <= -10) and (y >= -3) and (y <= 3):
return 7
elif (x >= -18.5) and (x <= -9) and (y >= 5.0) and (y <= 10.0):
return 8
else:
return -1
def get_dist(x1,y1,x2,y2):
return math.sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))
walls_p1 = [ [0,1], [0,6], [0,8], [2.25,1], [2.25,0.75], [-5.75,9], [-5.75,8.75], [-8.5,9], [-9.5,7], [-9.5,-4] ]
walls_p2 = [ [0,6], [8,6], [0,13], [8,1], [8,0.75], [0,9], [0,8.75], [-7.5,9], [-6.5,7], [-6.5,-4] ]
walls_shortedges_p1 = [ [2.3,0.75], [-5.75,8.75] ]
walls_shortedges_p2 = [ [2.3,1.0], [-5.75,9] ]
# todo: Make each 2Sided wall with two Segments.
#wall thickness: ~0.25
def get_closest_wall_dist(x,y):
walls_p1 = [ np.array(z) for z in walls_p1 ]
walls_p2 = [ np.array(z) for z in walls_p2 ]
pt = np.array([x,y]) #p3
closest_dist = 100.0
closest_wall = -1
for wi in range(len(walls_p1)):
p2 = walls_p2[wi]
p1 = walls_p1[wi]
try:
dist = np.cross(p2 - p1, pt - p1)/np.linalg.norm(p2 - p1)
# need to add dist from a corner if
c1_dist = get_dist(x,y, p1[0], p1[1])
except:
print( p1, p2, pt, "Input:", x,y)
if dist <= closest_dist:
closest_dist = dist
closest_wall = wi
return (closest_dist, closest_wall)
# sometimes, the robot collides with an obst & gets stuck, but the navPlan still keeps planning!! check for that:
# return 'end TS', expl_finish etc info.
def check_limbo_run(exp_id, smallest_map, small_map_obst):
# logic: get last posn, see since when its same posn [dx,dy small]
stall_start_ts_st = 0.0
stall_start_ts_rt = 0.0
last_ts_rt = 0.0
start = False
with open('../robot_nav2d_obstacleDist_logs_' + exp_id + '.txt', 'r') as f:
fl = f.readlines()
num_obst = 2 if smallest_map else 1 if (not small_map_obst) else 8
numl = (num_obst+3)
last_pos_x = 0.0
last_pos_y = 0.0
arr = reversed(range(len(fl)//numl))
for o in reversed(range(len(fl)//numl)):
rob_pos = o*numl + 1
rob_pos_l = fl[rob_pos].split(' ')
rob_x = float(rob_pos_l[1])
rob_y = float(rob_pos_l[2][:-1])
if not start:
start = True
last_ts_rt = float(fl[o*numl].split(' ')[3])
print("STARTING now! last ts rt: ", last_ts_rt, ", o: ", o, len(fl))
'''
last_pos_x = rob_x
last_pos_y = rob_y
elif (last_pos_x-rob_x) < 0.01 and () > 0.01:
'''
rob_stalled = fl[o*numl + num_obst + 2].split(' ')[9]
if "\n" in rob_stalled:
rob_stalled = rob_stalled[:-1]
if int(rob_stalled) == 1:
stall_start_ts_st = float(fl[o*numl].split(' ')[1])
stall_start_ts_rt = float(fl[o*numl].split(' ')[3])
else:
break # break the for loop.
buffer_time = 5.0
print("$$$$$ LIMBO RUN: %s, was stalled from ts: %f to %f"%(exp_id, stall_start_ts_rt, last_ts_rt) )
return (stall_start_ts_st + buffer_time*5, stall_start_ts_rt+buffer_time)
# Walls:Thichness is ~0.25
# w1: (0,1) - (0,6) : 2sided
# w2: (0,5.6) - (8,5.6) : 2sided
# w3: (0,8) - (0,13) : 2sided
# w4: (3,0.89) - (8,0.89) : 2sided
# w5: (-5.7,8.89) - (0,8.89) : 2sided
# w6: (-8.5,9) - (-7.5,9)
# w7: (-9.5,7) - (-6.5,7)
# w8: (-9.5,-4) - (-6.5,-4)
letter = 'N'
#opt_total_Area = 339142.0
opt_total_Area = 242367.0 if smallest_map else 339142.0 if small_map else 818045.0
opt_total_gtArea = 215591 if small_map else 155890.0 # GTArea as per PostProcessing
# LMap: 818045, 817667, 818141, 817838
#opt_total_Area = 818045.0
runlevel_agg_lowlevelmetrics = [] # list of lists.
runlevel_agg_lowlevelmetrics_dict = {} # metric name -> value. [median in runs, then ?]
runlevel_agg_collision_count = [] # one no for each i.
runlevel_agg_path_plan_fail_count = []
run_level_total_times = [] # list of lists
runlevel_agg_lowestTTC = [] # lowest time to collision. Inf. if no collision.
runlevel_mean_totalarea = []
runlevel_med_totalarea = [] # one no for each i.
runlevel_tail_totalarea = [] #9th area.
runlevel_med_0veltime = []
runlevel_mean_0veltime = []
runlevel_tail_0veltime = []
runlevel_agg_fullExpl_count = []
runlevel_mean_fullExplTime = []
runlevel_med_fullExplTime = [] #For each expt i, Median of expl time over all runs that finished & explored >=0.9*totalArea.
runlevel_tail_fullExplTime = []
runlevel_means = {"TotalExplTime": []}
runlevel_meds = {"TotalExplTime": []}
runlevel_tails = {"TotalExplTime": []}
runlevel_med_time80area = [] # Median Time taken to cover 80% area.
runlevel_tail_time80area = [] # Tail Time taken to cover 80% area.
runlevel_mean_time80area = []
counts_80area = [] # no. of runs per expt which cover atleast 80p area.
runlevel_med_time60area = [] # Median Time taken to cover 60% area.
runlevel_tail_time60area = [] # Tail Time taken to cover 60% area.
runlevel_mean_time60area = []
counts_60area = []
runlevel_med_pathlen = []
runlevel_mean_pathlen = []
runlevel_tail_pathlen = []
runlevel_med_areabypath = []
runlevel_mean_areabypath = []
runlevel_tail_areabypath = []
runs_tput_arrs = {} # i_subchainName -> array of [tputs] for each run.
runs_med_tputs = {} # subchain name -> array[over is] of arrays[over runs].
runs_mean_tputs = {} # subchain name -> array[over is] of arrays[over runs].
runs_75p_tputs = {} # subchain name -> array[over is] of arrays[over runs].
exptn = "OfflineMCB_H"
expts = [ "StaticNOFF1Y_1c" ] #,"DefSM4V3_1c_CC2" ,"DefaultTD_2c"]
#runs = range(5, 8) + range(31,48)
runs = range(1,26)
for badr in [3,10,13,17,21]: #[2,5,8,15,17]: #57,89]: #[3,20,25,28,31,40,51,55]:
runs.remove(badr)
print(runs, len(runs))
#for i in [1,2,3,4,5,6]: #1,3,6,7,8,9]:
run_rts_percentile = 90 #50
run_lats_percentile = 90
for i in expts:
run_start_rt_ts = []
run_totalareas = []
run_total_gtareas = []
run_tputs = {} # name -> list
run_rts = {} # chain name -> list
run_lats = {} # chain name -> list
run_ttc = []
if i == 2:
runs = [1,3,4,5]
colln_count = 0 # #runs with collision.
new_colln_count = 0 # total #collns across all runs.
path_plan_fail_count = 0
run_total_times = []
irun_75p_tput = {} # subchain name -> array.
irun_mean_tput = {} # subchain name -> array. for a given expt i.
vel0_frac_arr = [] # vel0 fraction for each run.
fullExplTimes = [] # include expl time only if finished & area > 0.9*opt.
time_80area = [] # for each run, time to cover 80% of area. [in terms of known_area]
time_60area = [] #20: [], 30: [], for each run, time to cover 60% of area. [in terms of known_area]
time_areas = { 40: [], 50: [], 55: [], 60: [], 65: [], 70: [], 75: [], 80: [], 85: [], 90: [], 95: []}
time_st_areas = { 40: [], 50: [], 55: [], 60: [], 65: [], 70: [], 75: [], 80: [], 85: [], 90: [], 95: []}
time_st_gt_areas = { 40: [], 50: [], 55: [], 60: [], 65: [], 70: [], 75: [], 80: [], 85: [], 90: [], 95: []}
area_time_zip_arr = []
area_time_agg_dict = { 20: [], 100: [] } # smallest map : 100s is too coarse.
gt_area_time_agg_dict = { 20: [], 100: [] }
if smallest_map:
area_time_agg_dict[50] = []
gt_area_time_agg_dict[50] = []
colln_count_arr = []
time_to_areas = [] # arr of dicts
stime_to_areas = [] # arrof dicts
stime_to_gt_areas = [] #arr of dicts
clean_finish_arr = [] # whether each run was a clean [>90p area & expl finished] exit.
run_finish_arr = [] # whether the robot claimed expl had finished.
runs_colln_end_arr = [] # whether there was a collision in the end of the run [last 10s ST]
run_time_phyarea = []
run_pathlens = [] # Distance travelled by robot
run_areabypaths = [] # ratio of area covered to path length.
for run in runs: #1,2]:
run_collision_hua = False
run_collision_count = 0
run_collision_end = False
stall_ct = 0
sto_ct = 0
run_expl_finished = False
run_expl_clean_finish = False
run_path_plan_fail = False
#exp_id = str(i) + letter +'run_' + str(run)
exp_id = i + ('_r' if smallest_map else '_run') + str(run)
exp_id = i + '_run' + str(run)
collision[exp_id] = {}
# get start, end times
start_i = 0.0
start_rt_i = 0.0
start_st_i = 0.0
end_i = 0.0
end_st_i = 0.0
#run = 2 if (i > 1) else 1
#run = 2
print("Starting Frac",i, "run:",run)
with open("nav2d_robot_logs_" + exp_id + ".err", 'r') as f:
for fl in f.readlines():
if "received StartExploration service action" in fl:
start_i = float( fl.split(' ')[11][:-1] )
start_rt_i = float( fl.split(' ')[1][1:-1] )
start_st_i = float( fl.split(' ')[2][:-2] )
if ( ("Exploration has failed" in fl) or ("Exploration has finished" in fl) ) and "Time of finish" in fl:
end_i = float( fl.split(' ')[-2] )
end_st_i = float( fl.split(' ')[2][:-2] )
if ("Exploration has finished" in fl):
run_expl_finished = True
if ("No way between robot and goal!" in fl):
run_path_plan_fail = True
if ("Exploration failed." in fl):
end_rt_i = float( fl.split(' ')[1][1:-1] )
end_i = start_i + (end_rt_i - start_rt_i)
end_st_i = float( fl.split(' ')[2][:-2] )
end_i += 0.1 # expl should fail after the collision for the collision to count.
if (end_i == 0.1):
end_st_i, end_i = check_limbo_run(exp_id, smallest_map, small_map_obst)
print("For i ", i, " Start, end times: ", start_i, end_i, " ST start %f end %f"%(start_st_i,end_st_i) )
run_total_times.append(round(end_st_i - start_st_i - 0.1,2))
run_finish_arr.append( run_expl_finished )
run_start_rt_ts.append(start_i)
# store each run's metrics as dict: window# -> value
# so its easier to take intersection of set of keys of all metrics.
# Get tput for each subchain
runlevel_meantputs[exp_id] = []
for fname in ["mapper_mapUpdate", "mapper_scanCB", "navigator_cmd", "navigator_plan"]:
print("Starting ", fname)
if fname not in runlevel_agg_lowlevelmetrics_dict:
runlevel_agg_lowlevelmetrics_dict[fname] = []
tput_agg_i = {}
tput_arr = []
ts_arr = []
try:
with open("../robot_nav2d_" + fname + "_stats_" + exp_id + ".txt", 'r') as f:
for fl in f.readlines():
if "tput:" in fl:
tput_arr += [ float(x) for x in fl.split(" ")[2:-1] ]
elif "ts:" in fl:
ts_arr += [ float(x) for x in fl.split(" ")[2:-1] ]
if fname not in run_tputs:
run_tputs[fname] = []
irun_75p_tput[fname] = []
irun_mean_tput[fname] = []
if (len(ts_arr) < 1):
run_tputs[fname].append( np.median(tput_arr) ) #sorted(tput_arr)[ len(tput_arr)/2 ] )
irun_75p_tput[fname].append( sorted(tput_arr)[ (75*len(tput_arr))/100 ] )
irun_mean_tput[fname].append( np.mean(tput_arr) )
tput_agg_i = aggregate_over_time(tput_arr, ts_arr[1:], start_i, slot, end_i)
#if "mapU" in fname:
#print(tput_agg_i, tput_arr, ts_arr, ":::: HERE'S the tput_agg_i")
meantput_agg_i = {}
new_tput_arr = [] # only keep the ones within start_i, end_i.
new_ts_arr = [] # APPROXIMATE TS of the tput values.
# ignore the first tput reading, might be delay due to gap bw StartMap, StartExpl.
mink = min(tput_agg_i.keys() )
for k in tput_agg_i.keys():
if (k == mink):
# Delete first tput elem.
if ( len( tput_agg_i[k][1:] ) > 0 ):
meantput_agg_i[k] = sum( tput_agg_i[k][1:] ) / len( tput_agg_i[k][1:] )
new_tput_arr += tput_agg_i[k][1:]
new_ts_arr += [ (k*slot + start_i) for x in tput_agg_i[k][1:] ]
else:
meantput_agg_i[k] = sum( tput_agg_i[k] ) / len ( tput_agg_i[k] )
new_tput_arr += tput_agg_i[k]
new_ts_arr += [ (k*slot + start_i) for x in tput_agg_i[k] ]
#print("For Frac%i%s_run%i : tput of SC%s for bin %i has just 1 elem!"%(i,letter, run,fname,k))
if fname not in tput_agg:
tput_agg[fname] = []
tput_agg[fname].append(meantput_agg_i)
runlevel_meantputs[exp_id].append( np.mean(new_tput_arr) ) #sum(tput_arr)/len(tput_arr) ) #Saving tput means
#run_tputs[fname].append( sum(tput_arr)/len(tput_arr) ) : Mean over each run.
run_tputs[fname].append( np.median(new_tput_arr) ) #sorted(tput_arr)[ len(tput_arr)/2 ] )
irun_75p_tput[fname].append( sorted(new_tput_arr)[ (75*len(new_tput_arr))/100 ] )
irun_mean_tput[fname].append( np.mean(new_tput_arr) )
if ("H4" in exp_id and "CB" in fname):
tput_ts = zip(new_tput_arr, new_ts_arr)
if (i + "_" + fname) not in runs_tput_arrs:
runs_tput_arrs[i + "_" + fname] = []
runs_tput_arrs[i + "_" + fname].append( new_tput_arr )
print("Here's the sorted tput array: ", sorted(tput_ts, key=lambda x: x[0]), len(new_tput_arr))
print("NP Median %f, sorted[1/2]: %f"%( np.median(new_tput_arr), sorted(new_tput_arr)[len(new_tput_arr)/2] ) )
except:
print("EXCEPTION In exp %s, for getting tput of node %s, Exception: %s"% (exp_id, fname, sys.exc_info()[0]) )
'''
if "_cmd" in fname and "H5_5c_run6" in exp_id:
if fname not in run_tputs:
run_tputs[fname] = []
irun_75p_tput[fname] = []
run_tputs[fname].append(1.25)
irun_75p_tput[fname].append(1.25)
'''
if "_plan" in fname and "NP" not in exp_id and "AllL" in exp_id:
if fname not in run_tputs:
run_tputs[fname] = []
irun_75p_tput[fname] = []
irun_mean_tput[fname] = []
run_tputs[fname].append(10.0)
irun_75p_tput[fname].append(10.0)
irun_mean_tput[fname].append(10.0)
# Get RT, Lat, Tput for each chain
runlevel_meanRTs[exp_id] = []
with open('../robot_nav2d_' + exp_id + "_rt_stats.txt", 'r') as f:
fl = f.readlines()
for chain in all_CHAINS: #["Scan_MapCB_MapU_NavP_NavC_LP", "Scan_LC_LP", "Scan_MapCB_NavPlan_NavCmd_LP"]: #"Scan_MapCB_NavCmd_LP",
print("Starting chain ", chain)
rts = []
ts = []
tputs = []
lats = []
if chain not in rt_agg:
rt_agg[chain] = []
if chain not in runlevel_agg_lowlevelmetrics_dict:
runlevel_agg_lowlevelmetrics_dict[chain] = []
for l in fl:
if chain in l:
if "RT_" in l:
rts += [ float(x) for x in l.split(' ')[1:-1] ]
elif "TS_" in l:
ts += [ float(x) for x in l.split(' ')[1:-1] ]
elif "Tput" in l:
tputs += [ float(x) for x in l.split(' ')[1:-1] ]
elif "Latency" in l:
lats += [ float(x) for x in l.split(' ')[1:-1] ]
# aggregate the RTs array, then add slot_mean_dict to rt_agg.
runlevel_meanRTs[exp_id].append( 5.0 )
chainrt_agg_i = aggregate_over_time(rts, ts[1:], start_i, slot, end_i)
rt_agg[chain].append(mean_aggregate(chainrt_agg_i) )
if chain not in run_rts:
run_rts[chain] = []
run_lats[chain] = []
try:
run_rts[chain].append( np.percentile(rts, run_rts_percentile ) )
run_lats[chain].append( np.percentile(lats, run_lats_percentile ) )
except:
print("EXCEPTION in getting rts/lats for chain %s, exp: %s"%(chain, exp_id) )
if "LC_LP" in chain:
# print "Here's CC RT: ", rt_agg[chain][-1]
tput_cc_agg_i = aggregate_over_time(tputs, ts[1:], start_i, slot, end_i)
tput_cc_agg.append(mean_aggregate(tput_cc_agg_i) )
# print "GOT CC tput", tput_cc_agg[-1]
if len(tputs) > 0:
runlevel_meantputs[exp_id].append( np.mean(tputs) ) #sum(tputs)/len(tputs) )
if chain+"_tput" not in run_tputs:
run_tputs[chain+"_tput"] = []
irun_75p_tput[chain+"_tput"] = []
irun_mean_tput[chain+"_tput"] = []
if chain + "_tput" not in runlevel_agg_lowlevelmetrics_dict:
runlevel_agg_lowlevelmetrics_dict[chain + "_tput"] = []
#run_tputs[chain].append( sum(tputs)/len(tputs) )
try:
run_tputs[chain+"_tput"].append( np.median(tputs) ) # Median over each run
irun_75p_tput[chain+"_tput"].append( sorted(tputs)[(75*len(tputs))/100] ) # 75%ile over each run.
irun_mean_tput[chain+"_tput"].append( np.mean(tputs) )
if ("H5" in exp_id):
# need to plot cdf for cc, H7.
if (i + "_" + chain) not in runs_tput_arrs:
runs_tput_arrs[i + "_" + chain] = []
runs_tput_arrs[i + "_" + chain].append( tputs )
except:
print("Exception in CC_Tput reading!!! len of tputs: ", len(tputs))
if "CC" not in exp_id and "AllLow" in exp_id:
run_tputs[chain+"_tput"].append(1.0)
irun_75p_tput[chain+"_tput"].append(1.0)
irun_mean_tput[chain+"_tput"].append(1.0)
raise
# Get intra run perf metrics
# 1. Odometry v=0 fraction per 2s
run_path_len_sum = 0.0
with open('../robot_nav2d_obstacleDist_logs_' + exp_id + '.txt', 'r') as f:
num_obst = 2 if smallest_map else 1 if (not small_map_obst) else 8
obfl = f.readlines()
numl = (num_obst+3)
ts_arr = []
st_ts_arr = []
ts_colln_bool_arr = []
robo_odom_arr = []
robo_ang_odom_arr = []
obst_dist_arr = []
obst_ts_arr = []
wall_dist_arr = []
old_pos_x = 0.0
old_pos_y = 0.0
path_started = False
robo_posn_arr = []
for o in range(len(obfl)//numl):
rob_pos = o*numl + 1
rob_pos_l = obfl[rob_pos].split(' ')
rob_x = float(rob_pos_l[1])
rob_y = float(rob_pos_l[2][:-1])
obst_ind = get_obstacle_no_stage(rob_x, rob_y)
#closest_wall_dist, wall_id = get_closest_wall_dist(rob_x,rob_y)
closest_wall_dist, wall_id = 100,-1
wall_dist_arr.append( closest_wall_dist )
# read TS:
try:
pos_st_ts = float(obfl[o*numl].split(' ')[1])
pos_rt_ts = float(obfl[o*numl].split(' ')[3])
except:
print("ERROR in numl = %i, o: %i, line split: "%(numl,o), obfl[o*numl].split(' ') )
raise
if ( (pos_rt_ts > start_i) and (pos_rt_ts < end_i) ):
# Calculating dist travelled for pathlen:
if not path_started:
path_started = True
else:
run_path_len_sum += get_dist(rob_x,rob_y,old_pos_x,old_pos_y)
old_pos_x = rob_x
old_pos_y = rob_y
vx = float( obfl[o*numl + num_obst + 2].split(' ')[1] )
vy = float( obfl[o*numl + num_obst + 2].split(' ')[2] )
robo_odom_arr.append( math.sqrt( vx*vx + vy*vy ) )
try:
vang = float( obfl[o*numl + num_obst + 2].split(' ')[4] )
#if o%2000 == 77:
#print("VELS for o=", o,vx,vy,vang)
#print "Dist from closest wall:", rob_x, rob_y, wall_id, closest_wall_dist
av = math.sqrt( vx*vx + vy*vy + vang*vang)
robo_ang_odom_arr.append( av )
except:
print("PROBLEM in reading vang for o: ", o)
raise
# get orientation
oz = float( obfl[o*numl + num_obst + 2].split(' ')[6] )
ow = float( obfl[o*numl + num_obst + 2].split(' ')[7] )
robo_posn_arr.append((rob_x, rob_y))
ts_arr.append(pos_rt_ts)
st_ts_arr.append(pos_st_ts)
ts_colln_hua = False
rob_stalled = obfl[o*numl + num_obst + 2].split(' ')[9]
if "\n" in rob_stalled:
rob_stalled = rob_stalled[:-1]
if ( (pos_rt_ts > start_i) and (pos_rt_ts < end_i) and (int( rob_stalled ) == 1) ):
run_collision_hua = True
ts_colln_hua = True
stall_ct += 1
#if "St_O" in obfl[o*numl + num_obst + 2].split(' '):
#print(obst_ind, obfl[o*numl + num_obst + 2], "St_O!!!!")
if obst_ind != -1:
obst_line = obfl[rob_pos + obst_ind].split(' ')
obst_x = float(obst_line[1])
obst_y = float(obst_line[2][:-1]) # remove \n.
dist = get_dist(rob_x, rob_y, obst_x, obst_y)
obst_ts_arr.append(pos_rt_ts)
obst_dist_arr.append(dist)
if "St_O" in obfl[o*numl + num_obst + 2]:
#print("St_O!!!!!! obst ind %i, line %s, dist %f, rt TS: %f"%(obst_ind, obfl[o*numl + num_obst + 2], dist, pos_rt_ts) )
if (dist < 1.5) and ((pos_rt_ts > start_i) and (pos_rt_ts < end_i)) :
# collision! check pos of robot and this obst
run_collision_hua = True
ts_colln_hua = True
sto_ct += 1
ts_colln_bool_arr.append(ts_colln_hua)
run_collision_count, last_colln_ts = get_num_collisions_run(st_ts_arr, ts_colln_bool_arr, start_st_i)
phy_area_numblocks_arr = get_phy_area(robo_posn_arr)
phyarea_iter_ct = 0
curr_blk_ct = phy_area_numblocks_arr[0]
this_run_time_parea_dict = {}
this_run_time_parea_dict[curr_blk_ct] = (st_ts_arr[0] - start_st_i)
while phyarea_iter_ct < len(phy_area_numblocks_arr):
while phyarea_iter_ct < len(phy_area_numblocks_arr) and phy_area_numblocks_arr[phyarea_iter_ct] == curr_blk_ct:
phyarea_iter_ct += 1
if phyarea_iter_ct < len(phy_area_numblocks_arr) and phy_area_numblocks_arr[phyarea_iter_ct] != curr_blk_ct:
curr_blk_ct = phy_area_numblocks_arr[phyarea_iter_ct]
this_run_time_parea_dict[curr_blk_ct] = (round(st_ts_arr[phyarea_iter_ct] - start_st_i,2))
print("FOR exptid : ", exp_id, " time_phyarea : ", this_run_time_parea_dict)
run_time_phyarea.append(this_run_time_parea_dict)
'''
if ( pos_rt_ts > (end_i - (end_i - start_i)/10 ) ) and (pos_rt_ts < (end_i + 1.0) ):
robot_edges = get_robot_edges(rob_x, rob_y, oz, ow) # gives an arr of 4segments.
colln = False
#if (o%100 == 7):
print("GOING to try for CollisionDETECTion at o=%i,robx=%f,roby=%f, edges: %i"%(o,rob_x,rob_y, len(robot_edges) ) )
for redg in robot_edges:
print("STARTing to check edge ", redg)
for i in range( len(walls_p1) ):
if (not colln):
wi = Segment2D( Point2D(walls_p1[i]), Point2D(walls_p2[i]) )
colln = colln or (edges_intersect(redg, wi) )
print("CHECKed walls1")
for i in range( len(walls_shortedges_p1) ):
if (not colln):
wi = Segment2D( Point2D(walls_shortedges_p1[i]), Point2D(walls_shortedges_p2[i]) )
colln = colln or (edges_intersect(redg, wi))
print("CHECKed walls short")
if colln:
print("For Frac%i%s_run%i : Collision with wall!! at time %f, robx: %f, roby: %f"%(i,letter,run,pos_rt_ts,rob_x,rob_y) )
if ( (obst_ind != 1) and (not colln) ):
obst_edges = get_robot_edges(obst_x, obst_y, 0, 1) # obstacles always ||al to axes.
for oedg in obst_edges:
if (not colln):
colln = colln or ( edges_intersect(oedg, redg) )
if colln:
print("For Frac%i%s_run%i : Collision with obstacle!! at time %f, robx: %f, roby: %f"%(i,letter,run,pos_rt_ts,rob_x,rob_y) )
collision[exp_id][pos_rt_ts] = True
'''
odom_agg_i = aggregate_over_time(robo_odom_arr, ts_arr, start_i, slot, end_i)
odom_ang_agg_i = aggregate_over_time(robo_ang_odom_arr, ts_arr, start_i, slot, end_i)
odom0_agg_i = {}
total_vel0_count = 0
for k in odom_ang_agg_i.keys():
ct = 0
for x in odom_ang_agg_i[k]:
if x < 0.01:
ct += 1
total_vel0_count += 1
odom0_agg_i[k] = float(ct) / len(odom_ang_agg_i[k])
odom0_frac_agg.append(odom0_agg_i)
vel0_frac_arr.append(float(total_vel0_count)/len(robo_ang_odom_arr))
#print("For Frac%iA, run%i, #collision points: %i"%( i,run, len(odom0_agg_i) ) )
# 2. Obstacle Info:
# for each 2s period, if its within ?mtrs of obstacle, usme se amt of time its in close call.
obst_agg_i = aggregate_over_time(obst_dist_arr, obst_ts_arr, start_i, slot, end_i)
colln_agg_i = {}
ccall_agg_i = {}
for k in obst_agg_i.keys():
ct2 = 0 # d<2m count
coct = 0 # collision ct
cc_ct = 0 # close call ct
for x in obst_agg_i[k]:
if x <= 2.0:
ct2 += 1
if x <= 1.4:
cc_ct += 1