1
2static void BenchmarkWeatherRadarAutoTilt()
3{
6 for(
auto& col:packet.
samples)
for(
auto& cell:col)
7 {cell.precipitation=100;cell.ceiling=1500;cell.visibility=42000;}
10 "benchmark must use the real terrain/weather decoder");
11 Scanner scanner;Display display;
auto in=Flight();
int calls=0;
12 const auto begin=std::chrono::steady_clock::now();
13 for(int i=0;i<240;++i) scanner.Update(in,TraverseSeconds/(Bearings-1),[&](Point p) {
14 ++calls;
15 return SampleGrid(source,p,10,[](unsigned,double,double,float& meters,float& water) {
16 meters=0;water=0;return true;
17 });
18 },display);
19 const double ms=std::chrono::duration<double,std::milli>(std::chrono::steady_clock::now()-begin).count();
20 Check(display.available && !display.limited && !display.attenuated,"benchmark must produce usable weather");
21 Check(calls<=241*Gates*18,"two elevation looks have a bounded sampler budget");
22 std::cout<<"240 bearing updates / 8 simulated seconds: "<<ms<<" ms wall time; "
23 <<ms/240<<" ms/update; "<<calls<<" production samples\n";
24}
25static void CheckWeatherRadarAutoTilt()
26{
27 Scanner scanner; Display display;
auto in=Flight();
28 auto flat=[](Point) {
return Sample{
true,2,0,10}; };
29 for(double height:{0.,.005,.1,.3,1.,7.2}) for(double range:{10.,40.,64.})
30 {
31 in=Flight();in.position.y=-in.radiusKm-height;in.rangeKm=range;
32 scanner.Reset();
Advance(scanner,in,display,4.1,flat);
33 Check(display.available && !display.attenuated && !display.limited && display.tiltValid,
34 "parked hover approach and cruise retain valid automatic scanning");
35 bool clutter=
false,
weather=
false;
36 for(const auto& beam:scanner.Beams())
37 {
38 clutter|=std::any_of(beam.groundEchoes.begin(),beam.groundEchoes.end(),IsReturn);
39 weather|=std::any_of(beam.echoes.begin(),beam.echoes.end(),IsReturn);
40 }
41 Check(!
weather,
"dry land never becomes a colored storm after automatic clutter rejection");
42 if(height<=.3) Check(clutter,"low-altitude test actually illuminates terrain before rejecting it");
43 const double start=range*.4,end=range*.6;
44 auto storm=[&](Point p) {
45 const auto delta=p-in.position;
46 const double d=std::hypot(
Dot(delta,in.forward),
Dot(delta,in.right));
47 return Sample{
true,d>start && d<end ? 12. : 2.,0,10};
48 };
49 Advance(scanner,in,display,8.1,storm);
50 Check(scanner.Beams()[60].echoes[Gates/2]==Echo::Red && !display.attenuated,
51 "weather ahead survives clutter rejection before entry at every approach height and range");
52 }
53
54
55
56 in=Flight();in.position.y=-in.radiusKm-4;in.rangeKm=40;
57 auto shallow=[&](Point p) {
58 const auto delta=p-in.position;
59 const double d=std::hypot(
Dot(delta,in.forward),
Dot(delta,in.right));
60 return Sample{
true,d>28 && d<32 ? 12. : 2.,0,1};
61 };
62 scanner.Reset();
Advance(scanner,in,display,4.1,shallow);
63 Check(display.tiltValid && display.tiltDegrees<0 &&
64 scanner.Beams()[60].echoes[96]==Echo::Red,
65 "downward automatic look detects a shallow cell missed by a horizontal beam");
66
67
68
69 in=Flight();in.position.y=-in.radiusKm-.005;in.rangeKm=40;
70 auto valley=[&](Point p) {
71 const auto delta=p-in.position;
72 const double d=std::hypot(
Dot(delta,in.forward),
Dot(delta,in.right));
73 return Sample{
true,(d>3 && d<5) || (d>24 && d<28) ? 12. : 2.,
74 d>8 && d<12 ? 6. : 0.,.2};
75 };
76 scanner.Reset();
Advance(scanner,in,display,4.1,valley);
77 Check(display.tiltDegrees==MaxTiltDegrees && scanner.Beams()[60].echoes[12]==Echo::Red,
78 "level guard look retains close shallow weather when terrain raises automatic tilt");
79 Check(scanner.Beams()[60].echoes[80]==Echo::TerrainShadow && !display.attenuated,
80 "clutter rejection cannot reveal a low storm through a high ridge or call terrain weather attenuation");
81
82
83
84 in=Flight();in.position.y=-in.radiusKm-5.005;in.rangeKm=10;
85 scanner.Reset();
Advance(scanner,in,display,4.1,[](Point){
return Sample{
true,2,5,10};});
86 Check(display.tiltDegrees>2 && display.tiltDegrees<3 &&
87 std::none_of(scanner.Beams()[60].echoes.begin(),scanner.Beams()[60].echoes.end(),IsReturn),
88 "high-elevation airfield gets a ground-appropriate tilt without false rain");
89
90
91
92 for(double height:{1.,.3,.1,.005,0.,.005,.1,.3,1.})
93 {
94 in.position.y=-in.radiusKm-height;
95 Advance(scanner,in,display,8.1,flat);
96 Check(display.tiltValid && !display.attenuated && !display.limited &&
97 std::none_of(scanner.Beams()[60].echoes.begin(),scanner.Beams()[60].echoes.end(),IsReturn),
98 "descent touchdown liftoff and climb refresh tilt and remove old colored weather");
99 }
100 auto gap=[](Point){
return Sample{};};
101 Advance(scanner,in,display,8.1,gap);
102 Check(!display.tiltValid && !display.available &&
TiltText(display)==L
"AUTO --",
103 "missing terrain cannot invent a tilt command or a clear weather picture");
104 Advance(scanner,in,display,8.1,flat);
105 Check(display.tiltValid && display.available,"fresh data restores automatic tilt after missing input");
106 in.rangeKm=64;scanner.Update(in,0,flat,display);
107 Check(
Count(scanner)==1 && display.tiltValid,
"range change immediately reacquires tilt and discards old history");
108 in.power=false;scanner.Update(in,.1,flat,display);
109 Check(!display.tiltValid &&
TiltText(display)==L
"AUTO --",
"power loss clears commanded tilt");
110 in.power=true;in.simulator=true;scanner.Update(in,.1,flat,display);
111 Check(!display.tiltValid && !display.enabled,"simulator cannot retain a real-flight tilt");
112 in.simulator=false;scanner.Update(in,0,flat,display);
113 Check(display.tiltValid &&
Count(scanner)==1,
"simulator exit starts fresh automatic acquisition");
114 in.aboveWeatherCoverage=true;in.dataAvailable=false;scanner.Update(in,0,flat,display);
115 Check(display.tiltValid && display.tiltDegrees==0 && display.echoes.empty() &&
SweepVisible(display) &&
116 TiltText(display)==L
"AUTO +0.0\x00b0",
117 "normal high-altitude empty sweep commands level without a stale angle or invalid-tilt indication");
118
119 Display label;label.available=label.tiltValid=true;
120 label.tiltDegrees=2.75;Check(
TiltText(label)==L
"AUTO +2.8\x00b0",
"positive tilt readout includes sign and degrees");
121 label.tiltDegrees=-12.25;Check(
TiltText(label).find(L
"AUTO -12.")==0,
"down tilt readout retains negative sign");
122 label.tiltDegrees=-.001;Check(
TiltText(label)==L
"AUTO +0.0\x00b0",
"rounded zero has no misleading negative sign");
123 label.tiltDegrees=std::numeric_limits<double>::quiet_NaN();
124 Check(
TiltText(label)==L
"AUTO --",
"invalid angle is never printed as a commanded tilt");
125}
Result Accept(const unsigned char *p, size_t length, uint16_t expectedToken)
Step Advance(float previous, float target, float baseline, float maximum, float dt, bool dead, float wakeFactor)
float Dot(const Vector3 &a, const Vector3 &b)
SRenderWeather Sample(const unsigned char *p)
bool SweepVisible(const Display &display)
std::wstring TiltText(const Display &display)
SRenderWeather samples[64][64]
SPlotWeatherHeader header