Rise
The Vieneo Province
Toggle main menu visibility
Loading...
Searching...
No Matches
GpwsWindshear.h
Go to the documentation of this file.
1
#pragma once
2
#include "
Rendering/ClientMath.h
"
3
#include <cmath>
4
#include <cstdint>
5
#include <deque>
6
7
// Reactive windshear inputs and the retained Rise approximation. This is not
8
// Honeywell's proprietary performance-dependent Mode 7 or predictive radar.
9
namespace
GpwsWindshear
10
{
11
using
RiseMath::Vector3
;
12
inline
bool
Finite
(
const
Vector3
& v)
13
{
return
std::isfinite(v.x) && std::isfinite(v.y) && std::isfinite(v.z); }
14
inline
float
Dot
(
const
Vector3
& a,
const
Vector3
& b) {
return
a.x*b.x+a.y*b.y+a.z*b.z; }
15
inline
bool
Unit
(
Vector3
& v)
16
{
17
const
float
squared =
Dot
(v,v);
18
if
(!
Finite
(v) || !std::isfinite(squared) || squared < 1.e-12f)
return
false
;
19
v *= 1.f/std::sqrt(squared);
return
true
;
20
}
21
struct
Sample
22
{
23
// Actual air velocity in planet/world coordinates, including body gusts.
24
Vector3
windToMs
{},
up
{},
forward
{};
25
double
seconds
= 0;
26
uint64_t
sequence
= 0;
27
int
vehicle
= -1;
28
bool
simulator
=
false
,
valid
=
false
;
29
};
30
inline
void
Publish
(
Sample
& sample,
float
elapsed,
const
Vector3
& bodyWindKms,
31
const
RiseMath::Matrix
& bodyToWorld,
const
Vector3
& groundVelocityKms,
32
const
Vector3
& position,
int
vehicle,
bool
simulator,
bool
available)
33
{
34
++sample.
sequence
;
35
sample.
vehicle
= vehicle; sample.
simulator
= simulator; sample.
valid
=
false
;
36
if
(!std::isfinite(elapsed) || elapsed <= 0)
return
;
37
sample.
seconds
+= elapsed;
38
sample.
up
= position;
39
if
(!available || !
Unit
(sample.
up
) || !
Finite
(bodyWindKms) || !
Finite
(groundVelocityKms))
return
;
40
RiseMath::Vec3TransformNormal
(&sample.
windToMs
,&bodyWindKms,&bodyToWorld);
41
sample.
windToMs
*= 1000.f;
42
sample.
forward
= groundVelocityKms-sample.
up
*
Dot
(groundVelocityKms,sample.
up
);
43
if
(!
Unit
(sample.
forward
))
44
{
45
// Hover/vertical flight has no ground track. Keep vertical protection
46
// and use the horizontal nose direction when it exists; never divide by TAS.
47
const
Vector3
nose(0,0,-1);
// propulsion StraightAheadVector uses body -Z
48
RiseMath::Vec3TransformNormal
(&sample.
forward
,&nose,&bodyToWorld);
49
sample.
forward
-= sample.
up
*
Dot
(sample.
forward
,sample.
up
);
50
if
(!
Unit
(sample.
forward
)) sample.
forward
=
Vector3
{};
51
}
52
sample.
valid
=
Finite
(sample.
windToMs
);
53
}
54
enum class
Alert
{
None
,
Caution
,
Warning
};
55
inline
bool
HeightAllowed
(
float
radioKm)
56
{
return
std::isfinite(radioKm) && radioKm >= .003048f && radioKm <= .4572f; }
57
class
Detector
58
{
59
struct
Point
{
double
time
;
Vector3
wind
; };
60
std::deque<Point>
history
;
61
Sample
previous
{};
62
double
age
= 0;
63
Alert
alert
=
Alert::None
;
64
float
headwindRate
= 0,
updraft
= 0;
65
public
:
66
// One-second differencing preserves the old sensor's intended time
67
// scale. Two seconds is an input freshness limit, not an aircraft envelope.
68
static
constexpr
double
WindowSeconds
= 1.,
StaleSeconds
= 2.;
69
void
Reset
() {
history
.clear();
previous
= {};
age
= 0;
alert
=
Alert::None
;
headwindRate
=
updraft
= 0; }
70
float
HeadwindRateKnotsPerSecond
()
const
{
return
headwindRate
; }
71
float
UpdraftMs
()
const
{
return
updraft
; }
72
Alert
Update
(
const
Sample
& sample,
float
elapsed,
bool
enabled)
73
{
74
if
(!enabled || !std::isfinite(elapsed) || elapsed <= 0 || !sample.
valid
||
75
!std::isfinite(sample.
seconds
) || !
Finite
(sample.
windToMs
) ||
76
!
Finite
(sample.
up
) || !
Finite
(sample.
forward
)) {
Reset
();
return
Alert::None
; }
77
age
+= elapsed;
78
if
(!
history
.empty() && sample.
sequence
==
previous
.
sequence
)
79
{
80
if
(
age
>
StaleSeconds
) {
Reset
();
previous
= sample; }
81
return
alert
;
82
}
83
// Never re-admit a stale duplicate after clearing its history.
84
if
(
history
.empty() && sample.
sequence
==
previous
.
sequence
)
return
Alert::None
;
85
if
(!
history
.empty() && (sample.
vehicle
!=
previous
.
vehicle
|| sample.
simulator
!=
previous
.
simulator
||
86
sample.
seconds
<=
previous
.
seconds
|| sample.
seconds
-
previous
.
seconds
>
StaleSeconds
))
Reset
();
87
age
= 0;
previous
= sample;
88
history
.push_back({sample.
seconds
,sample.
windToMs
});
89
const
double
target = sample.
seconds
-
WindowSeconds
;
90
while
(
history
.size() > 2 &&
history
[1].time <= target)
history
.pop_front();
91
headwindRate
= 0;
92
if
(
history
.size() >= 2 &&
history
.front().time <= target)
93
{
94
const
auto
& a =
history
[0];
const
auto
& b =
history
[1];
95
const
float
blend = float((target-a.time)/(b.time-a.time));
96
const
Vector3
oldWind = a.wind+(b.wind-a.wind)*blend;
97
// Difference the WORLD wind first, then project both samples
98
// along today's track. A turn in steady wind is not windshear.
99
headwindRate
= -
Dot
(sample.
windToMs
-oldWind,sample.
forward
)/float(
WindowSeconds
)*1.94384449f;
100
}
101
updraft
=
Dot
(sample.
windToMs
,sample.
up
);
102
const
float
score =
updraft
*196.850394f+750.f*
headwindRate
;
103
alert
= score < -1750.f ?
Alert::Warning
: score > 1750.f ?
Alert::Caution
:
Alert::None
;
104
return
alert
;
105
}
106
};
107
}
ClientMath.h
Caution
@ Caution
Definition
Message.h:8
Warning
@ Warning
Definition
Message.h:7
None
@ None
Definition
ServerTypes.h:97
GpwsWindshear::Detector
Definition
GpwsWindshear.h:58
GpwsWindshear::Detector::Reset
void Reset()
Definition
GpwsWindshear.h:69
GpwsWindshear::Detector::age
double age
Definition
GpwsWindshear.h:62
GpwsWindshear::Detector::Update
Alert Update(const Sample &sample, float elapsed, bool enabled)
Definition
GpwsWindshear.h:72
GpwsWindshear::Detector::WindowSeconds
static constexpr double WindowSeconds
Definition
GpwsWindshear.h:68
GpwsWindshear::Detector::previous
Sample previous
Definition
GpwsWindshear.h:61
GpwsWindshear::Detector::history
std::deque< Point > history
Definition
GpwsWindshear.h:60
GpwsWindshear::Detector::StaleSeconds
static constexpr double StaleSeconds
Definition
GpwsWindshear.h:68
GpwsWindshear::Detector::alert
Alert alert
Definition
GpwsWindshear.h:63
GpwsWindshear::Detector::HeadwindRateKnotsPerSecond
float HeadwindRateKnotsPerSecond() const
Definition
GpwsWindshear.h:70
GpwsWindshear::Detector::UpdraftMs
float UpdraftMs() const
Definition
GpwsWindshear.h:71
GpwsWindshear::Detector::headwindRate
float headwindRate
Definition
GpwsWindshear.h:64
GpwsWindshear::Detector::updraft
float updraft
Definition
GpwsWindshear.h:64
GpwsWindshear
Definition
GpwsWindshear.h:10
GpwsWindshear::Alert
Alert
Definition
GpwsWindshear.h:54
GpwsWindshear::Alert::Warning
@ Warning
Definition
GpwsWindshear.h:54
GpwsWindshear::Alert::None
@ None
Definition
GpwsWindshear.h:54
GpwsWindshear::Alert::Caution
@ Caution
Definition
GpwsWindshear.h:54
GpwsWindshear::Finite
bool Finite(const Vector3 &v)
Definition
GpwsWindshear.h:12
GpwsWindshear::Publish
void Publish(Sample &sample, float elapsed, const Vector3 &bodyWindKms, const RiseMath::Matrix &bodyToWorld, const Vector3 &groundVelocityKms, const Vector3 &position, int vehicle, bool simulator, bool available)
Definition
GpwsWindshear.h:30
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
RiseMath::Vec3TransformNormal
Vector3 * Vec3TransformNormal(Vector3 *out, const Vector3 *a, const Matrix *m)
Definition
ClientMath.h:107
GpwsWindshear::Detector::Point
Definition
GpwsWindshear.h:59
GpwsWindshear::Detector::Point::time
double time
Definition
GpwsWindshear.h:59
GpwsWindshear::Detector::Point::wind
Vector3 wind
Definition
GpwsWindshear.h:59
GpwsWindshear::Sample
Definition
GpwsWindshear.h:22
GpwsWindshear::Sample::forward
Vector3 forward
Definition
GpwsWindshear.h:24
GpwsWindshear::Sample::windToMs
Vector3 windToMs
Definition
GpwsWindshear.h:24
GpwsWindshear::Sample::seconds
double seconds
Definition
GpwsWindshear.h:25
GpwsWindshear::Sample::vehicle
int vehicle
Definition
GpwsWindshear.h:27
GpwsWindshear::Sample::up
Vector3 up
Definition
GpwsWindshear.h:24
GpwsWindshear::Sample::simulator
bool simulator
Definition
GpwsWindshear.h:28
GpwsWindshear::Sample::valid
bool valid
Definition
GpwsWindshear.h:28
GpwsWindshear::Sample::sequence
uint64_t sequence
Definition
GpwsWindshear.h:26
RiseMath::Matrix
Definition
ClientMath.h:80
RiseMath::Vector3
Definition
ClientMath.h:38
GpwsWindshear.h
Generated on
for Rise by
1.18.0