Rise
The Vieneo Province
Toggle main menu visibility
Loading...
Searching...
No Matches
GpwsPredictiveWindshear.h
Go to the documentation of this file.
1
#pragma once
2
#include "
GpwsWindshear.h
"
3
#include <algorithm>
4
#include <array>
5
6
// Rise surface-grid look-ahead advisory. This is horizontal shear only, not a
7
// Doppler microburst sensor or an aircraft-performance/escape calculation.
8
namespace
GpwsPredictiveWindshear
9
{
10
using
GpwsWindshear::Vector3
;
11
using
GpwsWindshear::Finite
;
12
using
GpwsWindshear::Dot
;
13
using
GpwsWindshear::Unit
;
14
constexpr
double
HorizonSeconds
= 30,
MaxRangeKm
= 8,
StepKm
= .25;
15
constexpr
double
SourceTimeoutSeconds
= 360;
// server's five-minute weather epoch + margin
16
// Retain the horizontal sensitivity of Rise's reactive detector. The loss
17
// floor rejects small differences in the byte-quantized surface vectors.
18
// These are Rise tuning choices, not manufacturer-certified F-factor limits.
19
constexpr
double
EnterRateMs2
= 1750. / (750. * 1.94384449);
20
constexpr
double
ExitRateMs2
=
EnterRateMs2
* .75;
21
constexpr
double
EnterLossMs
= 5,
ExitLossMs
= 4,
ConfirmSeconds
= .5;
22
struct
Sample
{ Vector3
windToMs
{};
double
surfaceKm
= 0;
bool
valid
=
false
; };
23
struct
Input
24
{
25
Vector3
position
{},
groundVelocityKms
{};
26
double
radiusKm
= 0,
radioKm
= 0,
maxFrameSeconds
= 0;
27
bool
enabled
=
false
,
dataAvailable
=
false
;
28
int
vehicle
= -1;
29
uint64_t
generation
= 0;
30
uint32_t
revision
= 0;
31
};
32
struct
State
33
{
34
bool
enabled
=
false
,
available
=
false
,
complete
=
false
,
caution
=
false
;
35
double
rangeKm
= 0,
timeSeconds
= 0,
headwindLossMs
= 0,
lossRateMs2
= 0;
36
};
37
class
Detector
38
{
39
Input
previous
{};
40
bool
trackedSource
=
false
,
trackedMotion
=
false
,
candidate
=
false
,
active
=
false
;
41
double
sourceAge
= 0,
confirm
= 0;
42
void
ClearEncounter
() {
candidate
=
active
=
false
;
confirm
= 0;
trackedMotion
=
false
; }
43
public
:
44
template
<
class
Sampler>
void
Update
(
const
Input
& in,
double
elapsed, Sampler sample,
State
& out)
45
{
46
out = {};
47
if
(!std::isfinite(elapsed) || elapsed <= 0) {
ClearEncounter
();
return
; }
48
// Age a source even while alerting is disarmed, so a power or height
49
// transition cannot rejuvenate an old grid. No cross-revision differencing.
50
const
bool
restarted = in.
dataAvailable
&& (!
trackedSource
|| in.
vehicle
!=
previous
.
vehicle
||
51
in.
generation
!=
previous
.
generation
);
52
const
bool
changed = in.
dataAvailable
&& (restarted || in.
revision
!=
previous
.
revision
);
53
if
(changed) {
sourceAge
= 0;
trackedSource
=
true
; }
54
else
if
(
trackedSource
)
sourceAge
+= elapsed;
55
if
(restarted)
ClearEncounter
();
56
if
(in.
dataAvailable
)
57
{
58
previous
.
vehicle
= in.
vehicle
;
previous
.
generation
= in.
generation
;
previous
.
revision
= in.
revision
;
59
}
60
Vector3 up = in.
position
;
61
const
double
radius = std::sqrt(
double
(
Dot
(up,up)));
62
if
(!in.
enabled
|| !
GpwsWindshear::HeightAllowed
(
float
(in.
radioKm
)) || !
Unit
(up) ||
63
!
Finite
(in.
groundVelocityKms
) || !std::isfinite(in.
radiusKm
) || in.
radiusKm
<= 0 ||
64
radius < in.
radiusKm
* .9)
65
{
ClearEncounter
();
return
; }
66
const
double
vertical =
Dot
(in.
groundVelocityKms
,up);
67
Vector3 forward = in.
groundVelocityKms
-up*float(vertical);
68
const
double
speed = std::sqrt(
double
(
Dot
(forward,forward)));
69
// Hover has no projected horizontal encounter. Reactive Mode 7
70
// remains responsible for a gust/downdraft at the current position.
71
if
(speed < .001 || !
Unit
(forward)) {
ClearEncounter
();
return
; }
72
out.
enabled
=
true
;
73
const
double
frame = in.
maxFrameSeconds
> 0 ? in.
maxFrameSeconds
: elapsed;
74
if
(!in.
dataAvailable
||
sourceAge
>
SourceTimeoutSeconds
|| !std::isfinite(in.
maxFrameSeconds
) ||
75
in.
maxFrameSeconds
< 0 || frame > .5)
76
{
ClearEncounter
();
return
; }
77
const
bool
relocated =
trackedMotion
&&
78
std::sqrt(
double
(
Dot
(in.
position
-
previous
.
position
,in.
position
-
previous
.
position
))) >
79
1 + std::sqrt(
double
(
Dot
(
previous
.
groundVelocityKms
,
previous
.
groundVelocityKms
))) * elapsed;
80
if
(relocated)
ClearEncounter
();
81
previous
.
position
= in.
position
;
previous
.
groundVelocityKms
= in.
groundVelocityKms
;
trackedMotion
=
true
;
82
const
double
requestedRange = speed *
HorizonSeconds
;
83
const
double
range = (std::min)(
MaxRangeKm
,requestedRange);
84
const
int
steps = (std::max)(1,
int
(std::ceil(range/
StepKm
)));
85
const
double
step = range/steps;
86
std::array<Sample,33> points{};
87
bool
found =
false
;
88
out.
complete
= requestedRange <=
MaxRangeKm
;
89
for
(
int
i = 0; i <= steps; ++i)
90
{
91
const
double
distance = step*i, time = distance/speed;
92
const
double
angle = distance/radius;
93
const
Vector3 radial = up*float(std::cos(angle))+forward*float(std::sin(angle));
94
const
Vector3 position = radial*float(radius+vertical*time);
95
points[i] = sample(position);
96
const
auto
& here = points[i];
97
if
(!here.valid || !
Finite
(here.windToMs) || !std::isfinite(here.surfaceKm))
98
{ out.
complete
=
false
;
break
; }
// never compare across missing cells
99
const
double
agl = radius-in.
radiusKm
+vertical*time-here.surfaceKm;
100
if
(agl < .003048 || agl > .4572)
101
{ out.
complete
=
false
;
break
; }
// no surface-wind prediction in space or through terrain
102
out.
available
=
true
;
103
if
(i == 0)
continue
;
104
// Compare over at most a kilometre, within this single snapshot.
105
// Ground speed converts a spatial gradient into an encounter rate.
106
const
int
back = (std::max)(0,i-(std::max)(1,
int
(std::floor(1/step))));
107
const
double
loss =
Dot
(here.windToMs-points[back].windToMs,forward);
108
const
double
rate = loss/((i-back)*step/speed);
109
if
(!found && loss >= (
active
?
ExitLossMs
:
EnterLossMs
) &&
110
rate > (
active
?
ExitRateMs2
:
EnterRateMs2
))
111
{
112
found =
true
; out.
rangeKm
= distance; out.
timeSeconds
= time;
113
out.
headwindLossMs
= loss; out.
lossRateMs2
= rate;
114
}
115
}
116
if
(!found) {
candidate
=
active
=
false
;
confirm
= 0;
return
; }
117
if
(!
candidate
) {
candidate
=
true
;
confirm
= 0; }
118
else
confirm
+= elapsed;
119
active
=
active
||
confirm
>=
ConfirmSeconds
;
120
out.
caution
=
active
;
121
}
122
};
123
}
GpwsWindshear.h
GpwsPredictiveWindshear::Detector
Definition
GpwsPredictiveWindshear.h:38
GpwsPredictiveWindshear::Detector::ClearEncounter
void ClearEncounter()
Definition
GpwsPredictiveWindshear.h:42
GpwsPredictiveWindshear::Detector::candidate
bool candidate
Definition
GpwsPredictiveWindshear.h:40
GpwsPredictiveWindshear::Detector::active
bool active
Definition
GpwsPredictiveWindshear.h:40
GpwsPredictiveWindshear::Detector::previous
Input previous
Definition
GpwsPredictiveWindshear.h:39
GpwsPredictiveWindshear::Detector::confirm
double confirm
Definition
GpwsPredictiveWindshear.h:41
GpwsPredictiveWindshear::Detector::Update
void Update(const Input &in, double elapsed, Sampler sample, State &out)
Definition
GpwsPredictiveWindshear.h:44
GpwsPredictiveWindshear::Detector::trackedSource
bool trackedSource
Definition
GpwsPredictiveWindshear.h:40
GpwsPredictiveWindshear::Detector::trackedMotion
bool trackedMotion
Definition
GpwsPredictiveWindshear.h:40
GpwsPredictiveWindshear::Detector::sourceAge
double sourceAge
Definition
GpwsPredictiveWindshear.h:41
GpwsPredictiveWindshear
Definition
GpwsPredictiveWindshear.h:9
GpwsPredictiveWindshear::HorizonSeconds
constexpr double HorizonSeconds
Definition
GpwsPredictiveWindshear.h:14
GpwsPredictiveWindshear::StepKm
constexpr double StepKm
Definition
GpwsPredictiveWindshear.h:14
GpwsPredictiveWindshear::Finite
bool Finite(const Vector3 &v)
Definition
GpwsWindshear.h:12
GpwsPredictiveWindshear::EnterLossMs
constexpr double EnterLossMs
Definition
GpwsPredictiveWindshear.h:21
GpwsPredictiveWindshear::ExitLossMs
constexpr double ExitLossMs
Definition
GpwsPredictiveWindshear.h:21
GpwsPredictiveWindshear::ExitRateMs2
constexpr double ExitRateMs2
Definition
GpwsPredictiveWindshear.h:20
GpwsPredictiveWindshear::SourceTimeoutSeconds
constexpr double SourceTimeoutSeconds
Definition
GpwsPredictiveWindshear.h:15
GpwsPredictiveWindshear::ConfirmSeconds
constexpr double ConfirmSeconds
Definition
GpwsPredictiveWindshear.h:21
GpwsPredictiveWindshear::Unit
bool Unit(Vector3 &v)
Definition
GpwsWindshear.h:15
GpwsPredictiveWindshear::Dot
float Dot(const Vector3 &a, const Vector3 &b)
Definition
GpwsWindshear.h:14
GpwsPredictiveWindshear::MaxRangeKm
constexpr double MaxRangeKm
Definition
GpwsPredictiveWindshear.h:14
GpwsPredictiveWindshear::EnterRateMs2
constexpr double EnterRateMs2
Definition
GpwsPredictiveWindshear.h:19
GpwsWindshear::Finite
bool Finite(const Vector3 &v)
Definition
GpwsWindshear.h:12
GpwsWindshear::HeightAllowed
bool HeightAllowed(float radioKm)
Definition
GpwsWindshear.h:55
GpwsWindshear::Unit
bool Unit(Vector3 &v)
Definition
GpwsWindshear.h:15
GpwsWindshear::Dot
float Dot(const Vector3 &a, const Vector3 &b)
Definition
GpwsWindshear.h:14
GpwsPredictiveWindshear::Input
Definition
GpwsPredictiveWindshear.h:24
GpwsPredictiveWindshear::Input::groundVelocityKms
Vector3 groundVelocityKms
Definition
GpwsPredictiveWindshear.h:25
GpwsPredictiveWindshear::Input::generation
uint64_t generation
Definition
GpwsPredictiveWindshear.h:29
GpwsPredictiveWindshear::Input::vehicle
int vehicle
Definition
GpwsPredictiveWindshear.h:28
GpwsPredictiveWindshear::Input::maxFrameSeconds
double maxFrameSeconds
Definition
GpwsPredictiveWindshear.h:26
GpwsPredictiveWindshear::Input::revision
uint32_t revision
Definition
GpwsPredictiveWindshear.h:30
GpwsPredictiveWindshear::Input::enabled
bool enabled
Definition
GpwsPredictiveWindshear.h:27
GpwsPredictiveWindshear::Input::position
Vector3 position
Definition
GpwsPredictiveWindshear.h:25
GpwsPredictiveWindshear::Input::radiusKm
double radiusKm
Definition
GpwsPredictiveWindshear.h:26
GpwsPredictiveWindshear::Input::dataAvailable
bool dataAvailable
Definition
GpwsPredictiveWindshear.h:27
GpwsPredictiveWindshear::Input::radioKm
double radioKm
Definition
GpwsPredictiveWindshear.h:26
GpwsPredictiveWindshear::Sample
Definition
GpwsPredictiveWindshear.h:22
GpwsPredictiveWindshear::Sample::surfaceKm
double surfaceKm
Definition
GpwsPredictiveWindshear.h:22
GpwsPredictiveWindshear::Sample::valid
bool valid
Definition
GpwsPredictiveWindshear.h:22
GpwsPredictiveWindshear::Sample::windToMs
Vector3 windToMs
Definition
GpwsPredictiveWindshear.h:22
GpwsPredictiveWindshear::State
Definition
GpwsPredictiveWindshear.h:33
GpwsPredictiveWindshear::State::lossRateMs2
double lossRateMs2
Definition
GpwsPredictiveWindshear.h:35
GpwsPredictiveWindshear::State::rangeKm
double rangeKm
Definition
GpwsPredictiveWindshear.h:35
GpwsPredictiveWindshear::State::enabled
bool enabled
Definition
GpwsPredictiveWindshear.h:34
GpwsPredictiveWindshear::State::timeSeconds
double timeSeconds
Definition
GpwsPredictiveWindshear.h:35
GpwsPredictiveWindshear::State::headwindLossMs
double headwindLossMs
Definition
GpwsPredictiveWindshear.h:35
GpwsPredictiveWindshear::State::caution
bool caution
Definition
GpwsPredictiveWindshear.h:34
GpwsPredictiveWindshear::State::complete
bool complete
Definition
GpwsPredictiveWindshear.h:34
GpwsPredictiveWindshear::State::available
bool available
Definition
GpwsPredictiveWindshear.h:34
RiseMath::Vector3
Definition
ClientMath.h:38
GpwsPredictiveWindshear.h
Generated on
for Rise by
1.18.0