-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathAlertThresholds.cpp
417 lines (372 loc) · 13.2 KB
/
AlertThresholds.cpp
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
/*
* 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.
*/
#include "AlertThresholds.h"
#include "Vect3.h"
#include "Util.h"
#include "Velocity.h"
#include "Detection3D.h"
#include "ConflictData.h"
#include "format.h"
namespace larcfm {
/**
* Creates an alert threholds object. Parameter det is a detector,
* alerting_time is a non-negative alerting time (possibly positive infinity),
* early_alerting_time is a early alerting time >= at (for maneuver guidance),
* region is the type of guidance
*/
AlertThresholds::AlertThresholds(const Detection3D& detector,
double alerting_time, double early_alerting_time, BandsRegion::Region region) :
detector_(detector.copy()),
alerting_time_(std::abs(alerting_time)),
early_alerting_time_(Util::max(alerting_time_,early_alerting_time)),
region_(region),
spread_hdir_(0.0),
spread_hs_(0.0),
spread_vs_(0.0),
spread_alt_(0.0) {
units_["alerting_time"] = "s";
units_["early_alerting_time"] = "s";
units_["spread_hdir"] = "deg";
units_["spread_hs"] = "knot";
units_["spread_vs"] = "fpm";
units_["spread_alt"] = "ft";
}
AlertThresholds::AlertThresholds(const AlertThresholds& athr) :
detector_(athr.detector_ ? athr.detector_->copy() : nullptr),
alerting_time_(athr.alerting_time_),
early_alerting_time_(athr.early_alerting_time_),
region_(athr.region_),
spread_hdir_(athr.spread_hdir_),
spread_hs_(athr.spread_hs_),
spread_vs_(athr.spread_vs_),
spread_alt_(athr.spread_alt_),
units_(athr.units_) {}
AlertThresholds::AlertThresholds() :
alerting_time_(0.0),
early_alerting_time_(0.0),
region_(BandsRegion::UNKNOWN),
spread_hdir_(0.0),
spread_hs_(0.0),
spread_vs_(0.0),
spread_alt_(0.0) {
units_["alerting_time"] = "s";
units_["early_alerting_time"] = "s";
units_["spread_hdir"] = "deg";
units_["spread_hs"] = "m/s";
units_["spread_vs"] = "m/s";
units_["spread_alt"] = "m";
}
/**
* Beware of this constructor. From this point on, AlertThresholds owns
* this Detection3D pointer.
*/
AlertThresholds::AlertThresholds(Detection3D* det) :
detector_(det),
alerting_time_(0.0),
early_alerting_time_(0.0),
region_(BandsRegion::UNKNOWN),
spread_hdir_(0.0),
spread_hs_(0.0),
spread_vs_(0.0),
spread_alt_(0.0) {
units_["alerting_time"] = "s";
units_["early_alerting_time"] = "s";
units_["spread_hdir"] = "deg";
units_["spread_hs"] = "m/s";
units_["spread_vs"] = "m/s";
units_["spread_alt"] = "m";
}
const AlertThresholds& AlertThresholds::INVALID() {
const static AlertThresholds athr;
return athr;
}
AlertThresholds::~AlertThresholds() {}
void AlertThresholds::copyFrom(const AlertThresholds& athr) {
if (&athr != this) {
if (athr.detector_) {
detector_.reset(athr.detector_->copy());
}
alerting_time_ = athr.alerting_time_;
early_alerting_time_ = athr.early_alerting_time_;
region_ = athr.region_;
spread_hdir_ = athr.spread_hdir_;
spread_hs_ = athr.spread_hs_;
spread_vs_ = athr.spread_vs_;
spread_alt_ = athr.spread_alt_;
units_ = athr.units_;
}
}
AlertThresholds& AlertThresholds::operator=(const AlertThresholds& athr) {
copyFrom(athr);
return *this;
}
bool AlertThresholds::isValid() const {
return detector_ && region_ != BandsRegion::UNKNOWN;
}
/**
* Return detector.
*/
const Detection3D& AlertThresholds::getCoreDetection() const {
return *detector_;
}
/**
* Set detector.
*/
void AlertThresholds::setCoreDetection(const Detection3D& det) {
detector_.reset(det.copy());
}
/**
* Return alerting time in seconds.
*/
double AlertThresholds::getAlertingTime() const {
return alerting_time_;
}
/**
* Return alerting time in specified units.
*/
double AlertThresholds::getAlertingTime(const std::string& u) const {
return Units::to(u,alerting_time_);
}
/**
* Set alerting time in seconds. Alerting time is non-negative number.
*/
void AlertThresholds::setAlertingTime(double val) {
alerting_time_ = std::abs(val);
}
/**
* Set alerting time in specified units. Alerting time is non-negative number.
*/
void AlertThresholds::setAlertingTime(double t, const std::string& u) {
setAlertingTime(Units::from(u,t));
units_["alerting_time"] = u;
}
/**
* Return early alerting time in seconds.
*/
double AlertThresholds::getEarlyAlertingTime() const {
return early_alerting_time_;
}
/**
* Return early alerting time in specified units.
*/
double AlertThresholds::getEarlyAlertingTime(const std::string& u) const {
return Units::to(u,early_alerting_time_);
}
/**
* Set early alerting time in seconds. Early alerting time is a positive number >= alerting time
*/
void AlertThresholds::setEarlyAlertingTime(double t) {
early_alerting_time_ = std::abs(t);
}
/**
* Set early alerting time in specified units. Early alerting time is a positive number >= alerting time
*/
void AlertThresholds::setEarlyAlertingTime(double t, const std::string& u) {
setEarlyAlertingTime(Units::from(u,t));
units_["early_alerting_time"] = u;
}
/**
* Return guidance region.
*/
BandsRegion::Region AlertThresholds::getRegion() const {
return region_;
}
/**
* Set guidance region.
*/
void AlertThresholds::setRegion(BandsRegion::Region region) {
region_ = region;
}
/**
* Get track spread in internal units [rad]. Spread is relative to ownship's track
*/
double AlertThresholds::getHorizontalDirectionSpread() const {
return spread_hdir_;
}
/**
* Get track spread in given units [u]. Spread is relative to ownship's track
*/
double AlertThresholds::getHorizontalDirectionSpread(const std::string& u) const {
return Units::to(u,spread_hdir_);
}
/**
* Set track spread in internal units. Spread is relative to ownship's track and is expected
* to be in [0,pi].
*/
void AlertThresholds::setHorizontalDirectionSpread(double spread) {
spread_hdir_ = std::abs(Util::to_pi(spread));
}
/**
* Set track spread in given units. Spread is relative to ownship's track and is expected
* to be in [0,pi] [u].
*/
void AlertThresholds::setHorizontalDirectionSpread(double spread, const std::string& u) {
setHorizontalDirectionSpread(Units::from(u,spread));
units_["spread_hdir"] = u;
}
/**
* Get ground speed spread in internal units [m/s]. Spread is relative to ownship's ground speed
*/
double AlertThresholds::getHorizontalSpeedSpread() const {
return spread_hs_;
}
/**
* Get ground speed spread in given units. Spread is relative to ownship's ground speed
*/
double AlertThresholds::getHorizontalSpeedSpread(const std::string& u) const {
return Units::to(u,spread_hs_);
}
/**
* Set ground speed spread in internal units [m/s]. Spread is relative to ownship's ground speed and is expected
* to be non-negative
*/
void AlertThresholds::setHorizontalSpeedSpread(double spread) {
spread_hs_ = std::abs(spread);
}
/**
* Set ground speed spread in given units. Spread is relative to ownship's ground speed and is expected
* to be non-negative
*/
void AlertThresholds::setHorizontalSpeedSpread(double spread, const std::string& u) {
setHorizontalSpeedSpread(Units::from(u,spread));
units_["spread_hs"] = u;
}
/**
* Get vertical speed spread in internal units [m/s]. Spread is relative to ownship's vertical speed
*/
double AlertThresholds::getVerticalSpeedSpread() const {
return spread_vs_;
}
/**
* Get vertical speed spread in given units. Spread is relative to ownship's vertical speed
*/
double AlertThresholds::getVerticalSpeedSpread(const std::string& u) const {
return Units::to(u,spread_vs_);
}
/**
* Set vertical speed spread in internal units [m/s]. Spread is relative to ownship's vertical speed and is expected
* to be non-negative
*/
void AlertThresholds::setVerticalSpeedSpread(double spread) {
spread_vs_ = std::abs(spread);
}
/**
* Set vertical speed spread in given units. Spread is relative to ownship's vertical speed and is expected
* to be non-negative
*/
void AlertThresholds::setVerticalSpeedSpread(double spread, const std::string& u) {
setVerticalSpeedSpread(Units::from(u,spread));
units_["spread_vs"] = u;
}
/**
* Get altitude spread in internal units [m]. Spread is relative to ownship's altitude
*/
double AlertThresholds::getAltitudeSpread() const {
return spread_alt_;
}
/**
* Get altitude spread in given units. Spread is relative to ownship's altitude
*/
double AlertThresholds::getAltitudeSpread(const std::string& u) const {
return Units::to(u,spread_alt_);
}
/**
* Set altitude spread in internal units [m]. Spread is relative to ownship's altitude and is expected
* to be non-negative
*/
void AlertThresholds::setAltitudeSpread(double spread) {
spread_alt_ = std::abs(spread);
}
/**
* Set altitude spread in given units. Spread is relative to ownship's altitude and is expected
* to be non-negative
*/
void AlertThresholds::setAltitudeSpread(double spread, const std::string& u) {
setAltitudeSpread(Units::from(u,spread));
units_["spread_alt"] = u;
}
std::string AlertThresholds::toString() const {
return "volume = "+(detector_ == NULL ? "INVALID_DETECTOR" : detector_->toString())+
", alerting_time = "+Units::str(getUnits("alerting_time"),alerting_time_)+
", early_alerting_time = "+Units::str(getUnits("early_alerting_time"),early_alerting_time_)+
", region = "+BandsRegion::to_string(region_)+
", spread_hdir = "+Units::str(getUnits("spread_hdir"),spread_hdir_)+
", spread_hs = "+Units::str(getUnits("spread_hs"),spread_hs_)+
", spread_vs = "+Units::str(getUnits("spread_vs"),spread_vs_)+
", spread_alt = "+Units::str(getUnits("spread_alt"),spread_alt_);
}
std::string AlertThresholds:: toPVS() const {
return "(# volume:= "+(detector_ == NULL ? "INVALID_DETECTOR" :detector_->toPVS())+
", alerting_time:= "+FmPrecision(alerting_time_)+
", early_alerting_time:= "+FmPrecision(early_alerting_time_)+
", region:= "+BandsRegion::to_string(region_)+
", spread_hdir:= ("+FmPrecision(spread_hdir_)+","+FmPrecision(spread_hdir_)+")"+
", spread_hs:= ("+FmPrecision(spread_hs_)+","+FmPrecision(spread_hs_)+")"+
", spread_vs:= ("+FmPrecision(spread_vs_)+","+FmPrecision(spread_vs_)+")"+
", spread_alt:= ("+FmPrecision(spread_alt_)+","+FmPrecision(spread_alt_)+")"+
" #)";
}
ParameterData AlertThresholds::getParameters() const {
ParameterData p;
updateParameterData(p);
return p;
}
void AlertThresholds::updateParameterData(ParameterData& p) const {
p.set("region",BandsRegion::to_string(region_));
p.setInternal("alerting_time",alerting_time_,getUnits("alerting_time"));
p.setInternal("early_alerting_time",early_alerting_time_,getUnits("early_alerting_time"));
p.setInternal("spread_hdir",spread_hdir_,getUnits("spread_hdir"));
p.setInternal("spread_hs",spread_hs_,getUnits("spread_hs"));
p.setInternal("spread_vs",spread_vs_,getUnits("spread_vs"));
p.setInternal("spread_alt",spread_alt_,getUnits("spread_alt"));
if (detector_ != NULL) {
p.set("detector",detector_->getIdentifier());
}
}
void AlertThresholds::setParameters(const ParameterData& p) {
if (p.contains("region")) {
setRegion(BandsRegion::valueOf(p.getString("region")));
}
if (p.contains("alerting_time")) {
setAlertingTime(p.getValue("alerting_time"));
units_["alerting_time"] = p.getUnit("alerting_time");
}
if (p.contains("early_alerting_time")) {
setEarlyAlertingTime(p.getValue("early_alerting_time"));
units_["early_alerting_time"] = p.getUnit("early_alerting_time");
}
if (p.contains("spread_hdir")) {
setHorizontalDirectionSpread(p.getValue("spread_hdir"));
units_["spread_hdir"] = p.getUnit("spread_hdir");
} else if (p.contains("spread_trk")) {
setHorizontalDirectionSpread(p.getValue("spread_trk"));
units_["spread_hdir"] = p.getUnit("spread_trk");
}
if (p.contains("spread_hs")) {
setHorizontalSpeedSpread(p.getValue("spread_hs"));
units_["spread_hs"] = p.getUnit("spread_hs");
} else if (p.contains("spread_gs")) {
setHorizontalSpeedSpread(p.getValue("spread_gs"));
units_["spread_hs"] = p.getUnit("spread_gs");
}
if (p.contains("spread_vs")) {
setVerticalSpeedSpread(p.getValue("spread_vs"));
units_["spread_vs"] = p.getUnit("spread_vs");
}
if (p.contains("spread_alt")) {
setAltitudeSpread(p.getValue("spread_alt"));
units_["spread_alt"] = p.getUnit("spread_alt");
}
}
std::string AlertThresholds::getUnits(const std::string& key) const {
std::map<std::string,std::string>::const_iterator got = units_.find(key);
if (got == units_.end()) {
return "unspecified";
}
return got->second;
}
}