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

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

1#pragma once
2void EntryEnvelopeTests()
3{
4 bool active=false;double clear=0;
5 Check(EntryControl::Protection::Track(true,false,active,clear,.2),"entry guard arms immediately");
6 Check(EntryControl::Protection::Track(false,true,active,clear,1),"entry guard does not chatter off on one clean forecast");
7 Check(!EntryControl::Protection::Track(false,true,active,clear,1),"entry guard releases after two seconds of recovery");
8 Check(!FlightLoads::OccupantExceeded(5,6,10)&&FlightLoads::OccupantExceeded(5.01,1,0),"shared occupant thresholds preserve client boundary semantics");
9 Check(FlightLoads::OccupantExceeded(0,-4.01,0)&&!FlightLoads::OccupantExceeded(0,-4,0),"negative body load uses existing one-G bias");
10 auto in=JasonReentryFixture();in.stallKms=.045;in.vrefKms=.0585;
11 auto another=in;another.vehicle=369;another.massKg*=2;
12 Check(EntryEnvelope::Fraction(in,{2,3,-4})==EntryEnvelope::Fraction(another,{2,3,-4}),
13 "aerospace-class load rating is independent of vehicle identity and mass");
14 Check(EntryEnvelope::Fraction(in,{0,4.8,0})>EntryEnvelope::Reserve,"wing limit precedes occupant injury limit");
15 in.entryVehicle.leftWing=63.5;
16 Check(EntryEnvelope::Fraction(in,{0,3,0})>1,"damaged wing tightens permitted body loads");
17 in.entryVehicle.leftWing=127;
18 auto unknown=in;unknown.entryVehicle.leftWing=NAN;Check(!std::isfinite(EntryEnvelope::Fraction(unknown,{0,1,0})),"invalid wing health cannot silently grant healthy-wing limits");
19 for(double angle:{0.,Pi/2,Pi}) {
20 Vec nose={std::cos(angle),std::sin(angle),0},up={0,0,1};
21 const auto g=EntryEnvelope::BodyG(up*(2*FlightLoads::G)+nose*(3*FlightLoads::G),nose,up);
22 Check(std::abs(g.y-2)<1e-9&&std::abs(g.z-3)<1e-9,"occupant force uses aircraft axes rather than planetary radial direction");
23 }
24 for(double altitude:{20.,67.,99.,150.}) {
25 State state{{in.radius+altitude,0,0},{.02,4,0}};
26 Check(EntryEnvelope::Skip(state,in.radius,true),"entry skip remains latched even after an upward interface crossing");
27 Check(!EntryEnvelope::Skip(state,in.radius,false),"orbit/ascent not entering atmosphere is not misclassified as a skip");
28 state.v.x=-.02;Check(!EntryEnvelope::Skip(state,in.radius,true),"descending recovery clears skip condition");
29 }
30 auto demand=EntryPhysics::Forces(in,in.own,SurfacePlanning::Gravity(in.own.r,in.gm),in.massKg);
31 in.entryVehicle.aeroValid=true;in.entryVehicle.aeroAcceleration=demand.nose*(-8*FlightLoads::G);
32 auto force=EntryEnvelope::Limit(in,demand,demand.nose*(-in.entryReverseKN));
33 const auto g=EntryEnvelope::BodyG(force/in.massKg+in.entryVehicle.aeroAcceleration,demand.nose,demand.up);
34 Check(g.z>=-FlightLoads::Fore*EntryEnvelope::Reserve-1e-9,"reverse thrust accounts for existing aerodynamic deceleration");
35 in.entryVehicle.loadValid=true;in.entryVehicle.bodyLoadG={0,1,-9};in.entryVehicle.deliveredAcceleration={};
36 force=EntryEnvelope::Limit(in,demand,demand.nose*(-in.entryReverseKN));
37 Check(Dot(force,demand.nose)/in.massKg>=-.5*FlightLoads::G-1e-9,
38 "measured cockpit forces reduce remaining thrust allowance");
39 in.entryVehicle.loadValid=false;
40 in.entryVehicle.aeroValid=false;
41 Request r;r.entryOrigin=true;r.final=Final::Ils;r.automaticHandoff=true;r.arrivalEpoch=in.now+1200;
42 const auto missing=[&] {auto bad=in;bad.stallKms=0;return EntryPlanning::Solve(bad,r,false);};
43 Check(!missing().valid,"automatic handoff fails closed without stall data");
44 RiseMath::Quaternion attitude;RiseMath::QuaternionRotationYawPitchRoll(&attitude,1.f,-.7f,1.2f);
45 auto frame=RotationFrame(attitude);in.entryVehicle.nose=frame.forward;in.bodyUp=frame.up;
46 for(double seconds:{720.,798.,1200.}) {
47 r.arrivalEpoch=in.now+seconds;
48 const auto p=EntryPlanning::Solve(in,r,true);
49 std::wcout<<L"Auto handoff at "<<seconds<<L": "<<p.surface.reason<<L" h "<<p.entry.handoffAltitudeKm<<L" v "<<p.entry.handoffSpeedKms<<L" load "<<p.entry.peakLoadFraction<<L"\n";
50 if(seconds==1200) Check(p.valid,"automatic handoff finds a feasible entry for the recorded Clipper");
51 if(p.valid) {
52 Check(p.entry.loadChecked&&p.entry.skipChecked&&p.entry.peakLoadFraction<=EntryEnvelope::Reserve,"accepted entry has load and skip protection");
53 Check(p.entry.handoffAltitudeKm!=30||std::abs(p.entry.handoffSpeedKms-.5)>.01,"automatic handoff is not fixed to Bill's arbitrary values");
54 }
55 }
56 r.passTime=PassTime::Pending;SurfacePlanning::InitialPassSearch search;
57 for(int n=0;n<100&&r.passTime==PassTime::Pending;++n) search.Step(in,r,false);
58 Check(r.passTime==PassTime::Seeded,"automatic entry finds earliest feasible handoff bracket");
59 const auto p=EntryPlanning::Solve(in,r,true);
60 std::wcout<<L"Fast automatic entry "<<r.arrivalSeconds<<L" h "<<p.entry.handoffAltitudeKm<<L" v "<<p.entry.handoffSpeedKms<<L"\n";
61 Check(p.valid,"fast automatic entry has a protected plan");
62 auto damaged=in;damaged.entryVehicle.leftWing=1;
63 Check(!EntryPlanning::Solve(damaged,r,false).valid,"entry is rejected when an almost failed wing cannot carry the trajectory");
64 auto manual=r;Snapshot snap;snap.plan=p;
65 Edit(manual,Row::EntryHandoff,1,snap,in.now);
66 Check(!manual.automaticHandoff&&manual.entryAltitudeKm==p.entry.handoffAltitudeKm&&manual.entrySpeedKms==p.entry.handoffSpeedKms,
67 "switching AUTO to SET preserves the computed target rather than jumping to 30km/500m/s");
68 const double disturbedTime=(p.entry.entrySeconds+p.end)*.5;
69 auto disturbed=in;disturbed.own=EntryControl::InCurrentFrame(p,disturbedTime,in.spin,in.gm).state;
70 const Vec radial=Unit(disturbed.own.r);
71 disturbed.own.v=disturbed.own.v+radial*(.1-Dot(disturbed.own.v,radial));
72 disturbed.entryVehicle.airVelocity=disturbed.own.v-Cross({0,0,in.spin},disturbed.own.r)-EntryPhysics::Wind(disturbed,disturbed.own.r);
73 disturbed.entryVehicle.nose=Unit(disturbed.entryVehicle.airVelocity);
74 disturbed.bodyUp=Unit(radial-disturbed.entryVehicle.nose*Dot(radial,disturbed.entryVehicle.nose));
75 Vec integral;const auto recovery=EntryControl::Command(disturbed,p,disturbedTime,integral,.2);
76 Check(recovery.valid&&recovery.entrySkipRisk&&recovery.entryLimited&&recovery.thrust,
77 "a rising atmospheric disturbance keeps DOR engaged with bounded skip recovery");
78 const auto aero=EntryPhysics::AerodynamicForce(disturbed,EntryPhysics::Atmosphere(disturbed,disturbed.own),
79 EntryPhysics::AeroAt(disturbed,disturbed.entryVehicle.aoa),disturbed.own.r)/disturbed.massKg;
80 Check(EntryEnvelope::Fraction(disturbed,EntryEnvelope::BodyG(recovery.accelerationCommand+aero,
81 disturbed.entryVehicle.nose,disturbed.bodyUp))<=EntryEnvelope::Reserve+1e-5,
82 "skip recovery does not borrow thrust beyond occupant/airframe load limits");
83 Preview(in,r,"entry-auto-envelope");
84 auto earlier=r;earlier.arrivalEpoch-=10;Check(!EntryPlanning::Solve(in,earlier,false).valid,"earlier ten-second bracket is infeasible");
85 const auto flown=FlyEntry(r.arrivalSeconds,1,1,0,false,&in,&p);
86 Guidance achieved;achieved.entryHandoff=true;achieved.phase=Phase::Complete;achieved.entryHandoffFpa=p.entry.handoffFpa;
87 achieved.entryHandoffAltitudeKm=p.entry.handoffAltitudeKm;achieved.entryHandoffSpeedKms=p.entry.handoffSpeedKms;
88 auto end=flown.finalInput;ApproachAfcs afcs;afcs.DorOn=true;
89 Check(FinishEntryExecution(end,r,achieved,false,afcs,[&]{afcs.DorOn=false;}),"automatic actual endpoint hands control to A/F");
90 Check(std::abs(afcs.DesiredTasKms-p.entry.handoffSpeedKms)<1e-6,"A/F receives computed speed rather than old 500m/s setting");
91 const Vec up=Unit(end.own.r),ground=end.own.v-Cross({0,0,end.spin},end.own.r);
92 Approach::Sensors sensors;sensors.ias=EntryPhysics::Atmosphere(end,end.own).ias;sensors.stall=in.stallKms;sensors.vref=in.vrefKms;
93 sensors.verticalSpeed=Dot(ground,up);sensors.groundSpeed=Norm(ground-up*sensors.verticalSpeed);
94 sensors.heading=ArrivalPlanning::AircraftHeading(end.own.r,end.entryVehicle.nose);sensors.dt=.2;
95 Approach::Controller approach;
96 Check(approach.Begin(end,r,achieved,sensors,afcs),"flown automatic endpoint starts its computed A/F descent geometry");
97 FlySteepDescent(false,1,flown.peakAft,p.entry.handoffAltitudeKm,p.entry.handoffSpeedKms);
98}
bool OccupantExceeded(double side, double normal, double fore)
Definition FlightLoads.h:16
constexpr double Fore
Definition FlightLoads.h:13
constexpr double G
Definition FlightLoads.h:13
bool Unit(Vector3 &v)
float Dot(const Vector3 &a, const Vector3 &b)
ArrivalPreview Preview(const Input &in, const Request &r)
constexpr double Pi
Definition OrbitMath.h:10
double Norm(Vec a)
Definition OrbitMath.h:18
void Edit(Request &r, Row row, int direction, const Snapshot &s, double now, bool circularize=false, bool recordingAllowed=false)
Definition OrbitState.h:438
Vec Cross(Vec a, Vec b)
Definition OrbitMath.h:17
bool FinishEntryExecution(const Input &in, const Request &r, Guidance &g, bool frozen, Afcs &afcs, Disconnect stopDor)
Quaternion * QuaternionRotationYawPitchRoll(Quaternion *out, float yaw, float pitch, float roll)
Definition ClientMath.h:169