1#pragma once
2#include "JasonReentryFixture.h"
3void DescendingHandoffTests()
4{
5 auto in=JasonReentryFixture();Request r;r.entryOrigin=true;r.passTime=PassTime::Manual;
6 r.final=Final::Ils;r.arrivalEpoch=in.now+798.2483325302601;
7 const auto snapshot=Solve(in,r);
8 const auto& p=snapshot.plan;
9 std::wcout<<L"Jason revised plan "<<p.surface.reason<<L" FPA "<<p.entry.handoffFpa*180/Pi<<L" fuel "<<p.fuel<<L"\n";
10 Check(p.valid&&!p.planningOnly,"recorded VCPS request has a descending executable arrival");
11 Check(p.entry.handoffFpa<0,"ILS handoff is a descent rather than an altitude capture");
12 const Vec up=Unit(p.entry.handoff.r),normal=Rotate(p.arrival.normal,{0,0,1},in.spin*p.end);
13 const Vec ground=p.entry.handoff.v-Cross({0,0,in.spin},p.entry.handoff.r);
14 const Vec air=ground-EntryPhysics::Wind(in,p.entry.handoff.r);
15 Check(std::abs(Dot(ground,normal))<1e-9,"crosswind is crabbed without a cross-track handoff velocity");
16 Check(std::abs(Norm(air)-.5)<1e-9,"crabbed descending endpoint still reaches 500m/s TAS");
17 Check(Dot(ground,up)<-.01,"entry retains useful descent at the 30km crossing");
18 for(double t:{p.end-.001,p.end+.001}) {
19 const auto k=EntryControl::Reference(p,t,in.spin,in.gm);
20 const Vec n=Rotate(normal,{0,0,1},in.spin*(t-p.end));
21 const Vec v=k.state.v-Cross({0,0,in.spin},k.state.r);
22 Check(std::abs(
Dot(v,n))<1e-5,
"handoff continuation preserves runway course across deadline");
23 }
24 const auto flight=FlyEntry(r.arrivalEpoch,1,1,0,false,&in);
25 auto end=flight.finalInput;
26 const Vec endUp=
Unit(end.own.r),endGround=end.own.v-
Cross({0,0,end.spin},end.own.r);
27 Approach::Sensors actual;
28 actual.verticalSpeed=
Dot(endGround,endUp);actual.groundSpeed=
Norm(endGround-endUp*actual.verticalSpeed);
29 actual.heading=ArrivalPlanning::AircraftHeading(end.own.r,end.entryVehicle.nose);
30 actual.ias=EntryPhysics::Atmosphere(end,end.own).ias;actual.stall=.045;actual.vref=.0585;actual.dt=.2;
31 Guidance achieved;achieved.entryHandoff=true;achieved.entryHandoffFpa=p.entry.handoffFpa;achieved.phase=Phase::Complete;
32 ApproachAfcs handoff;handoff.DorOn=true;
33 Check(
FinishEntryExecution(end,r,achieved,
false,handoff,[&]{handoff.DorOn=
false;}),
"actual flown endpoint hands to AFCS");
34 Approach::Controller continuation;
35 Check(continuation.Begin(end,r,achieved,actual,handoff),"actual finite-actuator endpoint starts NAV FPA descent");
36 Check(handoff.DesiredAltitudeKm==0&&handoff.DesiredFpaRadians<0,"descending handoff has no 30km altitude hold selection");
37
38
39
40 auto offset=end;
41 const Vec sideAxis=
Unit(
Cross(
Unit(offset.own.r),p.arrival.normal));
42 auto shift=[&](Vec v){
return Rotate(v,sideAxis,2.03/in.radius);};
43 offset.own={shift(end.own.r),shift(end.own.v)};
44 offset.entryVehicle.nose=shift(end.entryVehicle.nose);
45 offset.entryVehicle.airVelocity=offset.own.v-
Cross({0,0,in.spin},offset.own.r)-EntryPhysics::Wind(offset,offset.own.r);
46 Vec integral;
47 const auto offsetHandoff=EntryControl::Command(offset,p,end.now-in.now,integral,.2);
48 Check(offsetHandoff.positionErrorKm>1&&offsetHandoff.entryHandoff,
49 "valid descending handoff with distant NAV offset has no new 1km position gate");
50
51
52
53 const auto gate=ArrivalPlanning::Preview(in,r);
54 in.own.r=
Rotate(
Unit(in.target.r),gate.normal,-220/in.radius)*(in.radius+30);
56 in.entryVehicle.nose=
Unit(
Cross(gate.normal,in.own.r));in.entryVehicle.airVelocity=in.entryVehicle.nose*.5;
57 Approach::Sensors s;s.ias=.0845;s.stall=.045;s.vref=.0585;s.groundSpeed=.48;s.verticalSpeed=-.06;s.dt=.2;
58 s.heading=ArrivalPlanning::AircraftHeading(in.own.r,in.entryVehicle.nose);
59 ApproachAfcs a;a.DesiredCourseRadians=float(s.heading);
60 Approach::Controller controller;Guidance g;g.entryHandoff=true;
61 Check(controller.Begin(in,r,g,s,a),"distant NAV offset does not reject ILS descent");
62 Check(a.CurrentVerticalMode==ApproachAfcs::FlightPathAngle&&a.DesiredFpaRadians<-.1,
63 "approach captures the descending handoff without inserting zero FPA");
64 controller.Step(in,r,s,a);
65 Check(controller.Status().active&&!controller.Status().armed&&a.CurrentLateralMode==ApproachAfcs::Navigation,
66 "NAV converges while descent continues; LOC is not forced at 220km");
67 a.StandbyLateralMode=ApproachAfcs::Localizer;
68 controller.Step(in,r,s,a);
69 Check(controller.Status().active&&a.StandbyLateralMode==ApproachAfcs::Localizer,
70 "manual LOC arming retains the pilot selection and managed descent");
71}
float Dot(const Vector3 &a, const Vector3 &b)
Vec Rotate(Vec v, Vec axis, double angle)
bool FinishEntryExecution(const Input &in, const Request &r, Guidance &g, bool frozen, Afcs &afcs, Disconnect stopDor)