1static void PredictiveWindshearRegressions()
2{
6 const auto flight = [] {
10 };
11 const auto front = [](Vector3 p) {
12 const float tailwind = -20.f+40.f*(std::clamp)((p.z-1.f)/1.f,0.f,1.f);
13 return Sample{{0,0,tailwind},0,
true};
14 };
15 const auto run = [&](
Detector& d,
const Input& in,
State& out,
auto sampler,
int n = 12) {
16 for (
int i=0;i<n;++i) d.
Update(in,.1,sampler,out);
17 };
18 {
22 run(d,in,out,front);
24 "ground wind headwind loss is found ahead before ownship enters it");
25 in.groundVelocityKms={0,0,-.1f}; run(d,in,out,front);
26 Check(!out.
caution,
"hazard behind the aircraft is not ahead");
27 in=flight(); run(d,in,out,[](Vector3 p) {
return Sample{{p.z*40,0,0},0,
true}; });
28 Check(!out.
caution,
"pure crosswind gradient is not a longitudinal loss");
29 run(d,in,out,[](Vector3 p) {
return Sample{{0,0,-p.z*40},0,
true}; });
30 Check(!out.
caution,
"headwind gain does not masquerade as adverse shear");
31 run(d,in,out,[](Vector3 p) {
return Sample{{0,0,p.z*1.5f},0,
true}; });
32 Check(!out.
caution,
"small grid quantization differences do not alert");
33 for (float yaw : {0.f,.8f,2.f,3.f}) {
34 in.groundVelocityKms={.1f*std::sin(yaw),0,.1f*std::cos(yaw)};
35 run(d,in,out,[](Vector3) {
return Sample{{10,0,20},0,
true}; });
36 Check(!out.
caution,
"turning in spatially uniform world wind does not create shear");
37 }
38 in=flight(); run(d,in,out,front);
39 run(d,in,out,[](Vector3 p) {
return Sample{{0,0,p.z*10},0,
true}; });
40 Check(out.
caution,
"marginal recovery retains an active advisory through hysteresis");
41 run(d,in,out,[](Vector3 p) {
return Sample{{0,0,p.z*8},0,
true}; });
42 Check(!out.
caution,
"sufficient recovery clears the advisory");
43 run(d,in,out,[](Vector3 p) {
return Sample{{0,0,p.z*10},0,
true}; });
44 Check(!out.
caution,
"a cleared advisory requires the full entry threshold to rearm");
45 }
46 {
48 run(d,in,out,front); in.dataAvailable=
false; d.
Update(in,.1,front,out);
50 in.dataAvailable=true; run(d,in,out,front);
51 in.enabled=
false; d.
Update(in,361,front,out);
52 in.enabled=true; run(d,in,out,front);
53 Check(!out.
available && !out.
caution,
"disarming and rearming cannot rejuvenate an old weather revision");
54 ++in.revision; run(d,in,out,front);
55 Check(out.
caution,
"fresh weather revision rearms after source expiry");
56 ++in.revision; d.
Update(in,.1,front,out);
57 Check(out.
caution,
"routine grid revision does not flicker a continuing spatial threat");
58 ++in.revision; d.
Update(in,.1,[](Vector3) {
return Sample{{0,0,90},0,
true}; },out);
59 Check(!out.
caution,
"uniform wind change between revisions is not spatial windshear");
60 run(d,in,out,front);
61 ++in.generation; d.
Update(in,.1,front,out);
62 Check(!out.
caution,
"new request generation discards the old encounter confirmation");
63 run(d,in,out,front); ++in.vehicle; d.
Update(in,.1,front,out);
64 Check(!out.
caution,
"vehicle switch rearms from a fresh encounter");
65 run(d,in,out,front); in.position.x+=5; d.
Update(in,.1,front,out);
66 Check(!out.
caution,
"reposition does not carry over the old caution");
67 in=flight(); in.generation=9;
68 run(d,in,out,[&](Vector3 p) {
return p.z>.5f && p.z<.9f ?
Sample{} : front(p); });
69 Check(!out.
complete && !out.
caution,
"missing grid strip cannot be skipped to predict a later encounter");
70 run(d,in,out,[&](Vector3 p) {
return p.z>2.5f ?
Sample{} : front(p); });
71 Check(out.
caution && !out.
complete,
"known hazard remains useful with limited coverage farther ahead");
72 in.groundVelocityKms={0,0,2}; run(d,in,out,front);
73 Check(out.
caution && !out.
complete,
"fast near-ground flight retains protection with a bounded range");
74 in.groundVelocityKms={0,0,0}; run(d,in,out,front);
75 Check(!out.
enabled && !out.
caution,
"hover invents no forward travel; reactive detector remains separate");
76 in=flight(); in.position.y=-
radiusC-100; in.radioKm=100; run(d,in,out,front);
77 Check(!out.
enabled && !out.
caution,
"suborbital coast and orbit cannot sample a surface threat as flight-level wind");
78 in=flight(); d.
Update(in,.1,front,out);
79 Check(!out.
caution,
"reentry begins a fresh confirmation");
80 run(d,in,out,front); Check(out.
caution,
"near-ground return rearms predictive caution");
81 in.groundVelocityKms.y=-.1f; run(d,in,out,front);
82 Check(!out.
caution && !out.
complete,
"high-speed ascent stops the path when it leaves the surface layer");
83 in.groundVelocityKms.y=.1f; run(d,in,out,front);
84 Check(!out.
caution && !out.
complete,
"fast descent does not predict through the terrain");
85 in=flight(); in.maxFrameSeconds=.6; run(d,in,out,front);
86 Check(!out.
caution && !out.
available,
"actual frame pause clears pending predictions");
87 in.maxFrameSeconds=.1; d.
Update(in,1.4,front,out); d.
Update(in,1.4,front,out);
88 Check(out.
caution,
"long scheduled turns with ordinary frames still confirm");
89 in.position.x=std::numeric_limits<float>::quiet_NaN(); run(d,in,out,front);
90 Check(!out.
caution && !out.
enabled,
"invalid position clears the predictive display");
91 }
92 for (double dt : {1./144,1./60,1./30,.2})
93 {
95 double time=0;
96 while (!out.
caution && time<2) { d.
Update(in,dt,front,out); time+=dt; }
98 "advisory confirmation is elapsed-time based across frame rates");
99 }
103 for (int q=0;q<64;++q) for (int r=0;r<64;++r)
104 {
105 auto& cell=packet.
samples[q][r]; cell.
precipitation=20; cell.ceiling=1000; cell.visibility=42160;
106 cell.windSpeedMs=20; cell.windDirectionRadians=r<=31 ? 79 : 0;
107 }
108 const auto publish = [&] {
111 "production source consumes the ground-wind packet");
112 };
113 publish();
114 const auto elevation=[](unsigned,double,double,float& value) { value=0; return true; };
115 auto sample=
SampleGrid(source.store,{0,-radiusC,0},elevation);
116 Check(sample.valid && sample.windToMs.z<-19.9f && std::fabs(sample.windToMs.y)<.001f,
117 "encoded ground bearing is converted to the propulsion velocity-TO convention");
118 sample=
SampleGrid(source.store,{0,-radiusC,0},[](
unsigned,
double,
double,
float&) { return false; });
119 Check(!sample.valid,"independent missing terrain invalidates a weather-grid sample");
120 {
121 auto bearings=packet;
122 for (auto& column:bearings.samples) for (auto& cell:column) cell.windDirectionRadians=0;
123 const Vector3 positions[]={{0,-
radiusC,0},{
radiusC,0,0},{-
radiusC,0,0},{0,
radiusC,0}};
124 const short centers[]={1019,3057,-1019,5095};
125 for (int face=0;face<4;++face)
126 {
128 copy.
Accept(
reinterpret_cast<const unsigned char*
>(&bearings),
sizeof bearings,3);
129 const auto north=
SampleGrid(copy,positions[face],elevation);
130 Check(north.valid && north.windToMs.z>19.99f && std::fabs(north.windToMs.x)<.001f && std::fabs(north.windToMs.y)<.001f,
131 "ground north bearing agrees across equatorial cube faces");
132 }
133 }
135 {
136 Fixture f;
Gpws gpws(f.bus.get(),&f.logger,&view);
140 f.bus->RadioAltitudeKm=.3f; f.bus->IndicatedAirspeedKms=0; f.bus->AFCS.AutopilotEngaged=autopilot;
141 const auto step=[&](int n=12) { for(int i=0;i<n;++i) { gpws.FrameMove(.1f); f.vmu.FrameMove(.1f); } };
142 step();
143 Check(f.bus->GPWS.Alert==G::Predictive_Windshear_Caution && f.bus->GPWS.cautionLamp && !f.bus->GPWS.warningLamp &&
144 std::wstring(f.bus->GPWS.AlertText())==L"WINDSHEAR AHEAD",
145 "production GPWS selects distinct amber look-ahead in manual/Autoflyte APN/ACL with zero IAS");
147 "predictive caution reaches existing VMU recording");
150 f.bus->WindshearWind=actual; step(1);
151 Check(f.bus->GPWS.Alert==G::Mode7_Windshear_Warning,"encountered windshear outranks predictive advisory");
152 f.bus->WindshearWind.valid=false; step();
153 f.bus->vmuHold=0; step(45);
155 Check(!f.bus->GPWS.predictiveWindshear.enabled && f.bus->GPWS.Alert!=G::Predictive_Windshear_Caution,
156 "simulator entry clears the ground-grid predictor");
158 Check(!f.bus->GPWS.predictiveWindshear.caution,"simulator exit cannot replay the old grid while reset is pending");
159 source.pending=false; step();
161 Check(!f.bus->GPWS.predictiveWindshear.caution,"touchdown clears prediction");
164 Check(!f.bus->GPWS.predictiveWindshear.enabled,"weather radar power controls predictive acquisition");
166 Check(!f.bus->GPWS.predictiveWindshear.enabled,"GPWS inhibit clears predictive state");
167 f.bus->GPWS.inhibited=false; step(); f.bus->GPWS.positionValid=false; step(1);
168 Check(!f.bus->GPWS.predictiveWindshear.caution,"position validity failure clears prediction");
170 Check(!f.bus->GPWS.predictiveWindshear.caution,"aircraft power loss clears prediction");
171 }
172 {
173 Fixture f;
Gpws gpws(f.bus.get(),&f.logger,&view);
177 for(int i=0;i<12;++i) gpws.FrameMove(.1f);
178 Check(std::any_of(f.bus->commandStream.begin(),f.bus->commandStream.end(),[](
const Command& c) {
179 return c.sValue=="GPWSPredictiveWind";
180 }),"busy VMU queues predictive caution with its own lifecycle tag");
181 source.pending=
true; gpws.
FrameMove(.1f); f.bus->vmuHold=0; f.vmu.FrameMove(.1f);
182 Check(played.empty(),"withdrawn grid cannot play a stale queued caution");
183 source.pending=false;
184 for(
int i=0;i<55;++i) gpws.
FrameMove(.1f);
185 f.bus->vmuHold=0; f.vmu.FrameMove(.1f);
189 "VMU independently stops a playing predictive phrase on simulator entry before GPWS runs");
190 Command injected; injected.
name=
"GPWSPredictiveWindshear"; f.bus->commandStream.push_back(injected);
191 const auto count=played.size(); f.vmu.FrameMove(.1f);
192 Check(played.size()==count && f.bus->commandStream.empty(),"direct predictive command cannot bypass simulator exclusion");
193 }
194}
@ SOUND_GPWSWINDSHEARCAUTION
void Update(const Input &in, double elapsed, Sampler sample, State &out)
Result Accept(const unsigned char *p, size_t length, uint16_t expectedToken)
SPlotWeatherHeader header
void FrameMove(float fElapsedTime)
s_network_objects playerships[MAX_SCAN]
Sample SampleGrid(const PlotWeather::Store &source, Vector3 position, Elevation elevation)
constexpr double ConfirmSeconds
constexpr double EnterRateMs2
SRenderWeather samples[64][64]
SPlotWeatherHeader header
unsigned char precipitation
bool weatherRadarEquipped
RiseMath::Vector3 barycentric
RiseMath::Vector3 position
RiseMath::Vector3 velocity