1
2static void WindshearRegressions()
3{
6 const auto sampleAt = [](double time, float tailwind, float vertical = 0.f) {
10 };
12 {
14 Publish(s,.1f,
Vector3(.02f,0,0),identity,
Vector3(0,0,.1f),
Vector3(0,3000,0),0,
false,
true);
17 "horizontal wind is not an updraft");
18 Publish(s,.1f,
Vector3(0,.02f,0),identity,
Vector3(0,0,.1f),
Vector3(3000,0,0),0,
false,
true);
20 Check(std::fabs(d.
UpdraftMs())<1.e-5f,
"global Y is horizontal at another planetary location");
21 Publish(s,.1f,
Vector3(-.01f,0,0),identity,
Vector3(0,0,.1f),
Vector3(3000,0,0),0,
false,
true);
23 "negative local radial wind produces a downdraft warning away from world Y");
24
27 Vector3 windWorld(0,-.01f,-.02f), body;
29 Publish(s,.1f,body,rotation,
Vector3(0,0,.1f),
Vector3(0,3000,0),0,
false,
true);
30 Check(std::fabs(s.
windToMs.y+10)<1.e-4f && std::fabs(s.
windToMs.z+20)<1.e-4f,
31 "body attitude does not rotate measured gusts away from their world direction");
32 Publish(s,.1f,
Vector3(0,-.01f,0),identity,
Vector3{},
Vector3(0,3000,0),0,
false,
true);
35 Check(!s.
valid,
"unknown planetary position invalidates wind sample");
36 }
37
38
39 for (float yaw : {0.f,.6f,-1.4f})
40 {
43 Publish(s,1.f,
Vector3(0,0,.01f),attitude,
Vector3{},
Vector3(0,3000,0),0,
false,
true);
45 Publish(s,1.f,
Vector3(0,0,-.01f),attitude,
Vector3{},
Vector3(0,3000,0),0,
false,
true);
47 "hover headwind to tailwind reversal follows the physical minus-Z nose at every heading");
49 "hover headwind loss has the same signed rate as moving-flight headwind loss");
50 Publish(s,1.f,
Vector3(0,0,.01f),attitude,
Vector3{},
Vector3(0,3000,0),0,
false,
true);
52 "hover tailwind to headwind recovery cautions instead of reversing severity");
53 }
54 for (float sign : {-1.f,1.f})
55 {
57 d.
Update(sampleAt(0,-sign*10),.1f,
true);
58 const auto s=sampleAt(1,sign*10);
60 "equal-magnitude headwind/tailwind reversal has the correct severity");
62 "derivative uses sample timestamps rather than the frame interval");
64 "unchanged bus sample holds its result without injecting a false zero derivative");
66 "stale input expires and the same stale sample cannot rearm");
68 "recovered sensor primes a new history without a false shear spike");
69 }
70 {
72 for (int i=0;i<=120;++i) {
74 Check(d.
Update(s,1.f/30,
true)==
Alert::None,
"steady wind during a turn is not windshear");
75 }
76 auto s=sampleAt(5,10); s.
windToMs.x=40;
77 Check(d.
Update(s,.1f,
true)==
Alert::None,
"a pure crosswind change is not longitudinal shear");
78 s=sampleAt(6,10,-10);
80 s=sampleAt(7,10,10);
84 }
85
86
87 for (int sensorHz : {1,5,20,60}) for (int fps : {15,30,60,144,240})
88 {
90 float worstRateError=0;
91 bool warning=false,caution=false,clear=false,statesMatch=true;
92 for (int frame=0;frame<=fps*9;++frame)
93 {
94 const double t=double(frame)/fps;
95 while (double(sensor)/sensorHz<=t+1.e-9) {
96 const double st=double(sensor++)/sensorHz;
97 const float tailwind=st<2?-10.f:st<4?float(-10+10*(st-2)):st<6?10.f:st<8?float(10-10*(st-6)):-10.f;
98 sample=sampleAt(st,tailwind);
99 }
100 const auto alert=d.
Update(sample,1.f/fps,
true);
101 if (t>=3.25 && t<=3.75) {
105 }
108 }
109 Check(warning&&caution&&clear&&statesMatch&&worstRateError<.001f,
110 "15/30/60/144/240 FPS and 1/5/20/60 Hz sensing produce the same shear rate and encounter states");
111 std::cout << "Windshear replay: " << fps << " FPS / " << sensorHz << " Hz sensor; max rate error " << worstRateError << " kt/s\n";
112 }
113 {
115 const float steps[] = {1.f/144,1.f/30,.1f,1.f/60,1.f/15};
116 bool stable=true; float error=0;
117 for (int i=0;i<300;++i) {
118 const float dt=steps[i%5];
const float wind=float(s.
seconds+dt)*.005f;
119 Publish(s,dt,
Vector3(0,0,wind),identity,
Vector3(0,0,.1f),
Vector3(0,3000,0),0,
false,
true);
120 const auto a=d.
Update(s,dt,
true);
124 }
125 }
126 Check(stable&&error<.001f,"production timestamp publisher is stable with alternating 7-100 ms frame times");
127 std::cout << "Windshear jitter replay: max rate error " << error << " kt/s\n";
128 Publish(s,0,
Vector3{},identity,
Vector3{},
Vector3(0,3000,0),0,
false,
true);
129 Check(!s.
valid && d.
Update(s,.1f,
true)==
Alert::None,
"flight freeze invalidates the sample and clears shear");
130 }
131 for (int transition=0;transition<5;++transition)
132 {
135 auto s=sampleAt(2,-10);
136 if (transition==0) ++s.
vehicle;
138 if (transition==2) s.
seconds=.2;
139 if (transition==3) s.
seconds=5;
140 if (transition==4) d.
Update(sampleAt(1.5,10),.1f,
false);
141 Check(d.
Update(s,.1f,
true)==
Alert::None,
"vehicle, simulator, clock, sample-gap and disarm transitions discard history");
142 }
144 "reactive windshear height band is 10 through 1500 feet AGL");
145
147 {
151 for(int i=0;i<55;++i) {
152 f.bus->WindshearWind=sampleAt(i*.1,0,-10);
153 f.Step(.1f);
154 }
155 Check(f.bus->GPWS.Alert==G::Mode7_Windshear_Warning && f.bus->GPWS.warningLamp,
156 "manual/Autoflyte and APN/ACL hover use the same operational windshear warning");
158 "windshear goes through existing bus/VMU without restarting active speech");
159 f.bus->RadioAltitudeKm=900; f.Step(.1f);
160 Check(f.bus->GPWS.Alert!=G::Mode7_Windshear_Warning,"orbit has no reactive low-altitude windshear alert");
161 f.bus->RadioAltitudeKm=.3f; f.bus->WindshearWind=sampleAt(6,0); f.Step(.1f);
162 Check(f.bus->GPWS.Alert!=G::Mode7_Windshear_Warning,"reentry re-arms without replaying the old event");
163 f.bus->WindshearWind=sampleAt(7,0,-10); f.Step(.1f);
164 Check(f.bus->GPWS.Alert==G::Mode7_Windshear_Warning,"new near-ground encounter after reentry is detected");
165 f.bus->Mach=12; f.bus->TrueAirspeedKms=4; f.bus->IndicatedAirspeedKms=0;
166 f.bus->WindshearWind=sampleAt(7.1,0,-10); f.Step(.1f);
167 Check(f.bus->GPWS.Alert==G::Mode7_Windshear_Warning,"high-speed near-ground flight does not inherit the bank spaceflight exclusion");
169 Check(f.bus->GPWS.Alert!=G::Mode7_Windshear_Warning && f.bus->commandStream.empty(),
170 "touchdown clears windshear alert and queued speech");
172 Check(f.bus->GPWS.Alert!=G::Mode7_Windshear_Warning,"explicit hazard inhibit disarms windshear");
174 Check(f.bus->GPWS.Alert==G::NoAlert,"power loss clears windshear indication");
176 }
177 {
179 f.bus->vmuHold=10;
180 f.bus->WindshearWind=sampleAt(1,0,-10); f.gpws.FrameMove(4.1f);
181 Check(std::any_of(f.bus->commandStream.begin(),f.bus->commandStream.end(),[](
const Command& c){
182 return c.name=="GPWSMode7WindshearWarning";}),"busy VMU leaves windshear queued normally");
183 f.bus->WindshearWind=sampleAt(1.1,0); f.gpws.FrameMove(.1f);
184 f.bus->vmuHold=0; f.vmu.FrameMove(.1f);
185 Check(played.empty()&&f.bus->commandStream.empty(),"recovered windshear cannot play stale queued warning");
186 }
187}
@ SOUND_GPWSWINDSHEARWARNING
Alert Update(const Sample &sample, float elapsed, bool enabled)
float HeadwindRateKnotsPerSecond() const
s_network_objects playerships[MAX_SCAN]
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)
bool HeightAllowed(float radioKm)
Vector3 * Vec3TransformNormal(Vector3 *out, const Vector3 *a, const Matrix *m)
Matrix * MatrixRotationY(Matrix *out, float value)
Matrix * MatrixInverse(Matrix *out, float *determinant, const Matrix *a)
Matrix * MatrixIdentity(Matrix *out)
Matrix * MatrixRotationZ(Matrix *out, float value)