-
Notifications
You must be signed in to change notification settings - Fork 1
/
Features.jl
3659 lines (3060 loc) · 139 KB
/
Features.jl
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
##############################################################################
##
## Features
##
## Allows for the extraction of feature values for cars in scenes
##
##############################################################################
module Features
import Base: symbol, get
import Base.Meta: quot
using Trajdata
using DataArrays
using LaTeXStrings
using StreetMap
using Curves
# ----------------------------------
# exports
export AbstractFeature, InherentFeature, MarkovFeature, IteratedFeature
export RichVehicle
export FRAME_PER_SEC, SEC_PER_FRAME
export YAW, POSFX, POSFY, SPEED, VELFX, VELFY, DELTA_SPEED_LIMIT, TURNRATE, TURNRATE_GLOBAL, ACC, ACCFX, ACCFY, ISEGO
export CL, D_CL, D_ML, D_MR, SCENEVELFX, D_ONRAMP, D_OFFRAMP, TIMETOCROSSING_RIGHT, TIMETOCROSSING_LEFT
export D_MERGE, D_SPLIT, ID
export A_REQ_STAYINLANE, N_LANE_R, N_LANE_L, HAS_LANE_R, HAS_LANE_L, LANECURVATURE
export INDFRONT, HAS_FRONT, D_X_FRONT, D_Y_FRONT, V_X_FRONT, V_Y_FRONT, YAW_FRONT, TURNRATE_FRONT, A_REQ_FRONT, TTC_X_FRONT, TIMEGAP_X_FRONT
export INDREAR, HAS_REAR, D_X_REAR, D_Y_REAR, V_X_REAR, V_Y_REAR, YAW_REAR, TURNRATE_REAR, A_REQ_REAR, TTC_X_REAR, TIMEGAP_X_REAR
export INDLEFT, D_X_LEFT, D_Y_LEFT, V_X_LEFT, V_Y_LEFT, YAW_LEFT, TURNRATE_LEFT, A_REQ_LEFT, TTC_X_LEFT, TIMEGAP_X_LEFT
export INDRIGHT, D_X_RIGHT, D_Y_RIGHT, V_X_RIGHT, V_Y_RIGHT, YAW_RIGHT, TURNRATE_RIGHT, A_REQ_RIGHT, TTC_X_RIGHT, TIMEGAP_X_RIGHT
export GAINING_ON_FRONT
export FUTURETURNRATE_250MS, FUTUREACCELERATION_250MS, FUTUREDESIREDANGLE_250MS, FUTUREDESIREDSPEED_250MS, FUTUREACCELCONTROL_250MS
export FUTURETURNRATE_500MS, FUTUREACCELERATION_500MS, FUTUREDESIREDANGLE_500MS, FUTUREDESIREDSPEED_500MS, FUTUREACCELCONTROL_500MS
export FUTUREDELTAY2S, FUTUREDELTAY1S, FUTUREDELTAY_250MS
export TIMETOLANECROSSING, TIMESINCELANECROSSING, LANECHANGEDIR, LANECHANGE2S, LANECHANGE1S, LANECHANGE500MS
export TIME_CONSECUTIVE_BRAKE, TIME_CONSECUTIVE_ACCEL
export PASTACC250MS, PASTACC500MS, PASTACC750MS, PASTACC1S
export PASTTURNRATE250MS, PASTTURNRATE500MS, PASTTURNRATE750MS, PASTTURNRATE1S
export PASTVELFY250MS, PASTVELFY500MS, PASTVELFY750MS, PASTVELFY1S
export PASTD_CL250MS, PASTD_CL500MS, PASTD_CL750MS, PASTD_CL1S
export MAXACCFX250MS, MAXACCFX500MS, MAXACCFX750MS, MAXACCFX1S, MAXACCFX1500MS, MAXACCFX2S, MAXACCFX2500MS, MAXACCFX3S, MAXACCFX4S
export MAXACCFY250MS, MAXACCFY500MS, MAXACCFY750MS, MAXACCFY1S, MAXACCFY1500MS, MAXACCFY2S, MAXACCFY2500MS, MAXACCFY3S, MAXACCFY4S
export MAXTURNRATE250MS, MAXTURNRATE500MS, MAXTURNRATE750MS, MAXTURNRATE1S, MAXTURNRATE1500MS, MAXTURNRATE2S, MAXTURNRATE2500MS, MAXTURNRATE3S, MAXTURNRATE4S
export MEANACCFX250MS, MEANACCFX500MS, MEANACCFX750MS, MEANACCFX1S, MEANACCFX1500MS, MEANACCFX2S, MEANACCFX2500MS, MEANACCFX3S, MEANACCFX4S
export MEANACCFY250MS, MEANACCFY500MS, MEANACCFY750MS, MEANACCFY1S, MEANACCFY1500MS, MEANACCFY2S, MEANACCFY2500MS, MEANACCFY3S, MEANACCFY4S
export MEANTURNRATE250MS, MEANTURNRATE500MS, MEANTURNRATE750MS, MEANTURNRATE1S, MEANTURNRATE1500MS, MEANTURNRATE2S, MEANTURNRATE2500MS, MEANTURNRATE3S, MEANTURNRATE4S
export STDACCFX250MS, STDACCFX500MS, STDACCFX750MS, STDACCFX1S, STDACCFX1500MS, STDACCFX2S, STDACCFX2500MS, STDACCFX3S, STDACCFX4S
export STDACCFY250MS, STDACCFY500MS, STDACCFY750MS, STDACCFY1S, STDACCFY1500MS, STDACCFY2S, STDACCFY2500MS, STDACCFY3S, STDACCFY4S
export STDTURNRATE250MS, STDTURNRATE500MS, STDTURNRATE750MS, STDTURNRATE1S, STDTURNRATE1500MS, STDTURNRATE2S, STDTURNRATE2500MS, STDTURNRATE3S, STDTURNRATE4S
export SUBSET_EMERGENCY, SUBSET_FREE_FLOW, SUBSET_CAR_FOLLOWING, SUBSET_LANE_CROSSING, SUBSET_SUSTAINED_CROSSING
export SUBSET_AT_SIXTYFIVE, SUBSET_AUTO
export description, units, isint, isbool, lowerbound, upperbound, symbol, lsymbol, couldna, get, symbol2feature
export allfeatures
export NA_ALIAS
# ----------------------------------
# constants
const FRAME_PER_SEC = 20 # source frames per second
const SEC_PER_FRAME = 1.0/FRAME_PER_SEC
const NA_ALIAS = Inf # value assigned to floating point values when not available
const THRESHOLD_DY_CONSIDERED_IN_FRONT = 2.0 # number of meters of horizontal separation which allows two cars to be considered in front of / behind each other
const THRESHOLD_A_REQ = 10.0 # maximum required absolute value of required acceleration (m/s^2)
const THRESHOLD_TIME_TO_CROSSING = 10.0 # maximum time to crossing
const THRESHOLD_TIME_TO_COLLISION = 10.0 # maximum time to collision
const THRESHOLD_TIMEGAP = 10.0 # maximum timegap
const THRESHOLD_TIMETOLANECROSSING = 10.0 # [s]
const THRESHOLD_TIMESINCELANECROSSING = 10.0 # [s]
const THRESHOLD_TIMECONSECUTIVEBRAKE = 10.0 # [s]
const THRESHOLD_TIMECONSECUTIVEACCEL = 10.0 # [s]
const SPEED_LIMIT = 29.06 # [m/s]
const KP_DESIRED_ANGLE = 1.0 # unitary feedback is the general case
const KP_DESIRED_SPEED = 0.2 #
# ----------------------------------
# types
abstract AbstractFeature
abstract InherentFeature <: AbstractFeature # are always directly accessible from the scene data (posFx, vel) (not stored in meta)
abstract MarkovFeature <: AbstractFeature # only depend on the current state, but must be extracted (d_x_front, etc.)
abstract IteratedFeature <: AbstractFeature # require aggregated knowledge over time. They call an update function
abstract UnextractableFeature <: AbstractFeature # features that do not support get()
type BoundingBox
# a rectangle with length and width
l :: Float64
w :: Float64
end
type PointSE2
# a point in the 2D special euclidean group
# represents a position and rotation
x :: Float64
y :: Float64
yaw :: Float64 # [rad]
end
const CAR_WIDTH_STANDARD = 2.0 # [m]
const CAR_LENGTH_STANDARD = 4.6 # [m]
const LANE_WIDTH_STANDARD = 3.5 # [m]
abstract AbstractVehicle
type RichVehicle <: AbstractVehicle
pos :: PointSE2 # location in the frenet frame (s,d) [m, rad]
spd :: Real # speed [m/s]
box :: BoundingBox # the collision bounding box [m]
RichVehicle(x::Real, y::Real, θ::Real, v::Real) = new(PointSE2(x,y,θ), v, BoundingBox(CAR_WIDTH_STANDARD,CAR_LENGTH_STANDARD), Dict{Symbol,Float64}())
end
type TrafficScene
road :: Road # road definition
cars :: Vector{AbstractVehicle}
dist_fore :: Float64 # distance ahead of the ego car in which other agents are considered [m]
dist_rear :: Float64 # distance behind the ego car in which other agents are considered [m]
end
# ----------------------------------
# globals
sym2ftr = Dict{Symbol,AbstractFeature}()
meta = Dict{Int,Dict{Symbol,Float64}}() # carid -> meta map
meta_validfind = 0 # the validfind corresponding to the current meta datascene
# ----------------------------------
# abstract feature functions
symbol2feature(sym::Symbol) = sym2ftr[sym]
description(::AbstractFeature) = "None"
units( ::AbstractFeature) = "None"
isint( ::AbstractFeature) = error("Not implemented!") # true if the feature takes on only integer values
isbool( ::AbstractFeature) = error("Not implemented!") # true if the feature takes on only boolean values (0,1) (will also have isint = true)
upperbound( ::AbstractFeature) = error("Not implemented!") # max value of the feature
lowerbound( ::AbstractFeature) = error("Not implemented!") # min value of the feature
couldna( ::AbstractFeature) = true # whether the given variable could be NA (naalias is Inf)
symbol( ::AbstractFeature) = error("Not implemented!")
lsymbol( ::AbstractFeature) = error("Not implemented!")
get( ::AbstractFeature, ::TrafficScene, carind::Int) = error("Not implemented!")
get( ::AbstractFeature, ::PrimaryDataset, carind::Int, validfind::Int) = error("Not implemented!")
allfeatures() = collect(values(sym2ftr)) # array of all features
get(F::InherentFeature, pdset::PrimaryDataset, sn::StreetNetwork, carind::Int, validfind::Int) = get(F, pdset, carind, validfind)
_get(F::AbstractFeature, pdset::PrimaryDataset, sn::StreetNetwork, carind::Int, validfind::Int) = _get(F, pdset, carind, validfind)
function get(F::MarkovFeature, scene::TrafficScene, carind::Int)
car = scene.cars[carind]
sym = symbol(F)
if haskey(car.meta, F)
return car.meta[F]
end
value = _get(F, scene, carind)
car.meta[sym] = value
@assert(!isa(value, NAtype))
value
end
function get(F::MarkovFeature, pdset::PrimaryDataset, carind::Int, validfind::Int)
# a wrapper for get that automatically does the meta[] stuff for you
sym = symbol(F)
if checkmeta(carind, validfind, sym)
return meta[carind][sym]
end
value = _get(F, pdset, carind, validfind)
meta[carind][sym] = value
@assert(!isa(value, NAtype))
value
end
function get(F::UnextractableFeature, pdset::PrimaryDataset, carind::Int, validfind::Int)
# a wrapper for get that automatically does the meta[] stuff for you
sym = symbol(F)
if checkmeta(carind, validfind, sym)
return meta[carind][sym]
end
value = _get(F, pdset, carind, validfind)
meta[carind][sym] = value
@assert(!isa(value, NAtype))
value
end
function get(F::MarkovFeature, pdset::PrimaryDataset, sn::StreetNetwork, carind::Int, validfind::Int)
# a wrapper for get that automatically does the meta[] stuff for you
sym = symbol(F)
if checkmeta(carind, validfind, sym)
return meta[carind][sym]
end
value = _get(F, pdset, sn, carind, validfind)
meta[carind][sym] = value
@assert(!isa(value, NAtype))
value
end
function get(F::UnextractableFeature, pdset::PrimaryDataset, sn::StreetNetwork, carind::Int, validfind::Int)
# a wrapper for get that automatically does the meta[] stuff for you
sym = symbol(F)
if checkmeta(carind, validfind, sym)
return meta[carind][sym]
end
value = _get(F, pdset, sn, carind, validfind)
meta[carind][sym] = value
@assert(!isa(value, NAtype))
value
end
# ----------------------------------
function create_feature_basics{F<:AbstractFeature}(
name :: String,
feature_type :: Type{F},
unit :: String,
isint :: Bool,
isbool :: Bool,
ub :: Float64,
lb :: Float64,
could_be_na :: Bool,
sym :: Symbol,
lstr :: LaTeXString,
desc :: String
)
for feature in values(sym2ftr)
@assert(desc != description(feature), "desc: $name -> $feature")
@assert(sym != symbol(feature), "symb: $name -> $feature")
@assert(lstr != lsymbol(feature), "lstr: $name -> $feature")
end
@assert(ub >= lb)
feature_name = symbol("Feature_" * name)
const_name = symbol(uppercase(name))
sym_feature = quot(sym)
@eval begin
immutable $feature_name <: $feature_type end
const $const_name = ($feature_name)()
description( ::$feature_name) = $desc
units( ::$feature_name) = $unit
isint( ::$feature_name) = $isint
isbool( ::$feature_name) = $isbool
upperbound( ::$feature_name) = $ub
lowerbound( ::$feature_name) = $lb
couldna( ::$feature_name) = $could_be_na
symbol( ::$feature_name) = $sym_feature
lsymbol( ::$feature_name) = $lstr
sym2ftr[symbol( $const_name)] = $const_name
end
end
# ----------------------------------
# inherent features
create_feature_basics("Yaw", InherentFeature, "rad", false, false, Inf, -Inf, false, :yaw, L"\psi", "angle relative to the closest lane")
get( ::Feature_Yaw, scene::TrafficScene, carind::Int) = scene.cars[carind].pos.yaw
function get(::Feature_Yaw, pdset::PrimaryDataset, carind::Int, validfind::Int)
if carind == CARIND_EGO
frameind = validfind2frameind(pdset, validfind)
@assert(frameind != 0)
return gete(pdset, :posFyaw, frameind)
end
getc(pdset, "posFyaw", carind, validfind)
end
create_feature_basics("PosFx", InherentFeature, "m", false, false, Inf, -Inf, false, :posFx, L"p^F_x", "x position in the frenet frame")
get( ::Feature_PosFx, scene::TrafficScene, carind::Int) = scene.cars[carind].pos.x
function get(::Feature_PosFx, pdset::PrimaryDataset, carind::Int, validfind::Int)
if carind == CARIND_EGO
frameind = validfind2frameind(pdset, validfind)
return gete(pdset, :posFx, frameind)
end
getc(pdset, "posFx", carind, validfind)
end
create_feature_basics("PosFy", InherentFeature, "m", false, false, Inf, -Inf, false, :posFy, L"p^F_y", "y position in the frenet frame")
get( ::Feature_PosFy, scene::TrafficScene, carind::Int) = scene.cars[carind].pos.y
function get(::Feature_PosFy, pdset::PrimaryDataset, carind::Int, validfind::Int)
if carind == CARIND_EGO
frameind = validfind2frameind(pdset, validfind)
return gete(pdset, :posFy, frameind)
end
getc(pdset, "posFy", carind, validfind)
end
create_feature_basics("Speed", InherentFeature, "m/s", false, false, Inf, -Inf, false, :speed, L"\|v\|", "speed")
get( ::Feature_Speed, scene::TrafficScene, carind::Int) = scene.cars[carind].spd
function get(::Feature_Speed, pdset::PrimaryDataset, carind::Int, validfind::Int)
if carind == CARIND_EGO
frameind = validfind2frameind(pdset, validfind)
velx = gete(pdset, :velFx, frameind)
vely = gete(pdset, :velFy, frameind)
return hypot(velx, vely)
end
velx = getc(pdset, "velFx", carind, validfind)
vely = getc(pdset, "velFy", carind, validfind)
return hypot(velx, vely)
end
create_feature_basics("Delta_Speed_Limit", InherentFeature, "m/s", false, false, Inf, -Inf, false, :delta_speed_limit, L"Δv_{\text{limit}}", "difference between current speed and speed limit")
get( ::Feature_Delta_Speed_Limit, scene::TrafficScene, carind::Int) = SPEED_LIMIT - scene.cars[carind].spd
function get(::Feature_Delta_Speed_Limit, pdset::PrimaryDataset, carind::Int, validfind::Int)
speed = get(SPEED, pdset, carind, validfind)
SPEED_LIMIT - speed
end
create_feature_basics("VelFx", InherentFeature, "m/s", false, false, Inf, -Inf, false, :velFx, L"v^F_x", "velocity along the lane centerline")
get( ::Feature_VelFx, scene::TrafficScene, carind::Int) = scene.cars[carind].spd * cos(scene.cars[carind].pos.yaw)
function get(::Feature_VelFx, pdset::PrimaryDataset, carind::Int, validfind::Int)
if carind == CARIND_EGO
frameind = validfind2frameind(pdset, validfind)
return gete(pdset, :velFx, frameind)
end
getc(pdset, "velFx", carind, validfind)
end
create_feature_basics("VelFy", InherentFeature, "m/s", false, false, Inf, -Inf, false, :velFy, L"v^F_y", "velocity perpendicular to the lane centerline")
get( ::Feature_VelFy, scene::TrafficScene, carind::Int) = scene.cars[carind].spd * sin(scene.cars[carind].pos.yaw)
function get(::Feature_VelFy, pdset::PrimaryDataset, carind::Int, validfind::Int)
if carind == CARIND_EGO
frameind = validfind2frameind(pdset, validfind)
return gete(pdset, :velFy, frameind)
end
getc(pdset, "velFy", carind, validfind)
end
create_feature_basics("IsEgo", InherentFeature, "-", true, true, 1.0, 0.0, false, :isego, L"1_{ego}", "whether the car is the ego car")
get( ::Feature_IsEgo, scene::TrafficScene, carind::Int) = carind == CARIND_EGO
get( ::Feature_IsEgo, pdset::PrimaryDataset, carind::Int, validfind::Int) = carind == CARIND_EGO
# ----------------------------------
# markov features
create_feature_basics( "CL", MarkovFeature, "-", true, false, Inf, 1.0, false, :cl, L"cl", "index of the closest centerline. 1 is rightmost")
function _get(::Feature_CL, scene::TrafficScene, carind::Int)
car = scene.cars[carind]
# generate the lane centerlines
posFy = car.pos.y
n_lanes = scene.road.n_lanes
lane_centers = [0:(n_lanes-1)].*scene.road.lane_width # [0,lw,2lw,...]
indmin(abs(lane_centers .- posFy))
end
function _get(::Feature_CL, pdset::PrimaryDataset, carind::Int, validfind::Int)
if carind == CARIND_EGO
frameind = validfind2frameind(pdset, validfind)
return gete(pdset, :lane, frameind)
end
getc(pdset, "lane", carind, validfind)
end
get(::Feature_CL, ::PrimaryDataset, ::StreetNetwork, ::Int, ::Int) = error("CL not implemented with StreetNetworks")
create_feature_basics( "D_CL", MarkovFeature, "m", false, false, Inf, -Inf, false, :d_cl, L"d_{cl}", "distance to the closest centerline")
function _get(::Feature_D_CL, scene::TrafficScene, carind::Int)
car = scene.cars[carind]
lane = get(CL, scene, carind)
car.pos.y - (lane-1)*scene.road.lane_width
end
function get(::Feature_D_CL, pdset::PrimaryDataset, carind::Int, validfind::Int)
if carind == CARIND_EGO
frameind = validfind2frameind(pdset, validfind)
return gete(pdset, :d_cl, frameind)
end
getc(pdset, "d_cl", carind, validfind)
end
get(::Feature_D_CL, pdset::PrimaryDataset, sn::StreetNetwork, carind::Int, validfind::Int) = get(D_CL, pdset, carind, validfind)
create_feature_basics( "D_ML", MarkovFeature, "m", false, false, Inf, 0.0, true, :d_ml, L"d_{ml}", "lateral distance between center of car and the left lane marker")
function _get(::Feature_D_ML, scene::TrafficScene, carind::Int)
d_cl = get(D_CL, scene, carind)
d_cl > 0.5LANE_WIDTH_STANDARD ? NA_ALIAS : 0.5LANE_WIDTH_STANDARD - d_cl
end
function get(::Feature_D_ML, pdset::PrimaryDataset, carind::Int, validfind::Int)
if carind == CARIND_EGO
frameind = validfind2frameind(pdset, validfind)
d_ml = gete(pdset, :d_ml, frameind)
return isa(d_ml, NAtype) ? NA_ALIAS : d_ml
end
d_ml = getc(pdset, "d_ml", carind, validfind)
return isa(d_ml, NAtype) ? NA_ALIAS : d_ml
end
get(::Feature_D_ML, pdset::PrimaryDataset, sn::StreetNetwork, carind::Int, validfind::Int) = get(D_ML, pdset, carind, validfind)
create_feature_basics( "D_MR", MarkovFeature, "m", false, false, Inf, 0.0, true, :d_mr, L"d_{mr}", "lateral distance (strictly positive) between center of car and the right lane marker")
function _get(::Feature_D_MR, scene::TrafficScene, carind::Int)
d_cl = get(D_CL, scene, carind)
d_cl < 0.5LANE_WIDTH_STANDARD ? NA_ALIAS : 0.5LANE_WIDTH_STANDARD + d_cl
end
function get(::Feature_D_MR, pdset::PrimaryDataset, carind::Int, validfind::Int)
if carind == CARIND_EGO
frameind = validfind2frameind(pdset, validfind)
d_mr = gete(pdset, :d_mr, frameind)
return isa(d_mr, NAtype) ? NA_ALIAS : d_mr
end
d_mr = getc(pdset, "d_mr", carind, validfind)
return isa(d_mr, NAtype) ? NA_ALIAS : d_mr
end
get(::Feature_D_MR, pdset::PrimaryDataset, sn::StreetNetwork, carind::Int, validfind::Int) = get(D_MR, pdset, carind, validfind)
create_feature_basics( "TimeToCrossing_Right", MarkovFeature, "s", false, false, Inf, 0.0, true, :ttcr_mr, L"ttcr^{mr}_y", "time to cross the right marking of assigned lane")
function get(::Feature_TimeToCrossing_Right, scene::TrafficScene, carind::Int)
d_mr = get(D_MR, scene, carind)
velFy = get(VELFY, scene, carind)
d_mr > 0.0 && velFy < 0.0 ? min(d_mr / velFy,THRESHOLD_TIME_TO_CROSSING) : NA_ALIAS
end
function get(::Feature_TimeToCrossing_Right, pdset::PrimaryDataset, carind::Int, validfind::Int)
d_mr = get(D_MR, pdset, carind, validfind)
velFy = get(VELFY, pdset, carind, validfind)
d_mr > 0.0 && velFy < 0.0 ? min(-d_mr / velFy,THRESHOLD_TIME_TO_CROSSING) : NA_ALIAS
end
get(::Feature_TimeToCrossing_Right, pdset::PrimaryDataset, sn::StreetNetwork, carind::Int, validfind::Int) = get(TIMETOCROSSING_RIGHT, pdset, carind, validfind)
create_feature_basics( "TimeToCrossing_Left", MarkovFeature, "s", false, false, Inf, 0.0, true, :ttcr_ml, L"ttcr^{ml}_y", "time to cross the left marking of assigned lane")
function get(::Feature_TimeToCrossing_Left, scene::TrafficScene, carind::Int)
d_ml = get(D_MR, scene, carind)
velFy = get(VELFY, scene, carind)
d_ml > 0.0 && velFy > 0.0 ? min(d_ml / velFy,THRESHOLD_TIME_TO_CROSSING) : NA_ALIAS
end
function get(::Feature_TimeToCrossing_Left, pdset::PrimaryDataset, carind::Int, validfind::Int)
d_ml = get(D_ML, pdset, carind, validfind)
velFy = get(VELFY, pdset, carind, validfind)
d_ml > 0.0 && velFy > 0.0 ? min(d_ml / velFy,THRESHOLD_TIME_TO_CROSSING) : NA_ALIAS
end
function get(::Feature_TimeToCrossing_Left, pdset::PrimaryDataset, sn::StreetNetwork, carind::Int, validfind::Int)
d_ml = get(D_ML, pdset, sn, carind, validfind)
velFy = get(VELFY, pdset, sn, carind, validfind)
d_ml < 0.0 && velFy > 0.0 ? min(-d_ml / velFy,THRESHOLD_TIME_TO_CROSSING) : NA_ALIAS
end
create_feature_basics( "A_REQ_StayInLane", MarkovFeature, "m/s2", false, false, Inf, -Inf, true, :a_req_stayinlane, L"a^{req}_y", "acceleration required to stay in the current lane")
function get(::Feature_A_REQ_StayInLane, scene::TrafficScene, carind::Int)
velFy = get(VELFY, scene, carind)
d_mr = get(D_MR, scene, carind)
if d_mr > 0.0
return -min(0.5velFy*velFy / d_mr, THRESHOLD_A_REQ)
end
d_ml = get(D_ML, scene, carind)
d_ml > 0.0 ? -min(0.5velFy*velFy / d_ml, THRESHOLD_A_REQ) : NA_ALIAS
end
function get(::Feature_A_REQ_StayInLane, pdset::PrimaryDataset, carind::Int, validfind::Int)
velFy = get(VELFY, pdset, carind, validfind)
d_mr = get(D_MR, pdset, carind, validfind)
if d_mr > 0.0
return -min(0.5velFy*velFy / d_mr, THRESHOLD_A_REQ)
end
d_ml = get(D_ML, pdset, carind, validfind)
d_ml > 0.0 ? -min(0.5velFy*velFy / d_ml, THRESHOLD_A_REQ) : NA_ALIAS
end
function get(::Feature_A_REQ_StayInLane, pdset::PrimaryDataset, sn::StreetNetwork, carind::Int, validfind::Int)
velFy = get(VELFY, pdset, sn, carind, validfind)
if velFy > 0.0
d_mr = get(D_MR, pdset, sn, carind, validfind)
return d_mr > 0.0 ? min( 0.5velFy*velFy / d_mr, THRESHOLD_A_REQ) : NA_ALIAS
else
d_ml = get(D_ML, pdset, sn, carind, validfind)
return d_ml < 0.0 ? min(-0.5velFy*velFy / d_ml, THRESHOLD_A_REQ) : NA_ALIAS
end
end
create_feature_basics( "N_LANE_L", MarkovFeature, "-", true, false, 10.0, 0.0, false, :n_lane_left, L"nlane_l", "number of lanes on the left side of this vehicle")
function get(::Feature_N_LANE_L, scene::TrafficScene, carind::Int)
n_lanes = scene.road.n_lanes
lane = get(CL, scene, carind)
float64(n_lanes - lane)
end
function get(::Feature_N_LANE_L, pdset::PrimaryDataset, carind::Int, validfind::Int)
if carind == CARIND_EGO
frameind = validfind2frameind(pdset, validfind)
nll = float64(gete(pdset, :nll, frameind))
@assert(0.0 ≤ nll ≤ 6.0)
return nll
end
float64(getc(pdset, "nll", carind, validfind))
end
get(::Feature_N_LANE_L, pdset::PrimaryDataset, sn::StreetNetwork, carind::Int, validfind::Int) = get(N_LANE_L, pdset, carind, validfind)
create_feature_basics( "N_LANE_R", MarkovFeature, "-", true, false, 10.0, 0.0, false, :n_lane_right, L"nlane_r", "number of lanes on the right side of this vehicle")
get(::Feature_N_LANE_R, scene::TrafficScene, carind::Int) = get(CL, scene, carind) + 1.0
function get(::Feature_N_LANE_R, pdset::PrimaryDataset, carind::Int, validfind::Int)
if carind == CARIND_EGO
frameind = validfind2frameind(pdset, validfind)
return float64(gete(pdset, :nlr, frameind))
end
float64(getc(pdset, "nlr", carind, validfind))
end
get(::Feature_N_LANE_R, pdset::PrimaryDataset, sn::StreetNetwork, carind::Int, validfind::Int) = get(N_LANE_R, pdset, carind, validfind)
create_feature_basics( "HAS_LANE_R", MarkovFeature, "-", true, true, 1.0, 0.0, false, :has_lane_right, L"\exists_{\text{lane}}^\text{r}", "whether at least one lane exists to right")
function get(::Feature_HAS_LANE_R, scene::TrafficScene, carind::Int)
float64(get(N_LANE_R, scene, carind) > 0.0)
end
function get(::Feature_HAS_LANE_R, pdset::PrimaryDataset, carind::Int, validfind::Int)
float64(get(N_LANE_R, pdset, carind, validfind) > 0.0)
end
get(::Feature_HAS_LANE_R, pdset::PrimaryDataset, sn::StreetNetwork, carind::Int, validfind::Int) = get(HAS_LANE_R, pdset, carind, validfind)
create_feature_basics( "HAS_LANE_L", MarkovFeature, "-", true, true, 1.0, 0.0, false, :has_lane_left, L"\exists_{\text{lane}}^\text{l}", "whether at least one lane exists to the left")
function get(::Feature_HAS_LANE_L, scene::TrafficScene, carind::Int)
float64(get(N_LANE_L, scene, carind) > 0.0)
end
function get(::Feature_HAS_LANE_L, pdset::PrimaryDataset, carind::Int, validfind::Int)
float64(get(N_LANE_L, pdset, carind, validfind) > 0.0)
end
get(::Feature_HAS_LANE_L, pdset::PrimaryDataset, sn::StreetNetwork, carind::Int, validfind::Int) = get(HAS_LANE_L, pdset, carind, validfind)
create_feature_basics( "IndFront", MarkovFeature, "-", true, false, Inf, -1.0, true, :ind_front, L"i_{front}", "index of the closest car in front")
function _get(::Feature_IndFront, scene::TrafficScene, carind::Int)
car = scene.cars[carind]
mylane = get(CL, scene, carind)
myFy = car.pos.y
myFx = car.pos.x
myVy = car.spd*sin(car.pos.yaw)
myVx = car.spd*cos(car.pos.yaw)
min_dx = Inf
ind_front = -2
d_y_front = 0.0
v_x_front = 0.0
v_y_front = 0.0
yaw_front = 0.0
for (i,car2) in enumerate(scene.cars)
if i == carind
continue
end
dy = car2.pos.y - myFy
dlane = get(CL, scene, i)
if isapprox(dlane, mylane) || abs(dy) < THRESHOLD_DY_CONSIDERED_IN_FRONT
dx = car2.pos.x - myFx
if dx < min_dx && dx > 0.0
min_dx = dx
d_y_front = car2.pos.y - myFy
v_x_front = car2.spd*cos(car2.pos.yaw) - myVx
v_y_front = car2.spd*sin(car2.pos.yaw) - myVy
yaw_front = car2.pos.yaw
ind_front = i
end
end
end
if isinf(min_dx)
car.meta[:d_x_front] = NA_ALIAS
car.meta[:d_y_front] = NA_ALIAS
car.meta[:v_x_front] = NA_ALIAS
car.meta[:v_y_front] = NA_ALIAS
car.meta[:yaw_front] = NA_ALIAS
return NA_ALIAS
end
car.meta[:d_x_front] = min_dx
car.meta[:d_y_front] = d_y_front
car.meta[:v_x_front] = v_x_front
car.meta[:v_y_front] = v_y_front
car.meta[:yaw_front] = yaw_front
ind_front
end
function _get(::Feature_IndFront, pdset::PrimaryDataset, carind::Int, validfind::Int)
frameind = validfind2frameind(pdset, validfind)
curlane = gete(pdset, :lane, frameind)
egoFx = gete(pdset, :posFx, frameind)
egoFy = gete(pdset, :posFy, frameind)
ncarsinframe = ncars_in_frame(pdset, validfind)
searchcarinds = [0:ncarsinframe-1]
if carind == CARIND_EGO
if ncarsinframe == 0 # no other cars!
meta[CARIND_EGO][:d_x_front] = NA_ALIAS
meta[CARIND_EGO][:d_y_front] = NA_ALIAS
meta[CARIND_EGO][:v_x_front] = NA_ALIAS
meta[CARIND_EGO][:v_y_front] = NA_ALIAS
meta[CARIND_EGO][:yaw_front] = NA_ALIAS
meta[CARIND_EGO][:turnrate_front] = NA_ALIAS
return NA_ALIAS
end
d_x_front, frontcar_ind = findmin(map(ci->begin
dy = getc(pdset, "posFy", ci, validfind) - egoFy
dlane = getc(pdset, "lane", ci, validfind) - curlane
if isapprox(dlane, 0.0) || abs(dy) < THRESHOLD_DY_CONSIDERED_IN_FRONT
dx = getc(pdset, "posFx", ci, validfind) - egoFx
return dx > 0 ? dx : Inf
end
return Inf
end, searchcarinds))
if isinf(d_x_front)
meta[CARIND_EGO][:d_x_front] = NA_ALIAS
meta[CARIND_EGO][:d_y_front] = NA_ALIAS
meta[CARIND_EGO][:v_x_front] = NA_ALIAS
meta[CARIND_EGO][:v_y_front] = NA_ALIAS
meta[CARIND_EGO][:yaw_front] = NA_ALIAS
meta[CARIND_EGO][:turnrate_front] = NA_ALIAS
return NA_ALIAS
end
@assert(!isa(d_x_front, NAtype))
meta[CARIND_EGO][:d_x_front] = d_x_front
meta[CARIND_EGO][:d_y_front] = getc(pdset, "posFy", searchcarinds[frontcar_ind], validfind) - egoFy
meta[CARIND_EGO][:v_x_front] = getc(pdset, "velFx", searchcarinds[frontcar_ind], validfind) - gete(pdset, :velFx, frameind)
meta[CARIND_EGO][:v_y_front] = getc(pdset, "velFy", searchcarinds[frontcar_ind], validfind) - gete(pdset, :velFy, frameind)
meta[CARIND_EGO][:yaw_front] = getc(pdset, "posFyaw", searchcarinds[frontcar_ind], validfind)
meta[CARIND_EGO][:turnrate_front] = get(TURNRATE, pdset, searchcarinds[frontcar_ind], validfind)
return frontcar_ind
end
myFx = getc(pdset, "posFx", carind, validfind)
myFy = getc(pdset, "posFy", carind, validfind)
mylane = getc(pdset, "lane", carind, validfind)
frontcar_dist, frontcar_ind = findmin(map(carind2->begin
if carind2 == carind
return Inf
end
dy = getc(pdset, "posFy", carind2, validfind) - myFy
dlane = getc(pdset, "lane", carind2, validfind) - mylane
if isapprox(dlane, 0.0) || abs(dy) < THRESHOLD_DY_CONSIDERED_IN_FRONT
dx = getc(pdset, "posFx", carind2, validfind) - myFx
return dx > 0 ? dx : Inf
end
return Inf
end, searchcarinds))
dy_ego = myFy - egoFy
dlane = mylane - curlane
if (isapprox(dlane, 0.0) || abs(dy_ego) < THRESHOLD_DY_CONSIDERED_IN_FRONT) &&
egoFx - myFx > 0.0 &&
egoFx - myFx < frontcar_dist
# ego is better
meta[carind][:d_x_front] = egoFx - myFx
meta[carind][:d_y_front] = egoFy - myFy
meta[carind][:v_x_front] = gete(pdset, :velFx, frameind) - getc(pdset, "velFx", carind, validfind)
meta[carind][:v_y_front] = gete(pdset, :velFy, frameind) - getc(pdset, "velFy", carind, validfind)
meta[carind][:yaw_front] = gete(pdset, :posFyaw, frameind)
meta[carind][:turnrate_front] = get(TURNRATE, pdset, CARIND_EGO, validfind)
return frontcar_ind
end
if isinf(frontcar_dist)
meta[carind][:d_x_front] = NA_ALIAS
meta[carind][:d_y_front] = NA_ALIAS
meta[carind][:v_x_front] = NA_ALIAS
meta[carind][:v_y_front] = NA_ALIAS
meta[carind][:yaw_front] = NA_ALIAS
meta[carind][:turnrate_front] = NA_ALIAS
return NA_ALIAS
end
# other car is better
meta[carind][:d_x_front] = frontcar_dist
meta[carind][:d_y_front] = getc(pdset, "posFy", searchcarinds[frontcar_ind], validfind) - myFy
meta[carind][:v_x_front] = getc(pdset, "velFx", searchcarinds[frontcar_ind], validfind) - getc(pdset, "velFx", carind, validfind)
meta[carind][:v_y_front] = getc(pdset, "velFy", searchcarinds[frontcar_ind], validfind) - getc(pdset, "velFy", carind, validfind)
meta[carind][:yaw_front] = getc(pdset, "posFyaw", searchcarinds[frontcar_ind], validfind)
meta[carind][:turnrate_front] = get(TURNRATE, pdset, searchcarinds[frontcar_ind], validfind)
frontcar_ind
end
function _get(::Feature_IndFront, pdset::PrimaryDataset, sn::StreetNetwork, carind::Int, validfind::Int)
best_carind = -2
best_dist = 100.0 # start at max
best_ΔpFy = 0.0
frameind = validfind2frameind(pdset, validfind)
ncarsinframe = ncars_in_frame(pdset, validfind)
cars_to_check = Set([-1 : (ncarsinframe-1)])
lanetags = Array(LaneTag, ncarsinframe+1)
for cind in cars_to_check
lanetags[cind+2] = get(pdset, :lanetag, "lanetag", cind, frameind, validfind)::LaneTag
end
posFx = get(pdset, :posFx, "posFx", carind, frameind, validfind)::Float64
posFy = get(pdset, :posFy, "posFy", carind, frameind, validfind)::Float64
active_lanetag = lanetags[carind+2]
active_lane = get_lane(sn, active_lanetag)
search_dist = 0.0
delete!(cars_to_check, carind)
done = false
while !done
to_remove = Set{Int}()
for target_carind in cars_to_check
if active_lanetag == lanetags[target_carind+2]
target_posFx = get(pdset, :posFx, "posFx", target_carind, frameind, validfind)
# only accept cars that are in front of us
# and better than what we already have
target_dist = target_posFx - posFx + search_dist
if 0.0 < target_dist < best_dist
target_posFy = get(pdset, :posFy, "posFy", target_carind, frameind, validfind)
ΔpFy = target_posFy - posFy
if abs(ΔpFy) < THRESHOLD_DY_CONSIDERED_IN_FRONT
best_carind, best_dist = target_carind, target_dist
best_ΔpFy = ΔpFy
end
end
push!(to_remove, target_carind)
end
end
if best_carind != -2
break
end
for target_carind in to_remove
delete!(cars_to_check, target_carind)
end
if isempty(cars_to_check)
break
end
# move to next lane
if has_next_lane(sn, active_lane)
search_dist += active_lane.curve.s[end]
active_lane = next_lane(sn, active_lane)
active_lanetag = LaneTag(sn, active_lane)
done = search_dist > best_dist
else
done = true
end
end
if best_carind != -2
meta[carind][:d_x_front] = best_dist
meta[carind][:d_y_front] = best_ΔpFy
meta[carind][:v_x_front] = get(pdset, :velFx, "velFx", best_carind, frameind, validfind) - get(pdset, :velFx, "velFx", carind, frameind, validfind)
meta[carind][:v_y_front] = get(pdset, :velFy, "velFy", best_carind, frameind, validfind) - get(pdset, :velFy, "velFy", carind, frameind, validfind)
meta[carind][:yaw_front] = get(pdset, :posFyaw, "posFyaw", best_carind, frameind, validfind)
meta[carind][:turnrate_front] = get(TURNRATE, pdset, sn, best_carind, validfind)
return float64(best_carind)
else
meta[carind][:d_x_front] = NA_ALIAS
meta[carind][:d_y_front] = NA_ALIAS
meta[carind][:v_x_front] = NA_ALIAS
meta[carind][:v_y_front] = NA_ALIAS
meta[carind][:yaw_front] = NA_ALIAS
meta[carind][:turnrate_front] = NA_ALIAS
return NA_ALIAS
end
end
create_feature_basics( "HAS_FRONT", MarkovFeature, "-", true, true, 1.0, 0.0, false, :has_front, L"\exists_{fo}", "whether there is a car in front")
function get( ::Feature_HAS_FRONT, scene::TrafficScene, carind::Int)
float64(get(INDFRONT, scene, carind) != NA_ALIAS)
end
function get( ::Feature_HAS_FRONT, pdset::PrimaryDataset, carind::Int, validfind::Int)
float64(get(INDFRONT, pdset, carind, validfind) != NA_ALIAS)
end
function get( ::Feature_HAS_FRONT, pdset::PrimaryDataset, sn::StreetNetwork, carind::Int, validfind::Int)
float64(get(INDFRONT, pdset, sn, carind, validfind) != NA_ALIAS)
end
create_feature_basics( "D_X_FRONT", MarkovFeature, "m", false, false, Inf, 0.0, true, :d_x_front, L"d_{x,fo}", "longitudinal distance to the closest vehicle in the same lane in front")
function get( ::Feature_D_X_FRONT, scene::TrafficScene, carind::Int)
get(INDFRONT, scene, carind) # call to get it to do the calculation
scene.cars[carind].meta[:d_x_front] # pull the processed result
end
function get( ::Feature_D_X_FRONT, pdset::PrimaryDataset, carind::Int, validfind::Int)
get(INDFRONT, pdset, carind, validfind) # call to get it to do the calculation
meta[carind][:d_x_front] # pull the processed result
end
function get( ::Feature_D_X_FRONT, pdset::PrimaryDataset, sn::StreetNetwork, carind::Int, validfind::Int)
get(INDFRONT, pdset, sn, carind, validfind) # call to get it to do the calculation
meta[carind][:d_x_front] # pull the processed result
end
create_feature_basics( "D_Y_FRONT", MarkovFeature, "m", false, false, Inf, -Inf, true, :d_y_front, L"d_{y,fo}", "lateral distance to the closest vehicle in the same lane in front")
function get( ::Feature_D_Y_FRONT, scene::TrafficScene, carind::Int)
get(INDFRONT, scene, carind) # call to get it to do the calculation
scene.cars[carind].meta[:d_y_front] # pull the processed result
end
function get( ::Feature_D_Y_FRONT, pdset::PrimaryDataset, carind::Int, validfind::Int)
get(INDFRONT, pdset, carind, validfind) # call to get it to do the calculation
meta[carind][:d_y_front] # pull the processed result
end
function get( ::Feature_D_Y_FRONT, pdset::PrimaryDataset, sn::StreetNetwork, carind::Int, validfind::Int)
get(INDFRONT, pdset, sn, carind, validfind) # call to get it to do the calculation
meta[carind][:d_y_front] # pull the processed result
end
create_feature_basics( "V_X_FRONT", MarkovFeature, "m/s", false, false, Inf, -Inf, true, :v_x_front, L"v^{rel}_{x,fo}", "relative x velocity of the vehicle in front of you")
function get( ::Feature_V_X_FRONT, scene::TrafficScene, carind::Int)
get(INDFRONT, scene, carind) # call to get it to do the calculation
scene.cars[carind].meta[:v_x_front] # pull the processed result
end
function get( ::Feature_V_X_FRONT, pdset::PrimaryDataset, carind::Int, validfind::Int)
get(INDFRONT, pdset, carind, validfind) # call to get it to do the calculation
meta[carind][:v_x_front] # pull the processed result
end
function get( ::Feature_V_X_FRONT, pdset::PrimaryDataset, sn::StreetNetwork, carind::Int, validfind::Int)
get(INDFRONT, pdset, sn, carind, validfind) # call to get it to do the calculation
meta[carind][:v_x_front] # pull the processed result
end
create_feature_basics( "V_Y_FRONT", MarkovFeature, "m/s", false, false, Inf, -Inf, true, :v_y_front, L"v^{rel}_{y,fo}", "relative y velocity of the vehicle in front of you")
function get( ::Feature_V_Y_FRONT, scene::TrafficScene, carind::Int)
get(INDFRONT, scene, carind) # call to get it to do the calculation
scene.cars[carind].meta[:v_y_front] # pull the processed result
end
function get( ::Feature_V_Y_FRONT, pdset::PrimaryDataset, carind::Int, validfind::Int)
get(INDFRONT, pdset, carind, validfind) # call to get it to do the calculation
meta[carind][:v_y_front] # pull the processed result
end
function get( ::Feature_V_Y_FRONT, pdset::PrimaryDataset, sn::StreetNetwork, carind::Int, validfind::Int)
get(INDFRONT, pdset, sn, carind, validfind) # call to get it to do the calculation
meta[carind][:v_y_front] # pull the processed result
end
create_feature_basics( "YAW_FRONT", MarkovFeature, "rad", false, false, float64(pi), float64(-pi), true, :yaw_front, L"\psi_{fo}", "yaw of the vehicle in front of you")
function get( ::Feature_YAW_FRONT, scene::TrafficScene, carind::Int)
get(INDFRONT, scene, carind) # call to get it to do the calculation
scene.cars[carind].meta[:yaw_front] # pull the processed result
end
function get( ::Feature_YAW_FRONT, pdset::PrimaryDataset, carind::Int, validfind::Int)
get(INDFRONT, pdset, carind, validfind) # call to get it to do the calculation
meta[carind][:yaw_front] # pull the processed result
end
function get( ::Feature_YAW_FRONT, pdset::PrimaryDataset, sn::StreetNetwork, carind::Int, validfind::Int)
get(INDFRONT, pdset, sn, carind, validfind) # call to get it to do the calculation
meta[carind][:yaw_front] # pull the processed result
end
create_feature_basics( "TURNRATE_FRONT", MarkovFeature, "rad/s", false, false, Inf, -Inf, true, :turnrate_front, L"\dot{\psi}_{fo}", "turnrate of the vehicle in front of you")
function get( ::Feature_TURNRATE_FRONT, pdset::PrimaryDataset, carind::Int, validfind::Int)
get(INDFRONT, pdset, carind, validfind) # call to get it to do the calculation
meta[carind][:turnrate_front] # pull the processed result
end
function get( ::Feature_TURNRATE_FRONT, pdset::PrimaryDataset, sn::StreetNetwork, carind::Int, validfind::Int)
get(INDFRONT, pdset, sn, carind, validfind) # call to get it to do the calculation
meta[carind][:turnrate_front] # pull the processed result
end
function get( ::Feature_TURNRATE_FRONT, pdset::PrimaryDataset, sn::StreetNetwork, carind::Int, validfind::Int)
get(INDFRONT, pdset, sn, carind, validfind) # call to get it to do the calculation
meta[carind][:turnrate_front] # pull the processed result
end
create_feature_basics( "A_REQ_FRONT", MarkovFeature, "m/s2", false, false, 0.0, -Inf, true, :a_req_front, L"a^{req}_{x,fo}", "const acceleration required to prevent collision with car in front assuming constant velocity")
function get( ::Feature_A_REQ_FRONT, scene::TrafficScene, carind::Int)
# the constant acceleration required so as not to collide with the car in front
# assumes both cars maintain constant vel
# note: this assumes cars have zero-length, which is NOT the case
# note: finds the acceleration such that we have zero velocity when reaching other car
ind_front = get(INDFRONT, scene, carind)
if ind_front == NA_ALIAS
return NA_ALIAS
end
dx = get(D_X_FRONT, scene, carind) # distance between cars
dv = get(V_X_FRONT, scene, carind) # v_front - v_back
if dv >= 0.0 # they are pulling away; we are good
return NA_ALIAS
end
-min(dv*dv / (2dx),THRESHOLD_A_REQ)
end
function get( ::Feature_A_REQ_FRONT, pdset::PrimaryDataset, carind::Int, validfind::Int)
ind_front = get(INDFRONT, pdset, carind, validfind)
if ind_front == NA_ALIAS
return NA_ALIAS
end
dx = get(D_X_FRONT, pdset, carind, validfind) # distance between cars
dv = get(V_X_FRONT, pdset, carind, validfind) # v_front - v_back
if dv >= 0.0 # they are pulling away; we are good
return NA_ALIAS
end
-min(dv*dv / (2dx), THRESHOLD_A_REQ)
end
function get( ::Feature_A_REQ_FRONT, pdset::PrimaryDataset, sn::StreetNetwork, carind::Int, validfind::Int)
ind_front = get(INDFRONT, pdset, sn, carind, validfind)
if ind_front == NA_ALIAS
return NA_ALIAS
end
dx = get(D_X_FRONT, pdset, sn, carind, validfind) # distance between cars
dv = get(V_X_FRONT, pdset, sn, carind, validfind) # v_front - v_back
if dv >= 0.0 # they are pulling away; we are good
return NA_ALIAS
end
-min(dv*dv / (2dx), THRESHOLD_A_REQ)
end
create_feature_basics( "Gaining_On_Front", MarkovFeature, "-", true, true, 1.0, 0.0, true, :gaining_on_front, L"1\{v_\text{ego} > v_\text{front}\}", "whether the car will collide with front if no action is taken and both const. vel")
function get( ::Feature_Gaining_On_Front, pdset::PrimaryDataset, sn::StreetNetwork, carind::Int, validfind::Int)
get(INDFRONT, pdset, sn, carind, validfind) # call to get it to do the calculation
ΔV = meta[carind][:v_x_front] # pull the processed result
float64(ΔV < 0.0)
end
create_feature_basics( "TTC_X_FRONT", MarkovFeature, "s", false, false, Inf, 0.0, true, :ttc_x_front, L"ttc_{x,fo}", "time to collision with car in front assuming constant velocities")
function get( ::Feature_TTC_X_FRONT, scene::TrafficScene, carind::Int)
# assumes both cars maintain constant vel
# note: this assumes cars have zero-length, which is NOT the case
ind_front = get(INDFRONT, scene, carind)
if ind_front == NA_ALIAS
return NA_ALIAS
end
dx = get(D_X_FRONT, scene, carind) # distance between cars
dv = get(V_X_FRONT, scene, carind) # v_front - v_back
if dv >= 0.0 # they are pulling away; we are good
return NA_ALIAS
end
min(-dx / dv, THRESHOLD_TIME_TO_COLLISION)
end
function get( ::Feature_TTC_X_FRONT, pdset::PrimaryDataset, carind::Int, validfind::Int)
ind_front = get(INDFRONT, pdset, carind, validfind)
if ind_front == NA_ALIAS
return NA_ALIAS
end
dx = get(D_X_FRONT, pdset, carind, validfind) # distance between cars
dv = get(V_X_FRONT, pdset, carind, validfind) # v_front - v_back
if dv >= 0.0 # they are pulling away; we are good
return NA_ALIAS
end
min(-dx / dv, THRESHOLD_TIME_TO_COLLISION)
end
function get( ::Feature_TTC_X_FRONT, pdset::PrimaryDataset, sn::StreetNetwork, carind::Int, validfind::Int)
ind_front = get(INDFRONT, pdset, sn, carind, validfind)
if ind_front == NA_ALIAS
return NA_ALIAS
end
dx = get(D_X_FRONT, pdset, sn, carind, validfind) # distance between cars
dv = get(V_X_FRONT, pdset, sn, carind, validfind) # v_front - v_back
if dv >= 0.0 # they are pulling away; we are good
return NA_ALIAS
end
min(-dx / dv, THRESHOLD_TIME_TO_COLLISION)
end
create_feature_basics( "TimeGap_X_FRONT", MarkovFeature, "s", false, false, Inf, 0.0, false, :timegap_x_front, L"\tau_{x,fo}", "timegap between cars")
function get( ::Feature_TimeGap_X_FRONT, scene::TrafficScene, carind::Int)
# assumes we maintain constant velocity
# computes time it will take for us to pass same location that the other car is at now
ind_front = get(INDFRONT, scene, carind)
if ind_front == NA_ALIAS
return NA_ALIAS
end
dx = get(D_X_FRONT, scene, carind) # distance between cars
v = get(VELFX, scene, carind) # our current velocity
if v <= 0.0
return NA_ALIAS
end
dx / v
end
function get( ::Feature_TimeGap_X_FRONT, pdset::PrimaryDataset, carind::Int, validfind::Int)
ind_front = get(INDFRONT, pdset, carind, validfind)
if ind_front == NA_ALIAS
return NA_ALIAS
end
dx = get(D_X_FRONT, pdset, carind, validfind) # distance between cars
v = get(VELFX, pdset, carind, validfind) # our current velocity
if v <= 0.0
return NA_ALIAS
end