-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathDaidalus.cpp
More file actions
4806 lines (4310 loc) · 156 KB
/
Daidalus.cpp
File metadata and controls
4806 lines (4310 loc) · 156 KB
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
/*
* Copyright (c) 2015-2021 United States Government as represented by
* the National Aeronautics and Space Administration. No copyright
* is claimed in the United States under Title 17, U.S.Code. All Other
* Rights Reserved.
*/
/**
* Objects of class "Daidalus" compute the conflict bands using
* kinematic single-maneuver projections of the ownship and linear preditions
* of (multiple) traffic aircraft positions. The bands consist of ranges of
* guidance maneuvers: direction angles, horizontal speeds, vertical
* speeds, and altitude.<p>
*
* An assumption of the bands information is that the traffic aircraft
* do not maneuver. If the ownship immediately executes a NONE
* guidance maneuver, then the new path is conflict free (within a
* lookahead time of the parameter). If the ownship immediately executes a
* NEAR/MID/FAR guidance maneuver and no traffic aircraft maneuvers, then
* there will corresponding alert within the corresponding alerting level thresholds.<p>
*
* If recovery bands are set and the ownship is in
* a violation path, loss of separation recovery bands and recovery times are
* computed for each type of maneuver. If the ownship immediately executes a
* RECOVERY guidance maneuver, then the new path is conflict-free after the
* recovery time. Furthermore, the recovery time is the minimum time for which
* there exists a kinematic conflict-free maneuver in the future. <p>
*
* Note that in the case of geodetic coordinates this version of bands
* performs an internal projection of the coordinates and velocities
* into the Euclidean frame (see Util/Projection). Accuracy may be
* reduced if the traffic plans involve any segments longer than
* Util.Projection.projectionConflictRange(lat,acc), and an error will
* be logged if the distance between traffic and ownship exceeds
* Util.Projection.projectionMaxRange() at any point in the lookahead
* range.<p>
*
* Disclaimers: The formal proofs of the core algorithms use real numbers,
* however these implementations use floating point
* numbers, so numerical differences could result. In addition, the
* geodetic computations include certain inaccuracies, especially near
* the poles.<p>
*
* The basic usage is
* <pre>
* Daidalus daa;
* daa.loadFromFile(<configurationfile>);
*
* ...
* daa.setOwnshipState(position of ownship, velocity of ownship);
* daa.addTrafficState(position of (one) traffic aircraft, velocity of traffic);
* daa.addTrafficState(position of (another) traffic aircraft, velocity of traffic);
* ...add other traffic aircraft...
*
* for (int i = 0; i < daa.horizontalDirectionBandsLength(); i++ ) {
* interval = daa.horizontalDirectionIntervalAt(i);
* lower_ang = intrval.low;
* upper_ang = intrval.up;
* regionType = daa.horizontalDirectionRegionAt(i);
* ..do something with this information..
* }
*
* ...similar for horizontal speed and vertical speed...
* </pre>
*
*/
#include "Daidalus.h"
#include "CriteriaCore.h"
#include "UrgencyStrategy.h"
#include "IndexLevelT.h"
#include "Interval.h"
#include "TCASTable.h"
#include "Alerter.h"
#include "Constants.h"
#include "NoneUrgencyStrategy.h"
#include "DaidalusAltBands.h"
#include "DaidalusDirBands.h"
#include "DaidalusHsBands.h"
#include "DaidalusVsBands.h"
#include <vector>
#include <cmath>
#include "TrafficState.h"
namespace larcfm {
/**
* Construct an empty Daidalus object.
* NOTE: This object doesn't have any alert configured. Alerters can be
* configured either programmatically, set_DO_365B() or
* via a configuration file with the method loadFromFile(configurationfile)
**/
Daidalus::Daidalus() : error("Daidalus") {}
/**
* Construct a Daidalus object with initial alerter.
*/
Daidalus::Daidalus(const Alerter& alerter) : error("Daidalus"), core_(alerter) {}
/**
* Construct a Daidalus object with the default parameters and one alerter with the
* given detector and T (in seconds) as the alerting time, early alerting time, and lookahead time.
*/
Daidalus::Daidalus(const Detection3D& det, double T) : error("Daidalus"), core_(det,T) {}
/* Setting for WC Definitions RTCA DO-365 */
/*
* Set Daidalus object such that
* - Configure two alerters (Phase I and Phase II) as defined as in RTCA DO-365A
* - Maneuver guidance logic assumes kinematic maneuvers
* - Turn rate is set to 3 deg/s, when type is true, and to 1.5 deg/s
* when type is false.
* - Configure Sensor Uncertainty Migitation (SUM) when sum is true
* - Bands don't saturate until NMAC
*/
void Daidalus::set_DO_365A(bool type, bool sum) {
core_.parameters.set_DO_365A(type,sum);
reset();
clearHysteresis();
}
/*
* Set Daidalus object such that
* - Configure two alerters (Phase I, Phase II, and Non-Cooperative) as defined as in RTCA DO-365B
* - Maneuver guidance logic assumes kinematic maneuvers
* - Turn rate is set to 3 deg/s, when type is true, and to 1.5 deg/s
* when type is false.
* - Configure Sensor Uncertainty Migitation (SUM) when sum is true
* - Bands don't saturate until NMAC
*/
void Daidalus::set_DO_365B(bool type, bool sum) {
core_.parameters.set_DO_365B(type, sum);
reset();
clearHysteresis();
}
/*
* Set Daidalus object such that
* - Alerting thresholds are buffered
* - Maneuver guidance logic assumes kinematic maneuvers
* - Turn rate is set to 3 deg/s, when type is true, and to 1.5 deg/s
* when type is false.
* - Bands don't saturate until NMAC
*/
void Daidalus::set_Buffered_WC_DO_365(bool type) {
core_.parameters.set_Buffered_WC_DO_365(type);
reset();
clearHysteresis();
}
/* Set Daidalus object such that alerting logic and maneuver guidance corresponds to
* ACCoRD's CD3D, i.e.,
* - Separation is given by a cylinder of of diameter 5nm and height 1000ft
* - Lookahead time and alerting time is 180s
* - Only 1 alert level
* - Instantaneous maneuvers */
void Daidalus::set_CD3D() {
core_.parameters.set_CD3D();
reset();
clearHysteresis();
}
/* Set Daidalus object such that alerting logic and maneuver guidance corresponds to
* ideal TCASII */
void Daidalus::set_TCASII() {
core_.parameters.set_TCASII();
reset();
clearHysteresis();
}
/**
* Return release version string
*/
std::string Daidalus::release() {
return "DAIDALUS++-v"+DaidalusParameters::VERSION+
"-FormalATM-"+Constants::version;
}
/* Ownship and Traffic Setting */
/**
* Returns state of ownship.
*/
const TrafficState& Daidalus::getOwnshipState() const {
return core_.ownship;
}
/**
* Returns state of aircraft at index idx
*/
const TrafficState& Daidalus::getAircraftStateAt(int idx) const {
if (0 <= idx && idx <= lastTrafficIndex()) {
if (idx == 0) {
return core_.ownship;
} else {
return core_.traffic[idx-1];
}
} else {
error.addError("getAircraftStateAt: aircraft index "+Fmi(idx)+" is out of bounds");
return TrafficState::INVALID();
}
}
/**
* Set ownship state and current time. Clear all traffic.
* @param id Ownship's identifier
* @param pos Ownship's position
* @param vel Ownship's ground velocity
* @param airvel Ownship's air velocity
* @param time Time stamp of ownship's state
*/
void Daidalus::setOwnshipState(const std::string& id, const Position& pos, const Velocity& vel, const Velocity& airvel, double time) {
if (!hasOwnship() || !equals(core_.ownship.getId(),id) ||
time < getCurrentTime() ||
time-getCurrentTime() > getHysteresisTime()) {
// Full reset (including hysteresis) if adding a different ownship or time is
// in the past. Note that wind is not clear.
clearHysteresis();
core_.set_ownship_state(id,pos,vel,airvel,time);
} else {
// Otherwise, reset cache values but keeps hysteresis.
core_.set_ownship_state(id,pos,vel,airvel,time);
stale_bands();
}
}
/**
* Set ownship state and current time. Clear all traffic and assume previous wind.
* @param id Ownship's identifier
* @param pos Ownship's position
* @param vel Ownship's ground velocity
* @param time Time stamp of ownship's state
*/
void Daidalus::setOwnshipState(const std::string& id, const Position& pos, const Velocity& vel, double time) {
setOwnshipState(id,pos,vel,vel.Sub(core_.wind_vector),time);
}
/**
* Set ownship state at time 0.0. Clear all traffic.
* @param id Ownship's identifier
* @param pos Ownship's position
* @param vel Ownship's ground velocity
*/
void Daidalus::setOwnshipState(const std::string& id, const Position& pos, const Velocity& vel) {
setOwnshipState(id,pos,vel,0.0);
}
/**
* Add traffic state at given time. Assume previous wind.
* If time is different from current time, traffic state is projected, past or future,
* into current time. If it's the first aircraft, this aircraft is
* set as the ownship. If a traffic state with the same id already exists,
* the traffic state is overwritten. If id is ownship's, nothing is done and
* the value -1 is returned.
* If traffic aircraft is beyond distance_filter or altitude_filter, traffic aircraft won't be added and
* -1 is returned.
* @param id Aircraft's identifier
* @param pos Aircraft's position
* @param vel Aircraft's ground velocity
* @param time Time stamp of aircraft's state
* @return Aircraft's index
*/
int Daidalus::addTrafficState(const std::string& id, const Position& pos, const Velocity& vel, double time) {
if (lastTrafficIndex() < 0) {
setOwnshipState(id,pos,vel,time);
return 0;
}
if ((core_.parameters.getDistanceFilter() <= 0 || core_.ownship.getPosition().distanceH(pos) <= core_.parameters.getDistanceFilter()) &&
(core_.parameters.getAltitudeFilter() <= 0 || core_.ownship.getPosition().distanceV(pos) <= core_.parameters.getAltitudeFilter())) {
int idx = core_.set_traffic_state(id,pos,vel,time);
if (idx >= 0) {
++idx;
stale_bands();
}
return idx;
}
return -1;
}
/**
* Add traffic state at current time. If it's the first aircraft, this aircraft is
* set as the ownship.
* If traffic aircraft is beyond distance_filter or altitude_filter, traffic aircraft won't be added and
* -1 is returned.
* @param id Aircraft's identifier
* @param pos Aircraft's position
* @param vel Aircraft's ground velocity
* @return Aircraft's index
*/
int Daidalus::addTrafficState(const std::string& id, const Position& pos, const Velocity& vel) {
return addTrafficState(id,pos,vel,core_.current_time);
}
/**
* Get index of aircraft with given name. Return -1 if no such index exists
*/
int Daidalus::aircraftIndex(const std::string& name) const {
int idx = -1;
if (lastTrafficIndex() >= 0) {
if (equals(core_.ownship.getId(),name)) {
return 0;
}
idx = core_.find_traffic_state(name);
if (idx >= 0) {
++idx;
}
}
return idx;
}
/**
* Exchange ownship aircraft with aircraft named id.
* EXPERT USE ONLY !!!
*/
void Daidalus::resetOwnship(const std::string& id) {
int ac_idx = aircraftIndex(id);
if (1 <= ac_idx && ac_idx <= lastTrafficIndex()) {
clearHysteresis();
core_.reset_ownship(ac_idx-1);
} else {
error.addError("resetOwnship: aircraft index "+Fmi(ac_idx)+" is out of bounds");
}
}
/**
* Remove traffic from the list of aircraft. Returns false if no aircraft was removed.
* Ownship cannot be removed.
* If traffic is at index i, the indices of aircraft at k > i, are shifted to k-1.
* EXPERT USE ONLY !!!
*/
bool Daidalus::removeTrafficAircraft(const std::string& name) {
int ac_idx = aircraftIndex(name);
if (core_.remove_traffic(ac_idx-1)) {
stale_bands();
return true;
}
return false;
}
/**
* Project ownship and traffic aircraft offset seconds in the future (if positive) or in the past (if negative)
* XPERT USE ONLY !!!
*/
void Daidalus::linearProjection(double offset) {
if (core_.linear_projection(offset)) {
stale_bands();
}
}
/**
* @return true if ownship has been set
*/
bool Daidalus::hasOwnship() const {
return core_.has_ownship();
}
/**
* @return true if at least one traffic has been set
*/
bool Daidalus::hasTraffic() const {
return core_.has_traffic();
}
/**
* @return number of aircraft, including ownship.
*/
int Daidalus::numberOfAircraft() const {
if (!hasOwnship()) {
return 0;
} else {
return core_.traffic.size()+1;
}
}
/**
* @return last traffic index. Every traffic aircraft has an index between 1 and lastTrafficIndex.
* The index 0 is reserved for the ownship.
*/
int Daidalus::lastTrafficIndex() const {
return numberOfAircraft()-1;
}
bool Daidalus::isLatLon() const {
return hasOwnship() && core_.ownship.isLatLon();
}
/* Current Time */
/**
* Return currrent time in seconds. Current time is the time of the ownship.
*/
double Daidalus::getCurrentTime() const {
return core_.current_time;
}
/**
* Return currrent time in specified units. Current time is the time of the ownship.
*/
double Daidalus::getCurrentTime(const std::string& u) const {
return Units::to(u,getCurrentTime());
}
/* Wind Setting */
/**
* Get ownship's heading in internal units [0-2PI]
*/
double Daidalus::getOwnshipHeading() const {
return core_.ownship.horizontalDirection();
}
/**
* Get ownship's heading in given units [0-2PI]
*/
double Daidalus::getOwnshipHeading(const std::string& units) const {
return core_.ownship.horizontalDirection(units);
}
/**
* Get ownship's airspeed in internal units [m/s]
*/
double Daidalus::getOwnshipAirspeed() const {
return core_.ownship.horizontalSpeed();
}
/**
* Get ownship's airspeed in given units
*/
double Daidalus::getOwnshipAirspeed(const std::string& units) const {
return core_.ownship.horizontalSpeed(units);
}
/**
* Set ownship's air velocity. This method resets the wind setting and the air velocity of all traffic aircraft.
*/
void Daidalus::setOwnshipAirVelocity(double heading, double airspeed) {
core_.set_ownship_airvelocity(heading,airspeed);
stale_bands();
}
/**
* Get wind velocity specified in the TO direction
*/
Velocity Daidalus::getWindVelocityTo() const {
return Velocity::make(core_.wind_vector);
}
/**
* Get wind velocity specified in the From direction
*/
Velocity Daidalus::getWindVelocityFrom() const {
return Velocity::make(core_.wind_vector.Neg());
}
/**
* Set wind velocity specified in the TO direction
* @param windto: Wind velocity specified in TO direction
*/
void Daidalus::setWindVelocityTo(const Velocity& windto) {
core_.set_wind_velocity(windto.vect3());
stale_bands();
}
/**
* Set wind velocity specified in the From direction
* @param windfrom: Wind velocity specified in From direction
*/
void Daidalus::setWindVelocityFrom(const Velocity& windfrom) {
setWindVelocityTo(windfrom.Neg());
}
/**
* Set no wind velocity
*/
void Daidalus::setNoWind() {
core_.clear_wind();
stale_bands();
}
/* Alerter Setting */
/**
* Set alerter of the aircraft at ac_idx to alerter_idx
* @param ac_idx: Aircraft index between 0 (ownship) and lastTrafficIndex(), inclusive
* @param alerter_idx: Alerter index starting from 1. The value 0 means none.
*/
void Daidalus::setAlerterIndex(int ac_idx, int alerter_idx) {
if (0 <= ac_idx && ac_idx <= lastTrafficIndex()) {
if (getAircraftStateAt(ac_idx).getAlerterIndex() != alerter_idx) {
if (ac_idx == 0 && core_.set_alerter_ownship(alerter_idx)) {
stale_bands();
} else if (ac_idx > 0 && core_.set_alerter_traffic(ac_idx-1,alerter_idx)) {
stale_bands();
}
}
} else {
error.addError("setAlerterIndex: aircraft index "+Fmi(ac_idx)+" is out of bounds");
}
if (alerter_idx > core_.parameters.numberOfAlerters()) {
error.addWarning("setAlerterIndex: alerter index "+Fmi(alerter_idx)+" is out of bounds");
}
}
/**
* Set alerter of the aircraft at ac_idx to alerter
* @param ac_idx: Aircraft index between 0 (ownship) and lastTrafficIndex(), inclusive
* @param alerter: Alerter identifier
*/
void Daidalus::setAlerter(int ac_idx, const std::string& alerter) {
setAlerterIndex(ac_idx,core_.parameters.getAlerterIndex(alerter));
}
/**
* Return alert index used for the traffic aircraft at index ac_idx.
* The alert index depends on alerting logic. If ownship centric, it returns the
* alert index of ownship. Otherwise, it returns the alert index of the traffic aircraft
* at ac_idx.
*/
int Daidalus::alerterIndexBasedOnAlertingLogic(int ac_idx) {
if (0 <= ac_idx && ac_idx <= lastTrafficIndex()) {
return core_.alerter_index_of(getAircraftStateAt(ac_idx));
}
return 0;
}
/**
* Returns most severe alert level for a given aircraft. Returns 0 if either the aircraft or the alerter is undefined.
*/
int Daidalus::mostSevereAlertLevel(int ac_idx) {
int alerter_idx = alerterIndexBasedOnAlertingLogic(ac_idx);
if (alerter_idx > 0) {
const Alerter& alerter = core_.parameters.getAlerterAt(alerter_idx);
if (alerter.isValid()) {
return alerter.mostSevereAlertLevel();
}
}
return 0;
}
/* SUM Setting */
/**
* Set horizontal position uncertainty of aircraft at index ac_idx
* s_EW_std: East/West position standard deviation in internal units
* s_NS_std: North/South position standard deviation in internal units
* s_EN_std: East/North position standard deviation in internal units
*/
void Daidalus::setHorizontalPositionUncertainty(int ac_idx, double s_EW_std, double s_NS_std, double s_EN_std) {
if (0 <= ac_idx && ac_idx <= lastTrafficIndex()) {
if (ac_idx == 0) {
core_.ownship.setHorizontalPositionUncertainty(s_EW_std,s_NS_std,s_EN_std);
} else {
core_.traffic[ac_idx-1].setHorizontalPositionUncertainty(s_EW_std,s_NS_std,s_EN_std);
}
reset();
}
}
/**
* Set horizontal position uncertainty of aircraft at index ac_idx
* s_EW_std: East/West position standard deviation in given units
* s_NS_std: North/South position standard deviation in given units
* s_EN_std: East/North position standard deviation in given units
*/
void Daidalus::setHorizontalPositionUncertainty(int ac_idx, double s_EW_std, double s_NS_std, double s_EN_std, const std::string& u) {
setHorizontalPositionUncertainty(ac_idx,Units::from(u,s_EW_std),Units::from(u,s_NS_std),Units::from(u,s_EN_std));
}
/**
* Set vertical position uncertainty of aircraft at index ac_idx
* sz_std : Vertical position standard deviation in internal units
*/
void Daidalus::setVerticalPositionUncertainty(int ac_idx, double sz_std) {
if (0 <= ac_idx && ac_idx <= lastTrafficIndex()) {
if (ac_idx == 0) {
core_.ownship.setVerticalPositionUncertainty(sz_std);
} else {
core_.traffic[ac_idx-1].setVerticalPositionUncertainty(sz_std);
}
reset();
}
}
/**
* Set vertical position uncertainty of aircraft at index ac_idx
* sz_std : Vertical position standard deviation in given units
*/
void Daidalus::setVerticalPositionUncertainty(int ac_idx, double sz_std, const std::string& u) {
setVerticalPositionUncertainty(ac_idx,Units::from(u,sz_std));
}
/**
* Set horizontal velocity uncertainty of aircraft at index ac_idx
* v_EW_std: East/West speed standard deviation in internal units
* v_NS_std: North/South speed standard deviation in internal units
* v_EN_std: East/North speed standard deviation in internal units
*/
void Daidalus::setHorizontalVelocityUncertainty(int ac_idx, double v_EW_std, double v_NS_std, double v_EN_std) {
if (0 <= ac_idx && ac_idx <= lastTrafficIndex()) {
if (ac_idx == 0) {
core_.ownship.setHorizontalVelocityUncertainty(v_EW_std,v_NS_std,v_EN_std);
} else {
core_.traffic[ac_idx-1].setHorizontalVelocityUncertainty(v_EW_std,v_NS_std,v_EN_std);
}
reset();
}
}
/**
* Set horizontal velocity uncertainty of aircraft at index ac_idx
* v_EW_std: East/West speed standard deviation in given units
* v_NS_std: North/South speed standard deviation in given units
* v_EN_std: East/North speed standard deviation in given units
*/
void Daidalus::setHorizontalVelocityUncertainty(int ac_idx, double v_EW_std, double v_NS_std, double v_EN_std, const std::string& u) {
setHorizontalVelocityUncertainty(ac_idx,Units::from(u,v_EW_std),Units::from(u,v_NS_std),Units::from(u,v_EN_std));
}
/**
* Set vertical speed uncertainty of aircraft at index ac_idx
* vz_std : Vertical speed standard deviation in internal units
*/
void Daidalus::setVerticalSpeedUncertainty(int ac_idx, double vz_std) {
if (0 <= ac_idx && ac_idx <= lastTrafficIndex()) {
if (ac_idx == 0) {
core_.ownship.setVerticalSpeedUncertainty(vz_std);
} else {
core_.traffic[ac_idx-1].setVerticalSpeedUncertainty(vz_std);
}
reset();
}
}
/**
* Set vertical speed uncertainty of aircraft at index ac_idx
* vz_std : Vertical speed standard deviation in given units
*/
void Daidalus::setVerticalSpeedUncertainty(int ac_idx, double vz_std, const std::string& u) {
setVerticalSpeedUncertainty(ac_idx,Units::from(u,vz_std));
}
/**
* Reset all uncertainties of aircraft at index ac_idx
*/
void Daidalus::resetUncertainty(int ac_idx) {
if (0 <= ac_idx && ac_idx <= lastTrafficIndex()) {
if (ac_idx == 0) {
core_.ownship.resetUncertainty();
} else {
core_.traffic[ac_idx-1].resetUncertainty();
}
reset();
}
}
/* Urgency strategy for implicitly coordinate bands (experimental) */
/**
* @return strategy for computing most urgent aircraft.
*/
const UrgencyStrategy& Daidalus::getUrgencyStrategy() const {
return *core_.urgency_strategy;
}
/**
* Set strategy for computing most urgent aircraft.
*/
void Daidalus::setUrgencyStrategy(const UrgencyStrategy& strat) {
core_.urgency_strategy.reset(strat.copy());
reset();
}
/**
* @return most urgent aircraft.
*/
TrafficState Daidalus::mostUrgentAircraft() {
return core_.mostUrgentAircraft();
}
/* Computation of contours, a.k.a. blobs, and hazard zones */
/**
* Computes horizontal contours contributed by aircraft at index idx, for
* given alert level. A contour is a list of points in counter-clockwise
* direction representing a polygon. Last point should be connected to first one.
* The computed polygon should only be used for display purposes since it's merely an
* approximation of the actual contours defined by the violation and detection methods.
* @param blobs list of horizontal contours returned by reference.
* @param ac_idx is the index of the aircraft used to compute the contours.
* @param alert_level is the alert level used to compute detection. The value 0
* indicate the alert level of the corrective region.
*/
void Daidalus::horizontalContours(std::vector<std::vector<Position> >& blobs, int ac_idx, int alert_level) {
blobs.clear();
if (1 <= ac_idx && ac_idx <= lastTrafficIndex()) {
int code = core_.horizontal_contours(blobs,ac_idx-1,alert_level);
switch (code) {
case 1:
error.addError("horizontalContours: detector of traffic aircraft "+Fmi(ac_idx)+" is not set");
break;
case 2:
error.addError("horizontalContours: no corrective alerter level for alerter of "+Fmi(ac_idx));
break;
case 3:
error.addError("horizontalContours: alerter of traffic aircraft "+Fmi(ac_idx)+" is out of bounds");
break;
}
} else {
error.addError("horizontalContours: aircraft index "+Fmi(ac_idx)+" is out of bounds");
}
}
/**
* Computes horizontal contours contributed by aircraft at index idx, for
* given region. A contour is a list of points in counter-clockwise
* direction representing a polygon. Last point should be connected to first one.
* The computed polygon should only be used for display purposes since it's merely an
* approximation of the actual contours defined by the violation and detection methods.
* @param blobs list of horizontal contours returned by reference.
* @param ac_idx is the index of the aircraft used to compute the contours.
* @param region is the region used to compute detection.
*/
void Daidalus::horizontalContours(std::vector<std::vector<Position> >& blobs, int ac_idx,
BandsRegion::Region region) {
horizontalContours(blobs,ac_idx,alertLevelOfRegion(ac_idx,region));
}
/**
* Computes horizontal hazard zone around aircraft at index ac_idx, for given alert level.
* A hazard zone is a list of points in counter-clockwise
* direction representing a polygon. Last point should be connected to first one.
* @param haz hazard zone returned by reference.
* @param ac_idx is the index of the aircraft used to compute the contours.
* @param loss true means that the polygon represents the hazard zone. Otherwise,
* the polygon represents the hazard zone with an alerting time.
* @param from_ownship true means ownship point of view. Otherwise, the hazard zone is computed
* from the intruder's point of view.
* @param alert_level is the alert level used to compute detection. The value 0
* indicate the alert level of the corrective region.
* NOTE: The computed polygon should only be used for display purposes since it's merely an
* approximation of the actual hazard zone defined by the violation and detection methods.
*/
void Daidalus::horizontalHazardZone(std::vector<Position>& haz, int ac_idx, bool loss, bool from_ownship,
int alert_level) {
haz.clear();
if (1 <= ac_idx && ac_idx <= lastTrafficIndex()) {
int code = core_.horizontal_hazard_zone(haz,ac_idx-1,alert_level,loss,from_ownship);
switch (code) {
case 1:
error.addError("horizontalHazardZone: detector of traffic aircraft "+Fmi(ac_idx)+" is not set");
break;
case 2:
error.addError("horizontalHazardZone: no corrective alerter level for alerter of "+Fmi(ac_idx));
break;
case 3:
error.addError("horizontalHazardZone: alerter of traffic aircraft "+Fmi(ac_idx)+" is out of bounds");
break;
}
} else {
error.addError("horizontalHazardZone: aircraft index "+Fmi(ac_idx)+" is out of bounds");
}
}
/**
* Computes horizontal hazard zone around aircraft at index ac_idx, for given region.
* A hazard zone is a list of points in counter-clockwise
* direction representing a polygon. Last point should be connected to first one.
* @param haz hazard zone returned by reference.
* @param ac_idx is the index of the aircraft used to compute the contours.
* @param loss true means that the polygon represents the hazard zone. Otherwise,
* the polygon represents the hazard zone with an alerting time.
* @param from_ownship true means ownship point of view. Otherwise, the hazard zone is computed
* from the intruder's point of view.
* @param region is the region used to compute detection.
* NOTE: The computed polygon should only be used for display purposes since it's merely an
* approximation of the actual hazard zone defined by the violation and detection methods.
*/
void Daidalus::horizontalHazardZone(std::vector<Position>& haz, int ac_idx, bool loss, bool from_ownship,
BandsRegion::Region region) {
horizontalHazardZone(haz,ac_idx,loss,from_ownship,alertLevelOfRegion(ac_idx,region));
}
/* Setting and getting DaidalusParameters */
/**
* Return number of alerters.
*/
int Daidalus::numberOfAlerters() const {
return core_.parameters.numberOfAlerters();
}
/**
* Return alerter at index i (starting from 1).
*/
const Alerter& Daidalus::getAlerterAt(int i) const {
return core_.parameters.getAlerterAt(i);
}
/**
* Return index of alerter with a given name. Return 0 if it doesn't exist
*/
int Daidalus::getAlerterIndex(const std::string& id) const {
return core_.parameters.getAlerterIndex(id);
}
/**
* Clear all alert thresholds
*/
void Daidalus::clearAlerters() {
core_.parameters.clearAlerters();
reset();
}
/**
* Add alert thresholds
*/
int Daidalus::addAlerter(const Alerter& alerter) {
int alert_idx = core_.parameters.addAlerter(alerter);
reset();
return alert_idx;
}
/**
* @return lookahead time in seconds.
*/
double Daidalus::getLookaheadTime() const {
return core_.parameters.getLookaheadTime();
}
/**
* @return lookahead time in specified units [u].
*/
double Daidalus::getLookaheadTime(const std::string& u) const {
return core_.parameters.getLookaheadTime(u);
}
/**
* @return distance filter in meters.
*/
double Daidalus::getDistanceFilter() const {
return core_.parameters.getDistanceFilter();
}
/**
* @return distance filter in specified units [u].
*/
double Daidalus::getDistanceFilter(const std::string& u) const {
return core_.parameters.getDistanceFilter(u);
}
/**
* @return altitude filter in meters.
*/
double Daidalus::getAltitudeFilter() const {
return core_.parameters.getAltitudeFilter();
}
/**
* @return altitude filter in specified units [u].
*/
double Daidalus::getAltitudeFilter(const std::string& u) const {
return core_.parameters.getAltitudeFilter(u);
}
/**
* @return left direction in radians [0 - pi] [rad] from current ownship's direction
*/
double Daidalus::getLeftHorizontalDirection() const {
return core_.parameters.getLeftHorizontalDirection();
}
/**
* @return left direction in specified units [0 - pi] [u] from current ownship's direction
*/
double Daidalus::getLeftHorizontalDirection(const std::string& u) const {
return Units::to(u,getLeftHorizontalDirection());
}
/**
* @return right direction in radians [0 - pi] [rad] from current ownship's direction
*/
double Daidalus::getRightHorizontalDirection() const {
return core_.parameters.getRightHorizontalDirection();
}
/**
* @return right direction in specified units [0 - pi] [u] from current ownship's direction
*/
double Daidalus::getRightHorizontalDirection(const std::string& u) const {
return Units::to(u,getRightHorizontalDirection());
}
/**
* @return airspeed threshold in internal units [m/s].
*/
double Daidalus::getAirspeedThreshold() const {
return core_.parameters.getAirspeedThreshold();
}
/**
* @return airspeed threshold in specified units [u].
*/
double Daidalus::getAirspeedThreshold(const std::string& u) const {
return Units::to(u,getAirspeedThreshold());
}
/**
* @return minimum horizontal speed for horizontal speed bands in internal units [m/s].
*/
double Daidalus::getMinHorizontalSpeed() const {
return core_.parameters.getMinHorizontalSpeed();
}
/**
* @return minimum horizontal speed for horizontal speed bands in specified units [u].
*/
double Daidalus::getMinHorizontalSpeed(const std::string& u) const {
return Units::to(u,getMinHorizontalSpeed());
}
/**
* @return maximum horizontal speed for horizontal speed bands in internal units [m/s].
*/
double Daidalus::getMaxHorizontalSpeed() const {
return core_.parameters.getMaxHorizontalSpeed();
}
/**
* @return maximum horizontal speed for horizontal speed bands in specified units [u].
*/
double Daidalus::getMaxHorizontalSpeed(const std::string& u) const {
return Units::to(u,getMaxHorizontalSpeed());
}
/**
* @return minimum vertical speed for vertical speed bands in internal units [m/s].
*/
double Daidalus::getMinVerticalSpeed() const {
return core_.parameters.getMinVerticalSpeed();
}
/**
* @return minimum vertical speed for vertical speed bands in specified units [u].
*/
double Daidalus::getMinVerticalSpeed(const std::string& u) const {
return Units::to(u,getMinVerticalSpeed());
}
/**
* @return maximum vertical speed for vertical speed bands in internal units [m/s].
*/
double Daidalus::getMaxVerticalSpeed() const {
return core_.parameters.getMaxVerticalSpeed();
}
/**
* @return maximum vertical speed for vertical speed bands in specified units [u].
*/
double Daidalus::getMaxVerticalSpeed(const std::string& u) const {
return Units::to(u,getMaxVerticalSpeed());
}
/**
* @return minimum altitude for altitude bands in internal units [m]
*/
double Daidalus::getMinAltitude() const {
return core_.parameters.getMinAltitude();
}
/**
* @return minimum altitude for altitude bands in specified units [u].
*/
double Daidalus::getMinAltitude(const std::string& u) const {
return Units::to(u,getMinAltitude());
}
/**
* @return maximum altitude for altitude bands in internal units [m]
*/
double Daidalus::getMaxAltitude() const {
return core_.parameters.getMaxAltitude();
}
/**
* @return maximum altitude for altitude bands in specified units [u].
*/
double Daidalus::getMaxAltitude(const std::string& u) const {
return Units::to(u,getMaxAltitude());
}
/**
* @return Horizontal speed in internal units (below current value) for the
* computation of relative bands
*/
double Daidalus::getBelowRelativeHorizontalSpeed() const {
return core_.parameters.getBelowRelativeHorizontalSpeed();
}