Rise
The Vieneo Province
Loading...
Searching...
No Matches
Tests/GpwsPredictiveWindshearTests.h

Source at documentation-generation time. See Test catalog for fixture associations.

1static void PredictiveWindshearRegressions()
2{
3 using namespace GpwsPredictiveWindshear;
5 using G = Bus::Gpws;
6 const auto flight = [] {
7 Input in; in.enabled = in.dataAvailable = true; in.radiusKm = radiusC;
8 in.position = {0,-(radiusC+.3f),0}; in.groundVelocityKms = {0,0,.1f};
9 in.radioKm = .3; in.generation = in.revision = 1; in.vehicle = 4; return in;
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 {
19 Detector d; State out; auto in=flight();
20 d.Update(in,.1,front,out);
21 Check(out.enabled && out.available && out.complete && !out.caution,"look-ahead confirms before announcing");
22 run(d,in,out,front);
23 Check(out.caution && out.timeSeconds>10 && out.timeSeconds<=20 && out.lossRateMs2>EnterRateMs2,
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 {
47 Detector d; State out; auto in=flight();
48 run(d,in,out,front); in.dataAvailable=false; d.Update(in,.1,front,out);
49 Check(out.enabled && !out.available && !out.caution,"grid reset immediately clears predictive alert");
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 {
94 Detector d; State out; auto in=flight();
95 double time=0;
96 while (!out.caution && time<2) { d.Update(in,dt,front,out); time+=dt; }
97 Check(out.caution && time>=ConfirmSeconds && time<=ConfirmSeconds+2*dt+1.e-6,
98 "advisory confirmation is elapsed-time based across frame rates");
99 }
100 weather source; grid terrain; Viewscreen view{&source,&terrain};
101 SPlotWeatherGrid packet{}; packet.header.requestToken=3; packet.header.revision=1;
102 packet.header.tcp={1019,1019};
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 = [&] {
109 ++packet.header.revision;
110 Check(source.store.Accept(reinterpret_cast<const unsigned char*>(&packet),sizeof packet,3)==PlotWeather::Result::Full,
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 {
127 PlotWeather::Store copy; bearings.header.cube=uint8_t(face); bearings.header.tcp={centers[face],1019};
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 }
134 for (bool autopilot : {false,true}) for (auto reference : {REF_APNMODE,REF_ACLMODE})
135 {
136 Fixture f; Gpws gpws(f.bus.get(),&f.logger,&view);
138 playerships[0].reference=reference; playerships[0].position={0,-(radiusC+.3f),0}; playerships[0].mslKm=.3f;
139 playerships[0].barycentric={.4f,0,0}; playerships[0].velocity={.4f,0,.1f};
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");
146 Check(std::find(played.begin(),played.end(),SOUND_GPWSWINDSHEARCAUTION)!=played.end(),
147 "predictive caution reaches existing VMU recording");
148 GpwsWindshear::Sample actual; actual.valid=true; actual.vehicle=playerships[0].vehicleId;
149 actual.seconds=1; actual.sequence=1; actual.up={0,-1,0}; actual.forward={0,0,1}; actual.windToMs={0,10,0};
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); // ensure the predictive phrase is playing
154 playerships[0].isSimulator=true; step(1);
155 Check(!f.bus->GPWS.predictiveWindshear.enabled && f.bus->GPWS.Alert!=G::Predictive_Windshear_Caution,
156 "simulator entry clears the ground-grid predictor");
157 playerships[0].isSimulator=false; source.pending=true; step();
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");
162 playerships[0].reference=reference; step();
163 ourcockpit.weatherRadarPower=false; step(1);
164 Check(!f.bus->GPWS.predictiveWindshear.enabled,"weather radar power controls predictive acquisition");
165 ourcockpit.weatherRadarPower=true; step(); f.bus->GPWS.inhibited=true; step(1);
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");
169 f.bus->GPWS.positionValid=true; step(); ourcockpit.power=0; step(1);
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);
175 playerships[0].position={0,-(radiusC+.3f),0}; playerships[0].mslKm=.3f;
176 playerships[0].velocity={0,0,.1f}; f.bus->RadioAltitudeKm=.3f; f.bus->vmuHold=100;
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);
186 Check(played.back()==SOUND_GPWSWINDSHEARCAUTION,"fresh encounter plays predictive caution");
187 playerships[0].isSimulator=true; f.vmu.FrameMove(.1f);
188 Check(!stopped.empty() && stopped.back()==SOUND_GPWSWINDSHEARCAUTION,
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}
@ REF_ACLMODE
Definition ServerTypes.h:44
@ REF_APNMODE
Definition ServerTypes.h:42
@ REF_ONGROUND
Definition ServerTypes.h:43
@ SOUND_GPWSWINDSHEARCAUTION
Definition Sound.h:67
Definition Module.h:43
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
Definition grid.h:14
void FrameMove(float fElapsedTime)
Definition weather.cpp:32
s_network_objects playerships[MAX_SCAN]
Definition globals.cpp:112
Scockpit ourcockpit
Definition globals.cpp:114
#define radiusC
Definition globals.h:87
Sample SampleGrid(const PlotWeather::Store &source, Vector3 position, Elevation elevation)
std::string name
Definition Command.h:11
SRenderWeather samples[64][64]
SPlotWeatherHeader header
unsigned char precipitation
float power
Definition globals.h:599
bool weatherRadarEquipped
Definition globals.h:669
bool weatherRadarPower
Definition globals.h:597
RiseMath::Vector3 barycentric
Definition globals.h:500
RiseMath::Vector3 position
Definition globals.h:511
unsigned short vehicleId
Definition globals.h:537
RiseMath::Vector3 velocity
Definition globals.h:500