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

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

1#pragma once
2#include "../Modules/OrbitApproach.h"
3
4// VMCI RWY 36 / WOOKE are public navigation records. Positions below are
5// independent of ArrivalPlanning::Course: do not recreate the old tautology
6// of building a runway and then checking it with the same wrong convention.
7Input VmciApproachFixture()
8{
9 auto in=BillEntryFixture();in.radius=2939.60009765625;
10 in.target.r={1114.8568115234375,-2725.94921875,50.827316284179688};
11 in.arrivalSite.runway=in.arrivalSite.ils=in.arrivalSite.faf=true;
12 in.arrivalSite.threshold=in.target.r;in.arrivalSite.heading=0;
13 in.arrivalSite.fix={1114.6919,-2725.546,72.217606};in.arrivalSite.runwayTarget=78;
14 in.targetId=78;in.vehicle=434;
15 return in;
16}
17struct ApproachAfcs {
18 enum Vertical {VerticalMode_Off,Pitch,FlightPathAngle,AltitudeMsl,Glideslope};
19 enum Lateral {LateralMode_Off,Heading,Navigation,Localizer};
20 bool DorOn=false,TvmOn=false,AutopilotEngaged=true,AutothrottleEngaged=true;
21 float DesiredAltitudeKm=30,DesiredTasKms=.5f,DesiredFpaRadians=0,DesiredCourseRadians=0;
22 float DesiredHeadingRadians=0,DesiredRadians=0;
23 Vertical CurrentVerticalMode=AltitudeMsl,StandbyVerticalMode=VerticalMode_Off;
24 Lateral CurrentLateralMode=Navigation,StandbyLateralMode=LateralMode_Off;
25};
26void ApproachGeometryTests()
27{
28 auto in=VmciApproachFixture();Request r;r.final=Final::Ils;
29 const auto a=ArrivalPlanning::Preview(in,r);
30 Check(a.valid&&std::abs(a.distanceKm-21.35148)<.001,"VMCI ILS resolves WOOKE at 21.35km rather than 10km fallback");
31 Check(std::abs(a.altitudeKm-7.060347)<.001,"VMCI descending intercept is 7.060km MSL inside the receiver capture band");
32 Check(a.gate.z>in.target.r.z,"RWY 36 intercept lies on the WOOKE side of VMCI in recorded coordinates");
33 Check(ArrivalPlanning::AircraftCourse(in.target.r,0).z<-.99,"RWY 36 aircraft compass course decreases recorded Z");
34 for(double heading:{0.0,90.0,180.0,270.0,360.0}) {
35 const Vec direction=ArrivalPlanning::AircraftCourse({3000,0,0},heading*Pi/180);
36 const Vec expected=heading==0||heading==360?Vec{0,0,-1}:heading==90?Vec{0,1,0}:
37 heading==180?Vec{0,0,1}:Vec{0,-1,0};
38 Check(Norm(direction-expected)<1e-12,"aircraft runway compass cardinal directions match client axes");
39 Check(std::abs(std::remainder(ArrivalPlanning::AircraftHeading({3000,0,0},expected)-heading*Pi/180,Tau))<1e-12,
40 "AFCS course conversion uses aircraft rather than orbital convention");
41 }
42 // Actual DOR-1 sample at 865.894s: indicated heading 185.5807, not 354.
43 const Vec pos{1122.7332993234404,-2745.3844681673331,-145.62345432445045};
44 const Vec nose{-.082491509616374969,-.055125966668128967,.99506598711013794};
45 Check(std::abs(ArrivalPlanning::AircraftHeading(pos,nose)*180/Pi-185.580734)<.1,
46 "recorded heading regression detects the reciprocal-runway conversion");
47 struct W {int type,heading,pairedWithColonyId,ils;bool powered;double length;Vec location;};
48 std::vector<W> points{{2,360,244,127,true,2.6747649,in.target.r},{1,0,244,0,true,0,in.arrivalSite.fix}};
49 const auto site=ArrivalPlanning::Site(points,0),fromMarker=ArrivalPlanning::Site(points,1);
50 Check(site.faf&&fromMarker.runway&&site.runwayTarget==0&&fromMarker.runwayTarget==0,
51 "both explicit runway and WOOKE resolve the same inbound 360/0 approach");
52 points.push_back(points[1]);
53 Check(!ArrivalPlanning::Site(points,0).faf,"duplicate marker data cannot pick an arbitrary LOM");
54 points.pop_back();points[1].heading=180;
55 Check(!ArrivalPlanning::Site(points,0).faf&&!ArrivalPlanning::Site(points,1).runway,"opposite runway marker never associates");
56 for(double distance:{6.0,10.0,21.35148,30.0}) {
57 in.arrivalSite.faf=false;r.finalDistanceKm=distance;
58 const auto gate=ArrivalPlanning::Preview(in,r);
59 const Vec beam=Unit(gate.gate)*(in.radius+gate.altitudeKm+.015);
60 const double deviation=std::asin((Norm(beam)-Norm(in.target.r))/Norm(beam-in.target.r))-3*Pi/180;
61 Check(std::abs(deviation)<1e-9,"ILS preview matches actual slant-DME receiver at near and distant markers");
62 }
63}
64void FlyApproach(double dt,double lag,double wind,bool markerTarget=false)
65{
66 auto in=VmciApproachFixture();Request r;r.final=Final::Ils;
67 if(markerTarget) {in.targetId=79;in.target.r=in.arrivalSite.fix;}
68 const auto gate=ArrivalPlanning::Preview(in,r);
69 Vec radial=Rotate(Unit(in.arrivalSite.threshold),gate.normal,-205/in.radius);
70 const auto descent=Descent::Geometry(in,r,gate);
71 double altitude=30,tas=.5,gamma=-Descent::Steep,distance=descent.range;
72 radial=Rotate(Unit(in.arrivalSite.threshold),gate.normal,-distance/in.radius);
73 ApproachAfcs a;Approach::Controller controller;Guidance g;g.entryHandoff=true;
74 Approach::Sensors s;s.dt=dt;s.stall=.045;s.vref=.0585;
75 auto sense=[&] {
76 in.own.r=radial*(in.radius+altitude);
77 const Vec along=Unit(Cross(gate.normal,radial));
78 in.entryVehicle.wind=along*wind;
79 s.groundSpeed=tas*std::cos(gamma)+wind;s.verticalSpeed=tas*std::sin(gamma);
80 in.own.v=Cross({0,0,in.spin},in.own.r)+along*s.groundSpeed+radial*s.verticalSpeed;
81 in.entryVehicle.airVelocity=in.own.v-Cross({0,0,in.spin},in.own.r)-in.entryVehicle.wind;
82 in.entryVehicle.nose=Unit(in.entryVehicle.airVelocity);
83 s.heading=ArrivalPlanning::AircraftHeading(in.own.r,in.entryVehicle.nose);
84 a.DesiredCourseRadians=float(ArrivalPlanning::AircraftHeading(in.own.r,along));
85 s.ias=EntryPhysics::Atmosphere(in,in.own).ias;
86 };
87 sense();Check(controller.Begin(in,r,g,s,a),"achieved VMCI entry starts aircraft-mode descent");
88 double minimum=altitude,maxIas=0;int n=0;
89 for(;n<int(4000/dt)&&controller.Status().active;++n) {
90 // Independent lagged speed/path plant. Positions follow achieved
91 // velocity, never a copied desired profile or a gate teleport.
92 const double groundGamma=a.CurrentVerticalMode==ApproachAfcs::FlightPathAngle?a.DesiredFpaRadians:
93 std::atan2((a.DesiredAltitudeKm-altitude)/10,s.groundSpeed);
94 const double targetGamma=groundGamma+std::asin((std::clamp)(wind/tas*std::sin(groundGamma),-1.0,1.0));
95 gamma+=(targetGamma-gamma)*(std::min)(1.0,dt/lag);
96 tas+=(a.DesiredTasKms-tas)*(std::min)(1.0,dt/6);
97 altitude+=tas*std::sin(gamma)*dt;
98 const double advance=(tas*std::cos(gamma)+wind)*dt;
99 radial=Rotate(radial,gate.normal,advance/in.radius);distance-=advance;in.now+=dt;
100 // Preserve the AFCS command; the sensor does not move the course bug.
101 const float course=a.DesiredCourseRadians;sense();a.DesiredCourseRadians=course;
102 controller.Step(in,r,s,a);minimum=(std::min)(minimum,altitude);maxIas=(std::max)(maxIas,s.ias);
103 Check(a.DesiredFpaRadians>=-20*Pi/180-1e-6&&a.DesiredFpaRadians<=3*Pi/180+1e-6,"descent commands remain inside FPA envelope");
104 if(!(altitude>gate.altitudeKm-.1&&s.ias>1.1*s.stall&&s.ias<in.vneKms*.95))
105 std::cout<<"descent limit t "<<n*dt<<" h "<<altitude<<" IAS "<<s.ias<<" TAS "<<tas<<" target "<<a.DesiredTasKms<<" range "<<distance<<" status active "<<controller.Status().active<<"\n";
106 Check(altitude>gate.altitudeKm-.1&&s.ias>1.1*s.stall&&s.ias<in.vneKms*.95,"lagged descent retains IAS and final-altitude margins");
107 }
108 std::wcout<<L"VMCI approach: "<<controller.Status().status<<L" t "<<n*dt<<L" range "<<distance<<L" h "<<altitude<<L" IAS "<<s.ias<<L" peak "<<maxIas<<L" min "<<minimum<<L"\n";
109 Check(controller.Status().armed&&!controller.Status().active,"lagged descent reaches ILS handoff before marker");
110 Check(a.CurrentLateralMode==ApproachAfcs::Navigation&&a.CurrentVerticalMode==ApproachAfcs::FlightPathAngle&&
111 a.StandbyLateralMode==ApproachAfcs::Localizer&&a.StandbyVerticalMode==ApproachAfcs::Glideslope,
112 "ILS handoff retains descending NAV FPA with LOC and GS armed");
113 Check(distance>=gate.distanceKm&&distance<=gate.distanceKm+1&&std::abs(altitude-descent.Height(distance))<.05,
114 "handoff is descending below beam on correct inbound side near outer marker");
115 a.StandbyLateralMode=ApproachAfcs::LateralMode_Off;
116 controller.Step(in,r,s,a);
117 Check(a.StandbyLateralMode==ApproachAfcs::LateralMode_Off,"completed handoff never re-arms after pilot disarms");
118}
119void ApproachTests()
120{
121 ApproachGeometryTests();
122 // DOR-1 origin/performance, with the corrected runway and live WOOKE
123 // association. The existing finite-actuator plant also flies the entry;
124 // it does not merely assert that a drawing points in the right direction.
125 auto recorded=VmciApproachFixture();
126 recorded.own={{-1876.5226786857966,-2413.7434142773345,21.845617248499302},
127 {4.4554541347777885,-3.4621584013307181,-.02361322467282222}};
128 recorded.massKg=124304.4140625;recorded.fuelKg=9853.9267578125;
129 recorded.thrustKN=recorded.entryForwardKN=3134.26220703125;
130 recorded.entryReverseKN=recorded.entryUpKN=3134.2620029245736;
131 recorded.entryDownKN=1458.765563411318;recorded.entrySideKN=1488.5363503059198;
132 recorded.flowKgS=2.5082244873046875;recorded.idleFlowKgS=.006569;
133 recorded.bodyDragAcceleration=1.0386089609601712;recorded.seaLevelEfficiency=.9;
134 recorded.vneKms=.13166943192481995;
135 recorded.entryVehicle.wind={-.057861440293680566,-.06078512345498055,.000035961435078234877};
136 recorded.entryVehicle.airVelocity=recorded.own.v-Cross({0,0,recorded.spin},recorded.own.r)-recorded.entryVehicle.wind;
137 recorded.entryVehicle.nose=Unit(recorded.entryVehicle.airVelocity);
138 recorded.entryVehicle.aftC=21.85277;
139 FlyEntry(866.6664579957724,1,1,0,false,&recorded);
140 for(double dt:{.1,.5}) for(double lag:{2.0,8.0}) for(double wind:{-.03,0.0,.03}) FlyApproach(dt,lag,wind);
141 FlyApproach(.2,4,.015,true);
142 for(int fault=0;fault<25;++fault) {
143 auto in=VmciApproachFixture();Request r;r.final=Final::Ils;
144 const auto gate=ArrivalPlanning::Preview(in,r);
145 in.own.r=Rotate(Unit(in.target.r),gate.normal,-205/in.radius)*(in.radius+30);
146 in.entryVehicle.nose=Unit(Cross(gate.normal,in.own.r));in.entryVehicle.airVelocity=in.entryVehicle.nose*.5;
147 Approach::Sensors s;s.ias=.08;s.stall=.045;s.vref=.0585;s.groundSpeed=.5;s.dt=.2;
148 s.heading=ArrivalPlanning::AircraftHeading(in.own.r,in.entryVehicle.nose);
149 ApproachAfcs a;a.DesiredCourseRadians=float(s.heading);Approach::Controller c;Guidance g;g.entryHandoff=true;
150 Check(c.Begin(in,r,g,s,a),"fault fixture starts with valid achieved entry");
151 s.frozen=true;const double frozenTas=a.DesiredTasKms;
152 c.Step(in,r,s,a);
153 Check(c.Status().active&&a.DesiredFpaRadians==0&&a.DesiredTasKms==frozenTas,"freeze preserves stage and commands without descent or capture");
154 s.frozen=false;
155 if(fault==0)a.AutopilotEngaged=false;
156 if(fault==1)a.AutothrottleEngaged=false;
157 if(fault==2)a.TvmOn=true;
158 if(fault==3)++r.revision;
159 if(fault==4)++in.targetId;
160 if(fault==5)in.arrivalSite.ils=false;
161 if(fault==6)in.entryVehicle.airAge=1;
162 if(fault==7)s.groundSpeed=0;
163 if(fault==8)s.ias=NAN;
164 if(fault==9)in.onGround=true;
165 if(fault==10)in.simulator=!in.simulator;
166 if(fault==11)s.timingValid=false;
167 if(fault==12)a.CurrentVerticalMode=ApproachAfcs::Pitch;
168 if(fault==13)a.DesiredFpaRadians=.1f;
169 if(fault==14)in.entryVehicle.aftC=205;
170 if(fault==15)s.ias=in.vneKms;
171 if(fault==16)in.arrivalSite.fix.z+=1;
172 if(fault==17)in.powered=false;
173 if(fault==18)in.entryVehicle.airAge=NAN;
174 if(fault==19)a.DesiredCourseRadians+=.1f;
175 if(fault==20)a.DesiredTasKms+=.1f;
176 if(fault==21)a.StandbyLateralMode=ApproachAfcs::Localizer;
177 if(fault==22)in.massKg=NAN;
178 if(fault==23)in.own.r=in.own.r*(in.radius+100)/Norm(in.own.r);
179 if(fault==24) {in.aglKm=.05;s.verticalSpeed=-.01;}
180 const auto mode=a.CurrentVerticalMode;const double fpa=a.DesiredFpaRadians;
181 c.Step(in,r,s,a);
182 if(fault==21) {
183 Check(c.Status().active&&a.StandbyLateralMode==ApproachAfcs::Localizer,"manual LOC arming preserves managed vertical descent");
184 a.CurrentLateralMode=ApproachAfcs::Localizer;a.StandbyLateralMode=ApproachAfcs::LateralMode_Off;
185 c.Step(in,r,s,a);Check(c.Status().active,"LOC capture does not interrupt managed descent");
186 continue;
187 }
188 Check(!c.Status().active&&!c.Status().armed,"changed intent or invalid envelope cancels descent without ILS arming");
189 if(fault==12||fault==13) Check(a.CurrentVerticalMode==mode&&a.DesiredFpaRadians==fpa,"pilot mode/target edits are preserved");
190 in.entryVehicle.airAge=0;s.ias=.08;c.Step(in,r,s,a);
191 Check(!c.Status().active,"recovered data never silently restarts descent");
192 }
193}
SCRIPT_CONTROL SCRIPT_STATE const void int
bool Unit(Vector3 &v)
double Heading(Vec position, Vec direction)
constexpr double Tau
Definition OrbitMath.h:10
Vec Rotate(Vec v, Vec axis, double angle)
Definition OrbitMath.h:22
constexpr double Pi
Definition OrbitMath.h:10
double Norm(Vec a)
Definition OrbitMath.h:18
Vec Cross(Vec a, Vec b)
Definition OrbitMath.h:17
type
Definition erin.py:143